List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createXPath
public static XPath createXPath(String xPathExpression)
From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java
License:Open Source License
protected void verifyStructure(DDMStructure structure) throws Exception { boolean modified = false; String defaultLanguageId = structure.getDefaultLanguageId(); XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element"); Document document = structure.getDocument(); List<Node> nodes = xPathSelector.selectNodes(document); for (Node node : nodes) { Element dynamicElementElement = (Element) node; if (createDefaultMetadataElement(dynamicElementElement, defaultLanguageId)) { modified = true;/*from ww w . j a v a 2 s . co m*/ } } if (modified) { updateStructure(structure, document.asXML()); } }
From source file:com.liferay.adaptive.media.journal.web.internal.exportimport.content.processor.AMJournalArticleContentHTMLReplacer.java
License:Open Source License
public String replace(String content, Replace replace) throws Exception { try {//from w ww . ja v a 2 s . com Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='text_area']"); List<Node> ddmJournalArticleNodes = xPath.selectNodes(document); for (Node ddmJournalArticleNode : ddmJournalArticleNodes) { Element ddmJournalArticleElement = (Element) ddmJournalArticleNode; List<Element> dynamicContentElements = ddmJournalArticleElement.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String replacedHtml = replace.apply(dynamicContentElement.getStringValue()); dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(replacedHtml); } } return document.asXML(); } catch (DocumentException de) { if (_log.isDebugEnabled()) { _log.debug("Invalid content:\n" + content); } return content; } }
From source file:com.liferay.dynamic.data.mapping.test.util.DDMStructureTestUtil.java
License:Open Source License
public static Map<String, Map<String, String>> getXSDMap(String xsd) throws Exception { Map<String, Map<String, String>> map = new HashMap<>(); Document document = UnsecureSAXReaderUtil.read(xsd); XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element"); List<Node> nodes = xPathSelector.selectNodes(document); for (Node node : nodes) { Element dynamicElementElement = (Element) node; String elementName = getElementName(dynamicElementElement); map.put(elementName, getElementMap(dynamicElementElement)); }//from w w w . ja v a 2 s . c o m return map; }
From source file:com.liferay.exportimport.controller.LayoutImportController.java
License:Open Source License
protected List<Element> fetchPortletElements(Element rootElement) { List<Element> portletElements = new ArrayList<>(); // Site portlets Element sitePortletsElement = rootElement.element("site-portlets"); // LAR compatibility if (sitePortletsElement == null) { sitePortletsElement = rootElement.element("portlets"); }//from w ww. jav a 2s.c om portletElements.addAll(sitePortletsElement.elements("portlet")); // Layout portlets XPath xPath = SAXReaderUtil.createXPath("staged-model/portlets/portlet"); Element layoutsElement = rootElement.element(Layout.class.getSimpleName()); List<Node> nodes = xPath.selectNodes(layoutsElement); Stream<Node> nodesStream = nodes.stream(); nodesStream.map(node -> (Element) node).forEach(portletElements::add); return portletElements; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
@Override public Element getMissingReferenceElement(ClassedModel classedModel) { StringBundler sb = new StringBundler(5); sb.append("missing-reference[@class-name='"); sb.append(ExportImportClassedModelUtil.getClassName(classedModel)); sb.append("' and @class-pk='"); sb.append(String.valueOf(classedModel.getPrimaryKeyObj())); sb.append("']"); XPath xPath = SAXReaderUtil.createXPath(sb.toString()); Node node = xPath.selectSingleNode(_missingReferencesElement); return (Element) node; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected Element getDataElement(Element parentElement, String attribute, String value) { if (parentElement == null) { return null; }/*from ww w . j ava 2 s . co m*/ StringBundler sb = new StringBundler(5); sb.append("staged-model[@"); sb.append(attribute); sb.append(StringPool.EQUAL); sb.append(HtmlUtil.escapeXPathAttribute(value)); sb.append(StringPool.CLOSE_BRACKET); XPath xPath = SAXReaderUtil.createXPath(sb.toString()); return (Element) xPath.selectSingleNode(parentElement); }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected List<Element> getReferenceDataElements(List<Element> referenceElements, Class<?> clazz) { List<Element> referenceDataElements = new ArrayList<>(); for (Element referenceElement : referenceElements) { Element referenceDataElement = null; String path = referenceElement.attributeValue("path"); if (Validator.isNotNull(path)) { referenceDataElement = getImportDataElement(clazz.getSimpleName(), "path", path); } else {// w ww. j av a2s. c o m String groupId = referenceElement.attributeValue("group-id"); String uuid = referenceElement.attributeValue("uuid"); StringBuilder sb = new StringBuilder(5); sb.append("staged-model[@uuid="); sb.append(HtmlUtil.escapeXPathAttribute(uuid)); if (groupId != null) { sb.append(" and @group-id="); sb.append(HtmlUtil.escapeXPathAttribute(groupId)); } sb.append(StringPool.CLOSE_BRACKET); XPath xPath = SAXReaderUtil.createXPath(sb.toString()); Element groupElement = getImportDataGroupElement(clazz.getSimpleName()); referenceDataElement = (Element) xPath.selectSingleNode(groupElement); } if (referenceDataElement == null) { continue; } referenceDataElements.add(referenceDataElement); } return referenceDataElements; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected List<Element> getReferenceElements(Element parentElement, String className, long groupId, String uuid, Serializable classPK, String referenceType) { if (parentElement == null) { return Collections.emptyList(); }/*from w w w .j av a 2 s.co m*/ Element referencesElement = parentElement.element("references"); if (referencesElement == null) { return Collections.emptyList(); } StringBundler sb = new StringBundler(13); sb.append("reference[@class-name="); sb.append(HtmlUtil.escapeXPathAttribute(className)); if (groupId > 0) { sb.append(" and @group-id='"); sb.append(groupId); sb.append(StringPool.APOSTROPHE); } if (Validator.isNotNull(uuid)) { sb.append(" and @uuid="); sb.append(HtmlUtil.escapeXPathAttribute(uuid)); } if (Validator.isNotNull(classPK)) { sb.append(" and @class-pk='"); sb.append(classPK); sb.append(StringPool.APOSTROPHE); } if (referenceType != null) { sb.append(" and @type="); sb.append(HtmlUtil.escapeXPathAttribute(referenceType)); } sb.append(StringPool.CLOSE_BRACKET); XPath xPath = SAXReaderUtil.createXPath(sb.toString()); List<Node> nodes = xPath.selectNodes(referencesElement); return ListUtil.fromArray(nodes.toArray(new Element[nodes.size()])); }
From source file:com.liferay.exportimport.test.util.lar.BaseWorkflowedStagedModelDataHandlerTestCase.java
License:Open Source License
protected Element getExportStagedModelElement(PortletDataContext portletDataContext, StagedModel stagedModel) { Element rootElement = portletDataContext.getExportDataRootElement(); Class<?> modelClass = stagedModel.getModelClass(); Element modelElement = rootElement.element(modelClass.getSimpleName()); Assert.assertNotNull("Unable to find model element", modelElement); XPath xPath = SAXReaderUtil .createXPath("staged-model[@path ='" + ExportImportPathUtil.getModelPath(stagedModel) + "']"); return (Element) xPath.selectSingleNode(modelElement); }
From source file:com.liferay.journal.internal.exportimport.content.processor.ImageImportDDMFormFieldValueTransformer.java
License:Open Source License
@Override public void transform(DDMFormFieldValue ddmFormFieldValue) throws PortalException { Value value = ddmFormFieldValue.getValue(); for (Locale locale : value.getAvailableLocales()) { String valueString = value.getString(locale); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString); String alt = jsonObject.getString("alt"); long oldClassPK = jsonObject.getLong("fileEntryId"); String type = jsonObject.getString("type"); FileEntry importedFileEntry = fetchImportedFileEntry(_portletDataContext, oldClassPK); if (importedFileEntry == null) { continue; }//from www . j ava2s.c om String fileEntryJSON = toJSON(importedFileEntry, type, alt); value.addString(locale, fileEntryJSON); StringBundler sb = new StringBundler(4); sb.append("//dynamic-element[@type='image']"); sb.append("/dynamic-content[contains(text(),'"); sb.append(valueString); sb.append("')]"); XPath xPath = SAXReaderUtil.createXPath(sb.toString()); List<Node> imageNodes = xPath.selectNodes(_document); for (Node imageNode : imageNodes) { Element imageElement = (Element) imageNode; imageElement.clearContent(); imageElement.addCDATA(fileEntryJSON); } } }