List of usage examples for com.liferay.portal.kernel.xml Element getText
@Override
public String getText();
From source file:com.liferay.portlet.journal.util.JournalUtil.java
License:Open Source License
private static void _mergeArticleContentUpdate(Element curElement, Element newElement, String defaultLocale) { Attribute curTypeAttribute = curElement.attribute("type"); Attribute newTypeAttribute = newElement.attribute("type"); curTypeAttribute.setValue(newTypeAttribute.getValue()); Attribute curIndexTypeAttribute = curElement.attribute("index-type"); Attribute newIndexTypeAttribute = newElement.attribute("index-type"); if (newIndexTypeAttribute != null) { if (curIndexTypeAttribute == null) { curElement.addAttribute("index-type", newIndexTypeAttribute.getValue()); } else {/*from w w w.j a v a 2s . c o m*/ curIndexTypeAttribute.setValue(newIndexTypeAttribute.getValue()); } } Element newContentElement = newElement.elements("dynamic-content").get(0); String newLanguageId = newContentElement.attributeValue("language-id"); String newValue = newContentElement.getText(); String indexType = newElement.attributeValue("index-type"); if (Validator.isNotNull(indexType)) { curElement.addAttribute("index-type", indexType); } List<Element> curContentElements = curElement.elements("dynamic-content"); if (Validator.isNull(newLanguageId)) { for (Element curContentElement : curContentElements) { curContentElement.detach(); } Element curContentElement = SAXReaderUtil.createElement("dynamic-content"); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } curElement.add(curContentElement); } else { boolean alreadyExists = false; for (Element curContentElement : curContentElements) { String curLanguageId = curContentElement.attributeValue("language-id"); if (newLanguageId.equals(curLanguageId)) { alreadyExists = true; curContentElement.clearContent(); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } break; } } if (!alreadyExists) { Element curContentElement = curContentElements.get(0); String curLanguageId = curContentElement.attributeValue("language-id"); if (Validator.isNull(curLanguageId)) { if (newLanguageId.equals(defaultLocale)) { curContentElement.clearContent(); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } } else { curElement.add(newContentElement.createCopy()); } curContentElement.addAttribute("language-id", defaultLocale); } else { curElement.add(newContentElement.createCopy()); } } } }
From source file:com.liferay.portlet.journal.util.VelocityTemplateParser.java
License:Open Source License
@Override protected List<TemplateNode> getTemplateNodes(Element element) throws Exception { List<TemplateNode> templateNodes = new ArrayList<TemplateNode>(); Map<String, TemplateNode> prototypeTemplateNodes = new HashMap<String, TemplateNode>(); List<Element> dynamicElementElements = element.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { Element dynamicContentElement = dynamicElementElement.element("dynamic-content"); String data = StringPool.BLANK; if (dynamicContentElement != null) { data = dynamicContentElement.getText(); }/*from w w w.j a v a2 s. c o m*/ String name = dynamicElementElement.attributeValue("name", ""); if (name.length() == 0) { throw new TransformException("Element missing \"name\" attribute"); } String type = dynamicElementElement.attributeValue("type", ""); TemplateNode templateNode = new TemplateNode(getThemeDisplay(), name, stripCDATA(data), type); if (dynamicElementElement.element("dynamic-element") != null) { templateNode.appendChildren(getTemplateNodes(dynamicElementElement)); } else if ((dynamicContentElement != null) && (dynamicContentElement.element("option") != null)) { List<Element> optionElements = dynamicContentElement.elements("option"); for (Element optionElement : optionElements) { templateNode.appendOption(stripCDATA(optionElement.getText())); } } TemplateNode prototypeTemplateNode = prototypeTemplateNodes.get(name); if (prototypeTemplateNode == null) { prototypeTemplateNode = templateNode; prototypeTemplateNodes.put(name, prototypeTemplateNode); templateNodes.add(templateNode); } prototypeTemplateNode.appendSibling(templateNode); } return templateNodes; }
From source file:com.liferay.portlet.PortletBagFactory.java
License:Open Source License
protected Router newFriendlyURLRouter(Portlet portlet) throws Exception { if (Validator.isNull(portlet.getFriendlyURLRoutes())) { return null; }//from ww w. j a va 2 s . co m Router router = new RouterImpl(); String xml = getContent(portlet.getFriendlyURLRoutes()); Document document = SAXReaderUtil.read(xml, true); Element rootElement = document.getRootElement(); for (Element routeElement : rootElement.elements("route")) { String pattern = routeElement.elementText("pattern"); Route route = router.addRoute(pattern); for (Element generatedParameterElement : routeElement.elements("generated-parameter")) { String name = generatedParameterElement.attributeValue("name"); String value = generatedParameterElement.getText(); route.addGeneratedParameter(name, value); } for (Element ignoredParameterElement : routeElement.elements("ignored-parameter")) { String name = ignoredParameterElement.attributeValue("name"); route.addIgnoredParameter(name); } for (Element implicitParameterElement : routeElement.elements("implicit-parameter")) { String name = implicitParameterElement.attributeValue("name"); String value = implicitParameterElement.getText(); route.addImplicitParameter(name, value); } for (Element overriddenParameterElement : routeElement.elements("overridden-parameter")) { String name = overriddenParameterElement.attributeValue("name"); String value = overriddenParameterElement.getText(); route.addOverriddenParameter(name, value); } } return router; }
From source file:com.liferay.portlet.social.util.SocialConfigurationUtil.java
License:Open Source License
private static void _readActivityContribution(Element activityElement, SocialActivityDefinition activityDefinition) { Element contributionValueElement = activityElement.element("contribution-value"); Element contributionLimitElement = activityElement.element("contribution-limit"); if ((contributionValueElement == null) && (contributionLimitElement == null)) { return;/*from w ww . j a v a 2 s. c o m*/ } SocialActivityCounterDefinition activityCounterDefinition = new SocialActivityCounterDefinition(); activityCounterDefinition.setName(SocialActivityCounterConstants.NAME_CONTRIBUTION); activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_CREATOR); int increment = 0; if (contributionValueElement != null) { increment = GetterUtil.getInteger(contributionValueElement.getText()); } activityCounterDefinition.setIncrement(increment); if (contributionLimitElement != null) { String limitEnabled = contributionLimitElement.attributeValue("enabled"); if (Validator.isNotNull(limitEnabled)) { activityCounterDefinition.setLimitEnabled(GetterUtil.getBoolean(limitEnabled)); } String limitPeriod = contributionLimitElement.attributeValue("period"); if (Validator.isNotNull(limitPeriod)) { activityCounterDefinition.setLimitPeriod(limitPeriod); } int limitValue = GetterUtil.getInteger(contributionLimitElement.getText()); activityCounterDefinition.setLimitValue(limitValue); } activityDefinition.addCounter(activityCounterDefinition); SocialActivityCounterDefinition popularityActivityCounterDefinition = new SocialActivityCounterDefinition(); popularityActivityCounterDefinition.setName(SocialActivityCounterConstants.NAME_POPULARITY); popularityActivityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_ASSET); popularityActivityCounterDefinition.setIncrement(activityCounterDefinition.getIncrement()); popularityActivityCounterDefinition.setLimitEnabled(activityCounterDefinition.isLimitEnabled()); popularityActivityCounterDefinition.setLimitPeriod(activityCounterDefinition.getLimitPeriod()); popularityActivityCounterDefinition.setLimitValue(activityCounterDefinition.getLimitValue()); activityDefinition.addCounter(popularityActivityCounterDefinition); }
From source file:com.liferay.portlet.social.util.SocialConfigurationUtil.java
License:Open Source License
private static void _readActivityParticipation(Element activityElement, SocialActivityDefinition activityDefinition) { Element participationValueElement = activityElement.element("participation-value"); Element participationLimitElement = activityElement.element("participation-limit"); if ((participationValueElement == null) && (participationLimitElement == null)) { return;/*from w w w . j av a 2s . c o m*/ } SocialActivityCounterDefinition activityCounterDefinition = new SocialActivityCounterDefinition(); activityCounterDefinition.setName(SocialActivityCounterConstants.NAME_PARTICIPATION); activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_ACTOR); int increment = 0; if (participationValueElement != null) { increment = GetterUtil.getInteger(participationValueElement.getText()); } activityCounterDefinition.setIncrement(increment); if (participationLimitElement != null) { String limitEnabled = participationLimitElement.attributeValue("enabled"); if (Validator.isNotNull(limitEnabled)) { activityCounterDefinition.setLimitEnabled(GetterUtil.getBoolean(limitEnabled)); } String limitPeriod = participationLimitElement.attributeValue("period"); if (Validator.isNotNull(limitPeriod)) { activityCounterDefinition.setLimitPeriod(limitPeriod); } int limitValue = GetterUtil.getInteger(participationLimitElement.getText()); activityCounterDefinition.setLimitValue(limitValue); } activityDefinition.addCounter(activityCounterDefinition); }
From source file:com.liferay.portlet.wiki.importers.mediawiki.MediaWikiImporter.java
License:Open Source License
protected List<String> readSpecialNamespaces(Element root) throws ImportFilesException { List<String> namespaces = new ArrayList<String>(); Element siteinfoElement = root.element("siteinfo"); if (siteinfoElement == null) { throw new ImportFilesException("Invalid pages XML file"); }/*from ww w . j a va2s . c o m*/ Element namespacesElement = siteinfoElement.element("namespaces"); List<Element> namespaceElements = namespacesElement.elements("namespace"); for (Element namespaceElement : namespaceElements) { Attribute attribute = namespaceElement.attribute("key"); String value = attribute.getValue(); if (!value.equals("0")) { namespaces.add(namespaceElement.getText()); } } return namespaces; }
From source file:com.liferay.roles.admin.demo.data.creator.internal.BaseRoleDemoDataCreator.java
License:Open Source License
public void addPermissions(Role role, String permissionsXML, int scope, String primKey) throws PortalException { try {/*from www.j av a 2 s.c o m*/ Document document = SAXReaderUtil.read(permissionsXML); Element rootElement = document.getRootElement(); List<Element> resources = rootElement.elements("resource"); for (Element resource : resources) { String resourceName = resource.elementText("resource-name"); List<Element> actionIds = resource.elements("action-id"); for (Element actionId : actionIds) { addResourcePermission(role, resourceName, scope, primKey, actionId.getText()); } } } catch (Exception e) { throw new PortalException(e); } }
From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java
License:Open Source License
protected String formatFriendlyURLRoutesXML(String absolutePath, String content) throws Exception { if (isExcluded(_friendlyUrlRoutesSortExclusions, absolutePath)) { return content; }//from w ww. java 2 s. co m Document document = saxReaderUtil.read(content); Element rootElement = document.getRootElement(); List<ComparableRoute> comparableRoutes = new ArrayList<ComparableRoute>(); for (Element routeElement : rootElement.elements("route")) { String pattern = routeElement.elementText("pattern"); ComparableRoute comparableRoute = new ComparableRoute(pattern); for (Element generatedParameterElement : routeElement.elements("generated-parameter")) { String name = generatedParameterElement.attributeValue("name"); String value = generatedParameterElement.getText(); comparableRoute.addGeneratedParameter(name, value); } for (Element ignoredParameterElement : routeElement.elements("ignored-parameter")) { String name = ignoredParameterElement.attributeValue("name"); comparableRoute.addIgnoredParameter(name); } for (Element implicitParameterElement : routeElement.elements("implicit-parameter")) { String name = implicitParameterElement.attributeValue("name"); String value = implicitParameterElement.getText(); comparableRoute.addImplicitParameter(name, value); } for (Element overriddenParameterElement : routeElement.elements("overridden-parameter")) { String name = overriddenParameterElement.attributeValue("name"); String value = overriddenParameterElement.getText(); comparableRoute.addOverriddenParameter(name, value); } comparableRoutes.add(comparableRoute); } Collections.sort(comparableRoutes); String mainReleaseVersion = getMainReleaseVersion(); StringBundler sb = new StringBundler(); sb.append("<?xml version=\"1.0\"?>\n"); sb.append("<!DOCTYPE routes PUBLIC \"-//Liferay//DTD Friendly URL "); sb.append("Routes "); sb.append(mainReleaseVersion); sb.append("//EN\" \"http://www.liferay.com/dtd/"); sb.append("liferay-friendly-url-routes_"); sb.append(StringUtil.replace(mainReleaseVersion, StringPool.PERIOD, StringPool.UNDERLINE)); sb.append(".dtd\">\n\n<routes>\n"); for (ComparableRoute comparableRoute : comparableRoutes) { sb.append("\t<route>\n"); sb.append("\t\t<pattern>"); sb.append(comparableRoute.getPattern()); sb.append("</pattern>\n"); Map<String, String> generatedParameters = comparableRoute.getGeneratedParameters(); for (Map.Entry<String, String> entry : generatedParameters.entrySet()) { sb.append("\t\t<generated-parameter name=\""); sb.append(entry.getKey()); sb.append("\">"); sb.append(entry.getValue()); sb.append("</generated-parameter>\n"); } Set<String> ignoredParameters = comparableRoute.getIgnoredParameters(); for (String entry : ignoredParameters) { sb.append("\t\t<ignored-parameter name=\""); sb.append(entry); sb.append("\" />\n"); } Map<String, String> implicitParameters = comparableRoute.getImplicitParameters(); for (Map.Entry<String, String> entry : implicitParameters.entrySet()) { sb.append("\t\t<implicit-parameter name=\""); sb.append(entry.getKey()); sb.append("\">"); sb.append(entry.getValue()); sb.append("</implicit-parameter>\n"); } Map<String, String> overriddenParameters = comparableRoute.getOverriddenParameters(); for (Map.Entry<String, String> entry : overriddenParameters.entrySet()) { sb.append("\t\t<overridden-parameter name=\""); sb.append(entry.getKey()); sb.append("\">"); sb.append(entry.getValue()); sb.append("</overridden-parameter>\n"); } sb.append("\t</route>\n"); } sb.append("</routes>"); return sb.toString(); }
From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java
License:Open Source License
protected String formatPortletXML(String fileName, String absolutePath, String content) throws Exception { Document document = saxReaderUtil.read(content); Element rootElement = document.getRootElement(); rootElement.sortAttributes(true);//from w w w . j a v a 2 s . co m boolean checkNumericalPortletNameElement = !isExcluded(_numericalPortletNameElementExclusions, absolutePath); List<Element> portletElements = rootElement.elements("portlet"); for (Element portletElement : portletElements) { if (checkNumericalPortletNameElement) { Element portletNameElement = portletElement.element("portlet-name"); String portletNameText = portletNameElement.getText(); if (!Validator.isNumber(portletNameText)) { processErrorMessage(fileName, fileName + " contains a nonstandard portlet-name element " + portletNameText); } } if (fileName.endsWith("/liferay-portlet.xml")) { continue; } portletElement.sortElementsByChildElement("init-param", "name"); Element portletPreferencesElement = portletElement.element("portlet-preferences"); if (portletPreferencesElement != null) { portletPreferencesElement.sortElementsByChildElement("preference", "name"); } } return document.formattedString(); }
From source file:com.liferay.westminstercatechism.util.WCUtil.java
License:Open Source License
private WCUtil() { Document document = null;/*from w ww .j a va 2s . c om*/ try { ClassLoader classLoader = getClass().getClassLoader(); URL url = classLoader .getResource("com/liferay/westminstercatechism/dependencies/" + "westminster_catechmism.xml"); document = SAXReaderUtil.read(url); } catch (DocumentException de) { _log.error(de, de); } _shorter = new ArrayList<WCEntry>(); Element rootElement = document.getRootElement(); Element shorterElement = rootElement.element("shorter"); List<Element> entryElements = shorterElement.elements("entry"); for (Element entryElement : entryElements) { List<String[]> proofs = new ArrayList<String[]>(); Element proofsElement = entryElement.element("proofs"); List<Element> scripturesElements = proofsElement.elements("scriptures"); for (Element scripturesElement : scripturesElements) { proofs.add(StringUtil.split(scripturesElement.getText(), StringPool.SEMICOLON)); } _shorter.add(new WCEntry(entryElement.elementText("question"), entryElement.elementText("answer"), proofs.toArray(new String[0][0]))); } _shorter = Collections.unmodifiableList(_shorter); _larger = new ArrayList<WCEntry>(); Element largerElement = rootElement.element("larger"); entryElements = largerElement.elements("entry"); for (Element entry : entryElements) { List<String[]> proofs = new ArrayList<String[]>(); Element proofsElement = entry.element("proofs"); List<Element> scripturesElements = proofsElement.elements("scriptures"); for (Element scriptures : scripturesElements) { proofs.add(StringUtil.split(scriptures.getText(), StringPool.SEMICOLON)); } _larger.add(new WCEntry(entry.elementText("question"), entry.elementText("answer"), proofs.toArray(new String[0][0]))); } _larger = Collections.unmodifiableList(_larger); }