List of usage examples for com.liferay.portal.kernel.xml Element addAttribute
public Element addAttribute(String name, String value);
From source file:com.liferay.google.apps.connector.GUserManagerImpl.java
License:Open Source License
@Override public void addGUser(long userId, String password, String firstName, String lastName) throws GoogleAppsException { Document document = SAXReaderUtil.createDocument(); Element atomEntryElement = addAtomEntry(document); addAtomCategory(atomEntryElement, "user"); Element appsLoginElement = atomEntryElement.addElement("apps:login"); appsLoginElement.addAttribute("password", password); appsLoginElement.addAttribute("userName", String.valueOf(userId)); Element appsNameElement = atomEntryElement.addElement("apps:name"); appsNameElement.addAttribute("familyName", lastName); appsNameElement.addAttribute("givenName", firstName); submitAdd(userURL, document);//from www . ja v a2 s. c o m }
From source file:com.liferay.google.apps.connector.GUserManagerImpl.java
License:Open Source License
@Override public void updateActive(long userId, boolean active) throws GoogleAppsException { Document document = getDocument(getUserURL(userId)); if (hasError(document)) { if (_log.isInfoEnabled()) { _log.info(getErrorMessage(document)); }//from w ww .j a v a 2 s . c o m return; } Element atomEntryElement = document.getRootElement(); Element appsLoginElement = atomEntryElement.element(getAppsQName("login")); appsLoginElement.addAttribute("suspended", String.valueOf(!active)); submitUpdate(getUserURL(userId), document); }
From source file:com.liferay.google.apps.connector.GUserManagerImpl.java
License:Open Source License
@Override public void updatePassword(long userId, String password) throws GoogleAppsException { Document document = getDocument(getUserURL(userId)); if (hasError(document)) { if (_log.isInfoEnabled()) { _log.info(getErrorMessage(document)); }//from www .ja v a2 s . c o m return; } Element atomEntryElement = document.getRootElement(); Element appsLoginElement = atomEntryElement.element(getAppsQName("login")); appsLoginElement.addAttribute("password", password); submitUpdate(getUserURL(userId), document); }
From source file:com.liferay.journal.demo.data.creator.internal.JournalArticleDemoDataCreatorImpl.java
License:Open Source License
private Document _createDocumentContent(String locale) { Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); rootElement.addAttribute("available-locales", locale); rootElement.addAttribute("default-locale", locale); return document; }
From source file:com.liferay.journal.demo.data.creator.internal.JournalArticleDemoDataCreatorImpl.java
License:Open Source License
private String _getStructuredContent(String content) { Locale locale = LocaleUtil.getSiteDefault(); Document document = _createDocumentContent(locale.toString()); Element rootElement = document.getRootElement(); Element dynamicElementElement = rootElement.addElement("dynamic-element"); dynamicElementElement.addAttribute("index-type", "text"); dynamicElementElement.addAttribute("name", "content"); dynamicElementElement.addAttribute("type", "text_area"); Element element = dynamicElementElement.addElement("dynamic-content"); element.addAttribute("language-id", LocaleUtil.toLanguageId(locale)); element.addCDATA(content);/*from w w w. j a v a 2s .com*/ return document.asXML(); }
From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java
License:Open Source License
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, JournalArticle article) throws Exception { Element articleElement = portletDataContext.getExportDataElement(article); articleElement.addAttribute("article-resource-uuid", article.getArticleResourceUuid()); if (article.getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, article.getFolder(), PortletDataContext.REFERENCE_TYPE_PARENT); }//from ww w .j a va2s. c om DDMStructure ddmStructure = _ddmStructureLocalService.getStructure(article.getGroupId(), _portal.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, ddmStructure, PortletDataContext.REFERENCE_TYPE_STRONG); if (article.getClassNameId() != _portal.getClassNameId(DDMStructure.class)) { DDMTemplate ddmTemplate = _ddmTemplateLocalService.getTemplate(article.getGroupId(), _portal.getClassNameId(DDMStructure.class), article.getDDMTemplateKey(), true); StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, ddmTemplate, PortletDataContext.REFERENCE_TYPE_STRONG); } Layout layout = article.getLayout(); if (layout != null) { portletDataContext.addReferenceElement(article, articleElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } if (article.isSmallImage()) { if (Validator.isNotNull(article.getSmallImageURL())) { String smallImageURL = _journalArticleExportImportContentProcessor.replaceExportContentReferences( portletDataContext, article, article.getSmallImageURL() + StringPool.SPACE, true, false); article.setSmallImageURL(smallImageURL); } else { Image smallImage = _imageLocalService.fetchImage(article.getSmallImageId()); if ((smallImage != null) && (smallImage.getTextObj() != null)) { String smallImagePath = ExportImportPathUtil.getModelPath(article, smallImage.getImageId() + StringPool.PERIOD + smallImage.getType()); articleElement.addAttribute("small-image-path", smallImagePath); article.setSmallImageType(smallImage.getType()); portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj()); } else { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export small image "); sb.append(article.getSmallImageId()); sb.append(" to article "); sb.append(article.getArticleId()); _log.warn(sb.toString()); } article.setSmallImage(false); article.setSmallImageId(0); } } } JournalArticle latestArticle = _journalArticleLocalService.fetchLatestArticle(article.getResourcePrimKey()); if ((latestArticle != null) && (latestArticle.getId() == article.getId())) { for (FileEntry fileEntry : article.getImagesFileEntries()) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK); } } article.setStatusByUserUuid(article.getStatusByUserUuid()); String content = _journalArticleExportImportContentProcessor.replaceExportContentReferences( portletDataContext, article, article.getContent(), portletDataContext.getBooleanParameter("journal", "referenced-content"), false); article.setContent(content); long defaultUserId = _userLocalService.getDefaultUserId(article.getCompanyId()); if (defaultUserId == article.getUserId()) { articleElement.addAttribute("preloaded", "true"); } portletDataContext.addClassedModel(articleElement, ExportImportPathUtil.getModelPath(article), article); }
From source file:com.liferay.journal.exportimport.data.handler.JournalFeedStagedModelDataHandler.java
License:Open Source License
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, JournalFeed feed) throws Exception { Element feedElement = portletDataContext.getExportDataElement(feed); DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure(feed.getGroupId(), _portal.getClassNameId(JournalArticle.class), feed.getDDMStructureKey(), true); if (ddmStructure != null) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, feed, ddmStructure, PortletDataContext.REFERENCE_TYPE_STRONG); } else {/*from w ww . j a v a 2s. co m*/ if (_log.isWarnEnabled()) { _log.warn("Unable to find DDM structure with key " + feed.getDDMStructureKey()); } } DDMTemplate ddmTemplate = _ddmTemplateLocalService.fetchTemplate(feed.getGroupId(), _portal.getClassNameId(DDMStructure.class), feed.getDDMTemplateKey()); if (ddmTemplate != null) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, feed, ddmTemplate, PortletDataContext.REFERENCE_TYPE_STRONG); } else { if (_log.isWarnEnabled()) { _log.warn("Unable to find DDM template with key " + feed.getDDMTemplateKey()); } } DDMTemplate rendererDDMTemplate = _ddmTemplateLocalService.fetchTemplate(feed.getGroupId(), _portal.getClassNameId(DDMStructure.class), feed.getDDMRendererTemplateKey()); if (rendererDDMTemplate != null) { Element rendererDDMTemplateElement = StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, feed, rendererDDMTemplate, PortletDataContext.REFERENCE_TYPE_STRONG); rendererDDMTemplateElement.addAttribute("rendererDDMTemplate", "true"); } else { if (_log.isWarnEnabled()) { _log.warn("Unable to find DDM template with key " + feed.getDDMRendererTemplateKey()); } } _journalFeedExportImportContentProcessor.replaceExportContentReferences(portletDataContext, feed, StringPool.BLANK, true, true); portletDataContext.addClassedModel(feedElement, ExportImportPathUtil.getModelPath(feed), feed); }
From source file:com.liferay.journal.exportimport.data.handler.JournalPortletDataHandler.java
License:Open Source License
@Override protected String doExportData(final PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { portletDataContext.addPortletPermissions(JournalPermission.RESOURCE_NAME); Element rootElement = addExportDataRootElement(portletDataContext); rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId())); if (portletDataContext.getBooleanParameter(NAMESPACE, "feeds")) { ActionableDynamicQuery feedActionableDynamicQuery = _journalFeedLocalService .getExportActionableDynamicQuery(portletDataContext); feedActionableDynamicQuery.performActions(); }/*from w w w . j a v a2s .com*/ if (portletDataContext.getBooleanParameter(NAMESPACE, "folders")) { ActionableDynamicQuery folderActionableDynamicQuery = _journalFolderLocalService .getExportActionableDynamicQuery(portletDataContext); folderActionableDynamicQuery.performActions(); } if (portletDataContext.getBooleanParameter(NAMESPACE, "structures")) { ActionableDynamicQuery ddmStructureActionableDynamicQuery = getDDMStructureActionableDynamicQuery( portletDataContext); ddmStructureActionableDynamicQuery.performActions(); // Export DDM structure default values ActionableDynamicQuery ddmStructureDefaultValueActionableDynamicQuery = getDDMStructureDefaultValuesActionableDynamicQuery( portletDataContext); ddmStructureDefaultValueActionableDynamicQuery.performActions(); } if (portletDataContext.getBooleanParameter(NAMESPACE, "templates")) { ActionableDynamicQuery ddmTemplateActionableDynamicQuery = getDDMTemplateActionableDynamicQuery( portletDataContext); ddmTemplateActionableDynamicQuery.performActions(); } if (portletDataContext.getBooleanParameter(NAMESPACE, "web-content")) { ActionableDynamicQuery articleActionableDynamicQuery = getArticleActionableDynamicQuery( portletDataContext); articleActionableDynamicQuery.performActions(); } return getExportDataRootElementString(rootElement); }
From source file:com.liferay.journal.exportimport.data.handler.test.ManifestSummaryTest.java
License:Open Source License
@Override protected void validateExport(PortletDataContext portletDataContext, StagedModel stagedModel, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { ManifestSummary manifestSummary = portletDataContext.getManifestSummary(); Map<String, LongWrapper> modelAdditionCounters = manifestSummary.getModelAdditionCounters(); Assert.assertEquals(modelAdditionCounters.toString(), 4, modelAdditionCounters.size()); Assert.assertEquals(1, manifestSummary .getModelAdditionCount(new StagedModelType(DDMStructure.class, JournalArticle.class))); Assert.assertEquals(1,//from ww w . j ava 2s .c o m manifestSummary.getModelAdditionCount(new StagedModelType(DDMTemplate.class, DDMStructure.class))); Assert.assertEquals(1, manifestSummary.getModelAdditionCount(new StagedModelType(JournalArticle.class))); Assert.assertEquals(1, manifestSummary.getModelAdditionCount(new StagedModelType(JournalFolder.class))); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); Element headerElement = rootElement.addElement("header"); DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat(Time.RFC822_FORMAT); String rfc822DateString = Time.getRFC822(); _exportDate = dateFormat.parse(rfc822DateString); headerElement.addAttribute("export-date", rfc822DateString); ExportImportHelperUtil.writeManifestSummary(document, manifestSummary); zipWriter.addEntry("/manifest.xml", document.asXML()); }
From source file:com.liferay.journal.internal.upgrade.v0_0_5.UpgradeJournal.java
License:Open Source License
protected String convertStaticContentToDynamic(String content) throws Exception { Document document = SAXReaderUtil.read(content); Document newDocument = SAXReaderUtil.createDocument(); Element rootElement = document.getRootElement(); String availableLocales = GetterUtil.getString(rootElement.attributeValue("available-locales"), _getDefaultLanguageId());/*from w ww . j a v a 2 s.co m*/ String defaultLocale = GetterUtil.getString(rootElement.attributeValue("default-locale"), _getDefaultLanguageId()); Element newRootElement = SAXReaderUtil.createElement("root"); newRootElement.addAttribute("available-locales", availableLocales); newRootElement.addAttribute("default-locale", defaultLocale); newDocument.add(newRootElement); Element dynamicElementElement = SAXReaderUtil.createElement("dynamic-element"); dynamicElementElement.addAttribute("name", "content"); dynamicElementElement.addAttribute("type", "text_area"); dynamicElementElement.addAttribute("index-type", "text"); dynamicElementElement.addAttribute("index", String.valueOf(0)); newRootElement.add(dynamicElementElement); List<Element> staticContentElements = rootElement.elements("static-content"); for (Element staticContentElement : staticContentElements) { String languageId = GetterUtil.getString(staticContentElement.attributeValue("language-id"), _getDefaultLanguageId()); String text = staticContentElement.getText(); Element dynamicContentElement = SAXReaderUtil.createElement("dynamic-content"); dynamicContentElement.addAttribute("language-id", languageId); dynamicContentElement.addCDATA(text); dynamicElementElement.add(dynamicContentElement); } return XMLUtil.formatXML(newDocument); }