List of usage examples for com.liferay.portal.kernel.xml Element attributeValue
public String attributeValue(String name);
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 ava 2 s . c om*/ 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.JournalUtil.java
License:Open Source License
private static void _removeOldContent(Stack<String> path, Element contentElement, Document xsdDocument, String elementPath) throws SystemException { String name = contentElement.attributeValue("name"); if (Validator.isNull(name)) { return;// w w w.ja v a2 s. c om } String localPath = "dynamic-element[@name='" + name + "']"; String fullPath = elementPath + "/" + localPath; XPath xPathSelector = SAXReaderUtil.createXPath(fullPath); List<Node> curNodes = xPathSelector.selectNodes(xsdDocument); if (curNodes.size() == 0) { contentElement.detach(); } path.push(localPath); _removeOldContent(path, contentElement, xsdDocument); path.pop(); }
From source file:com.liferay.portlet.layoutconfiguration.util.xml.ActionURLLogic.java
License:Open Source License
@Override public String processXML(String xml) throws Exception { Document doc = SAXReaderUtil.read(xml); Element root = doc.getRootElement(); LiferayPortletResponse liferayPortletResponse = PortalUtil.getLiferayPortletResponse(_renderResponseImpl); LiferayPortletURL liferayPortletURL = liferayPortletResponse.createLiferayPortletURL(getLifecycle()); String portletId = root.attributeValue("portlet-name"); if (portletId != null) { portletId = PortalUtil.getJsSafePortletId(portletId); liferayPortletURL.setPortletId(portletId); }//from w w w . ja v a 2 s .c o m for (int i = 1;; i++) { String paramName = root.attributeValue("param-name-" + i); String paramValue = root.attributeValue("param-value-" + i); if ((paramName == null) || (paramValue == null)) { break; } liferayPortletURL.setParameter(paramName, paramValue); } return liferayPortletURL.toString(); }
From source file:com.liferay.portlet.layoutconfiguration.util.xml.PortletLogic.java
License:Open Source License
@Override public String processXML(String xml) throws Exception { Document doc = SAXReaderUtil.read(xml); Element root = doc.getRootElement(); String rootPortletId = root.attributeValue("name"); String instanceId = root.attributeValue("instance"); String queryString = root.attributeValue("queryString"); String portletId = rootPortletId; if (Validator.isNotNull(instanceId)) { portletId += PortletConstants.INSTANCE_SEPARATOR + instanceId; }//from w w w . j av a 2 s.c om return RuntimePortletUtil.processPortlet(_servletContext, _request, _response, _renderRequest, _renderResponse, portletId, queryString, false); }
From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java
License:Open Source License
@Override protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { portletDataContext.importPermissions("com.liferay.portlet.messageboards", portletDataContext.getSourceGroupId(), portletDataContext.getScopeGroupId()); Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); Element categoriesElement = rootElement.element("categories"); for (Element categoryElement : categoriesElement.elements("category")) { String path = categoryElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; }/*from w w w . j a v a 2 s. co m*/ MBCategory category = (MBCategory) portletDataContext.getZipEntryAsObject(path); importCategory(portletDataContext, path, category); } Element messagesElement = rootElement.element("messages"); for (Element messageElement : messagesElement.elements("message")) { String path = messageElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } MBMessage message = (MBMessage) portletDataContext.getZipEntryAsObject(path); importMessage(portletDataContext, messageElement, message); } if (portletDataContext.getBooleanParameter(_NAMESPACE, "thread-flags")) { Element threadFlagsElement = rootElement.element("thread-flags"); for (Element threadFlagElement : threadFlagsElement.elements("thread-flag")) { String path = threadFlagElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } MBThreadFlag threadFlag = (MBThreadFlag) portletDataContext.getZipEntryAsObject(path); importThreadFlag(portletDataContext, threadFlagElement, threadFlag); } } if (portletDataContext.getBooleanParameter(_NAMESPACE, "user-bans")) { Element userBansElement = rootElement.element("user-bans"); for (Element userBanElement : userBansElement.elements("user-ban")) { String path = userBanElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } MBBan ban = (MBBan) portletDataContext.getZipEntryAsObject(path); importBan(portletDataContext, userBanElement, ban); } } return null; }
From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java
License:Open Source License
protected List<ObjectValuePair<String, InputStream>> getAttachments(PortletDataContext portletDataContext, Element messageElement, MBMessage message) { if (!message.isAttachments() && portletDataContext.getBooleanParameter(_NAMESPACE, "attachments")) { return Collections.emptyList(); }//from w w w . j a v a2 s . c o m List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<ObjectValuePair<String, InputStream>>(); List<Element> attachmentElements = messageElement.elements("attachment"); for (Element attachmentElement : attachmentElements) { String name = attachmentElement.attributeValue("name"); String binPath = attachmentElement.attributeValue("bin-path"); InputStream inputStream = portletDataContext.getZipEntryAsInputStream(binPath); ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<String, InputStream>(name, inputStream); inputStreamOVPs.add(inputStreamOVP); } if (inputStreamOVPs.isEmpty()) { _log.error("Could not find attachments for message " + message.getMessageId()); } return inputStreamOVPs; }
From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java
License:Open Source License
protected void importThreadFlag(PortletDataContext portletDataContext, Element threadFlagElement, MBThreadFlag threadFlag) throws Exception { long userId = portletDataContext.getUserId(threadFlag.getUserUuid()); Map<Long, Long> messagePKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBMessage.class); long threadId = MapUtil.getLong(messagePKs, threadFlag.getThreadId(), threadFlag.getThreadId()); MBThread thread = MBThreadUtil.fetchByPrimaryKey(threadId); if (thread == null) { String rootMessageUuid = threadFlagElement.attributeValue("root-message-uuid"); MBMessage rootMessage = MBMessageUtil.fetchByUUID_G(rootMessageUuid, portletDataContext.getScopeGroupId()); if (rootMessage != null) { thread = rootMessage.getThread(); }//from w w w . j a va2 s .c o m } if (thread == null) { return; } MBThreadFlagLocalServiceUtil.addThreadFlag(userId, thread); }
From source file:com.liferay.portlet.polls.lar.PollsDisplayPortletDataHandlerImpl.java
License:Open Source License
@Override protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { portletDataContext.importPermissions("com.liferay.portlet.polls", portletDataContext.getSourceGroupId(), portletDataContext.getScopeGroupId()); if (Validator.isNull(data)) { return null; }/* w ww . java2 s.c o m*/ Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); Element questionsElement = rootElement.element("questions"); for (Element questionElement : questionsElement.elements("question")) { String path = questionElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } PollsQuestion question = (PollsQuestion) portletDataContext.getZipEntryAsObject(path); PollsPortletDataHandlerImpl.importQuestion(portletDataContext, questionElement, question); } Element choicesElement = rootElement.element("choices"); for (Element choiceElement : choicesElement.elements("choice")) { String path = choiceElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } PollsChoice choice = (PollsChoice) portletDataContext.getZipEntryAsObject(path); PollsPortletDataHandlerImpl.importChoice(portletDataContext, choice); } if (portletDataContext.getBooleanParameter(_NAMESPACE, "votes")) { Element votesElement = rootElement.element("votes"); for (Element voteElement : votesElement.elements("vote")) { String path = voteElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } PollsVote vote = (PollsVote) portletDataContext.getZipEntryAsObject(path); PollsPortletDataHandlerImpl.importVote(portletDataContext, vote); } } long questionId = GetterUtil.getLong(portletPreferences.getValue("questionId", StringPool.BLANK)); if (questionId > 0) { Map<Long, Long> questionPKs = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(PollsQuestion.class); questionId = MapUtil.getLong(questionPKs, questionId, questionId); portletPreferences.setValue("questionId", String.valueOf(questionId)); } return portletPreferences; }
From source file:com.liferay.portlet.polls.lar.PollsPortletDataHandlerImpl.java
License:Open Source License
@Override protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { portletDataContext.importPermissions("com.liferay.portlet.polls", portletDataContext.getSourceGroupId(), portletDataContext.getScopeGroupId()); Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); Element questionsElement = rootElement.element("questions"); for (Element questionElement : questionsElement.elements("question")) { String path = questionElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; }//from www . jav a2 s .c om PollsQuestion question = (PollsQuestion) portletDataContext.getZipEntryAsObject(path); importQuestion(portletDataContext, questionElement, question); } Element choicesElement = rootElement.element("choices"); for (Element choiceElement : choicesElement.elements("choice")) { String path = choiceElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } PollsChoice choice = (PollsChoice) portletDataContext.getZipEntryAsObject(path); importChoice(portletDataContext, choice); } if (portletDataContext.getBooleanParameter(_NAMESPACE, "votes")) { Element votesElement = rootElement.element("votes"); for (Element voteElement : votesElement.elements("vote")) { String path = voteElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { continue; } PollsVote vote = (PollsVote) portletDataContext.getZipEntryAsObject(path); importVote(portletDataContext, vote); } } return null; }
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 w ww . ja v a 2 s . c o 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; }