List of usage examples for com.liferay.portal.kernel.util HtmlUtil escapeXPathAttribute
public static String escapeXPathAttribute(String xPathAttribute)
From source file:com.liferay.dynamic.data.mapping.internal.util.DDMXMLImpl.java
License:Open Source License
protected List<Node> getElementsByName(Document document, String name) { name = HtmlUtil.escapeXPathAttribute(name); XPath xPathSelector = _saxReader.createXPath("//dynamic-element[@name=".concat(name).concat("]")); return xPathSelector.selectNodes(document); }
From source file:com.liferay.dynamic.data.mapping.io.internal.DDMFormXSDDeserializerImpl.java
License:Open Source License
protected Element fetchMetadataEntry(Element parentElement, String entryName) { XPath xPathSelector = _saxReader .createXPath("entry[@name=" + HtmlUtil.escapeXPathAttribute(entryName) + StringPool.CLOSE_BRACKET); return (Element) xPathSelector.selectSingleNode(parentElement); }
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; }/* w w w . j a va2 s. c om*/ 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 {/*from w w w. j av a2 s . 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 ww .ja v a2 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.journal.internal.util.impl.JournalConverterImpl.java
License:Open Source License
protected Element fetchMetadataEntry(Element parentElement, String attributeName, String attributeValue) { StringBundler sb = new StringBundler(5); sb.append("entry[@"); sb.append(attributeName);/*from www . j a v a 2 s . co m*/ sb.append(StringPool.EQUAL); sb.append(HtmlUtil.escapeXPathAttribute(attributeValue)); sb.append(StringPool.CLOSE_BRACKET); XPath xPathSelector = SAXReaderUtil.createXPath(sb.toString()); return (Element) xPathSelector.selectSingleNode(parentElement); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected JournalArticleDisplay getArticleDisplay(JournalArticle article, String ddmTemplateKey, String viewMode, String languageId, int page, PortletRequestModel portletRequestModel, ThemeDisplay themeDisplay, boolean propagateException) throws PortalException { String content = null;//from w ww . ja v a 2s .co m if (page < 1) { page = 1; } int numberOfPages = 1; boolean paginate = false; boolean pageFlow = false; boolean cacheable = true; Map<String, String> tokens = JournalUtil.getTokens(article.getGroupId(), portletRequestModel, themeDisplay); if ((themeDisplay == null) && (portletRequestModel == null)) { tokens.put("company_id", String.valueOf(article.getCompanyId())); Group companyGroup = groupLocalService.getCompanyGroup(article.getCompanyId()); tokens.put("article_group_id", String.valueOf(article.getGroupId())); tokens.put("company_group_id", String.valueOf(companyGroup.getGroupId())); // Deprecated tokens tokens.put("group_id", String.valueOf(article.getGroupId())); } tokens.put(TemplateConstants.CLASS_NAME_ID, String.valueOf(classNameLocalService.getClassNameId(DDMStructure.class))); tokens.put("article_resource_pk", String.valueOf(article.getResourcePrimKey())); DDMStructure ddmStructure = article.getDDMStructure(); tokens.put("ddm_structure_key", String.valueOf(ddmStructure.getStructureKey())); tokens.put("ddm_structure_id", String.valueOf(ddmStructure.getStructureId())); // Deprecated token tokens.put("structure_id", article.getDDMStructureKey()); String defaultDDMTemplateKey = article.getDDMTemplateKey(); if (Validator.isNull(ddmTemplateKey)) { ddmTemplateKey = defaultDDMTemplateKey; } Document document = article.getDocument(); document = document.clone(); Element rootElement = document.getRootElement(); List<Element> pages = rootElement.elements("page"); if (!pages.isEmpty()) { pageFlow = true; String targetPage = null; Map<String, String[]> parameters = portletRequestModel.getParameters(); if (parameters != null) { String[] values = parameters.get("targetPage"); if ((values != null) && (values.length > 0)) { targetPage = values[0]; } } Element pageElement = null; if (Validator.isNotNull(targetPage)) { targetPage = HtmlUtil.escapeXPathAttribute(targetPage); XPath xPathSelector = SAXReaderUtil.createXPath("/root/page[@id = " + targetPage + "]"); pageElement = (Element) xPathSelector.selectSingleNode(document); } if (pageElement != null) { document = SAXReaderUtil.createDocument(pageElement); rootElement = document.getRootElement(); numberOfPages = pages.size(); } else { if (page > pages.size()) { page = 1; } pageElement = pages.get(page - 1); document = SAXReaderUtil.createDocument(pageElement); rootElement = document.getRootElement(); numberOfPages = pages.size(); paginate = true; } } JournalUtil.addAllReservedEls(rootElement, tokens, article, languageId, themeDisplay); try { if (_log.isDebugEnabled()) { _log.debug( "Transforming " + article.getArticleId() + " " + article.getVersion() + " " + languageId); } // Try with specified template first (in the current group and the // global group). If a template is not specified, use the default // one. If the specified template does not exist, use the default // one. If the default one does not exist, throw an exception. DDMTemplate ddmTemplate = null; try { ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(article.getGroupId()), classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true); Group companyGroup = groupLocalService.getCompanyGroup(article.getCompanyId()); if (companyGroup.getGroupId() == ddmTemplate.getGroupId()) { tokens.put("company_group_id", String.valueOf(companyGroup.getGroupId())); } } catch (NoSuchTemplateException nste) { if (!defaultDDMTemplateKey.equals(ddmTemplateKey)) { ddmTemplate = ddmTemplateLocalService.getTemplate( PortalUtil.getSiteGroupId(article.getGroupId()), classNameLocalService.getClassNameId(DDMStructure.class), defaultDDMTemplateKey); } else { throw nste; } } tokens.put("ddm_template_key", String.valueOf(ddmTemplate.getTemplateKey())); tokens.put("ddm_template_id", String.valueOf(ddmTemplate.getTemplateId())); // Deprecated token tokens.put("template_id", ddmTemplateKey); String script = ddmTemplate.getScript(); String langType = ddmTemplate.getLanguage(); cacheable = ddmTemplate.isCacheable(); content = JournalUtil.transform(themeDisplay, tokens, viewMode, languageId, document, portletRequestModel, script, langType, propagateException); if (!pageFlow) { JournalServiceConfiguration journalServiceConfiguration = configurationProvider .getCompanyConfiguration(JournalServiceConfiguration.class, article.getCompanyId()); String[] pieces = StringUtil.split(content, journalServiceConfiguration.journalArticlePageBreakToken()); if (pieces.length > 1) { if (page > pieces.length) { page = 1; } content = pieces[page - 1]; numberOfPages = pieces.length; paginate = true; } } } catch (Exception e) { throw new SystemException(e); } return new JournalArticleDisplayImpl(article.getCompanyId(), article.getId(), article.getResourcePrimKey(), article.getGroupId(), article.getUserId(), article.getArticleId(), article.getVersion(), article.getTitle(languageId), article.getUrlTitle(), article.getDescription(languageId), article.getAvailableLanguageIds(), content, article.getDDMStructureKey(), ddmTemplateKey, article.isSmallImage(), article.getSmallImageId(), article.getSmallImageURL(), numberOfPages, page, paginate, cacheable); }
From source file:com.liferay.journal.util.impl.JournalUtil.java
License:Open Source License
private static Element _getElementByInstanceId(Document document, String instanceId) { if (Validator.isNull(instanceId)) { return null; }/* w w w . j a va 2 s . com*/ XPath xPathSelector = SAXReaderUtil .createXPath("//dynamic-element[@instance-id=" + HtmlUtil.escapeXPathAttribute(instanceId) + "]"); List<Node> nodes = xPathSelector.selectNodes(document); if (nodes.size() == 1) { return (Element) nodes.get(0); } else { return null; } }
From source file:com.liferay.journal.util.impl.JournalUtil.java
License:Open Source License
private static void _removeOldContent(Stack<String> path, Element contentElement, Document xsdDocument, String elementPath) {//from w w w. j av a 2s .co m String name = contentElement.attributeValue("name"); if (Validator.isNull(name)) { return; } String localPath = "dynamic-element[@name=" + HtmlUtil.escapeXPathAttribute(name) + "]"; String fullPath = elementPath + "/" + localPath; XPath xPathSelector = SAXReaderUtil.createXPath(fullPath); List<Node> curNodes = xPathSelector.selectNodes(xsdDocument); if (curNodes.isEmpty()) { contentElement.detach(); } path.push(localPath); _removeOldContent(path, contentElement, xsdDocument); path.pop(); }
From source file:com.liferay.journal.web.internal.portlet.action.ActionUtil.java
License:Open Source License
protected static String getElementInstanceId(String content, String fieldName, int index) throws Exception { Document document = SAXReaderUtil.read(content); String xPathExpression = "//dynamic-element[@name = " + HtmlUtil.escapeXPathAttribute(fieldName) + "]"; XPath xPath = SAXReaderUtil.createXPath(xPathExpression); List<Node> nodes = xPath.selectNodes(document); if (index > nodes.size()) { return StringPool.BLANK; }//from w ww . ja va 2s . co m Element dynamicElementElement = (Element) nodes.get(index); return dynamicElementElement.attributeValue("instance-id"); }