List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil read
public static Document read(URL url) throws DocumentException
From source file:com.liferay.portlet.journal.util.JournalUtil.java
License:Open Source License
public static String removeArticleLocale(String content, String languageId) { try {//from www .ja v a2 s . co m Document document = SAXReaderUtil.read(content); Element rootElement = document.getRootElement(); String availableLocales = rootElement.attributeValue("available-locales"); if (availableLocales == null) { return content; } availableLocales = StringUtil.remove(availableLocales, languageId); if (availableLocales.endsWith(",")) { availableLocales = availableLocales.substring(0, availableLocales.length() - 1); } rootElement.addAttribute("available-locales", availableLocales); removeArticleLocale(rootElement, languageId); content = DDMXMLUtil.formatXML(document); } catch (Exception e) { _log.error(e, e); } return content; }
From source file:com.liferay.portlet.journal.util.JournalUtil.java
License:Open Source License
public static String removeOldContent(String content, String xsd) { try {//from ww w . ja v a 2s . co m Document contentDoc = SAXReaderUtil.read(content); Document xsdDoc = SAXReaderUtil.read(xsd); Element contentRoot = contentDoc.getRootElement(); Stack<String> path = new Stack<String>(); path.push(contentRoot.getName()); _removeOldContent(path, contentRoot, xsdDoc); content = DDMXMLUtil.formatXML(contentDoc); } catch (Exception e) { _log.error(e, e); } return content; }
From source file:com.liferay.portlet.journal.util.JournalUtil.java
License:Open Source License
private static void _populateTokens(Map<String, String> tokens, long groupId, String xmlRequest) throws Exception { Document requestDocument = SAXReaderUtil.read(xmlRequest); Element rootElement = requestDocument.getRootElement(); Element themeDisplayElement = rootElement.element("theme-display"); Layout layout = LayoutLocalServiceUtil .getLayout(GetterUtil.getLong(themeDisplayElement.elementText("plid"))); Group group = layout.getGroup(); LayoutSet layoutSet = layout.getLayoutSet(); String friendlyUrlCurrent = null; if (layout.isPublicLayout()) { friendlyUrlCurrent = themeDisplayElement.elementText("path-friendly-url-public"); } else if (group.isUserGroup()) { friendlyUrlCurrent = themeDisplayElement.elementText("path-friendly-url-private-user"); } else {/*from www. j a v a 2 s.c o m*/ friendlyUrlCurrent = themeDisplayElement.elementText("path-friendly-url-private-group"); } String layoutSetFriendlyUrl = StringPool.BLANK; String virtualHostname = layoutSet.getVirtualHostname(); if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplayElement.elementText("server-name"))) { layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL(); } tokens.put("cdn_host", themeDisplayElement.elementText("cdn-host")); tokens.put("company_id", themeDisplayElement.elementText("company-id")); tokens.put("friendly_url_current", friendlyUrlCurrent); tokens.put("friendly_url_private_group", themeDisplayElement.elementText("path-friendly-url-private-group")); tokens.put("friendly_url_private_user", themeDisplayElement.elementText("path-friendly-url-private-user")); tokens.put("friendly_url_public", themeDisplayElement.elementText("path-friendly-url-public")); tokens.put("group_friendly_url", group.getFriendlyURL()); tokens.put("group_id", String.valueOf(groupId)); tokens.put("image_path", themeDisplayElement.elementText("path-image")); tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl); tokens.put("main_path", themeDisplayElement.elementText("path-main")); tokens.put("portal_ctx", themeDisplayElement.elementText("path-context")); tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplayElement.elementText("url-portal"))); tokens.put("protocol", HttpUtil.getProtocol(themeDisplayElement.elementText("url-portal"))); tokens.put("root_path", themeDisplayElement.elementText("path-context")); tokens.put("theme_image_path", themeDisplayElement.elementText("path-theme-images")); _populateCustomTokens(tokens); // Deprecated tokens tokens.put("friendly_url", themeDisplayElement.elementText("path-friendly-url-public")); tokens.put("friendly_url_private", themeDisplayElement.elementText("path-friendly-url-private-group")); tokens.put("page_url", themeDisplayElement.elementText("path-friendly-url-public")); }
From source file:com.liferay.portlet.journal.util.LocaleTransformerListener.java
License:Open Source License
protected String replace(String xml) { if (xml == null) { return xml; }// w ww.j a v a2s . com _requestedLocale = getLanguageId(); try { Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); String defaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault()); String[] availableLocales = StringUtil .split(rootElement.attributeValue("available-locales", defaultLanguageId)); String defaultLocale = rootElement.attributeValue("default-locale", defaultLanguageId); boolean supportedLocale = false; for (String availableLocale : availableLocales) { if (availableLocale.equalsIgnoreCase(getLanguageId())) { supportedLocale = true; break; } } if (!supportedLocale) { setLanguageId(defaultLocale); } replace(rootElement); xml = DDMXMLUtil.formatXML(document); } catch (Exception e) { _log.error(e); } return xml; }
From source file:com.liferay.portlet.journalcontent.action.UpdateArticleFieldAction.java
License:Open Source License
protected void updateArticleField(HttpServletRequest request, HttpServletResponse response) throws Exception { long groupId = ParamUtil.getLong(request, "groupId"); String articleId = ParamUtil.getString(request, "articleId"); double version = ParamUtil.getDouble(request, "version"); String containerId = ParamUtil.getString(request, "containerId"); if (Validator.isNotNull(containerId)) { int x = containerId.indexOf("_"); int y = containerId.lastIndexOf("_"); if ((x != -1) && (y != -1)) { groupId = GetterUtil.getLong(containerId.substring(0, x)); articleId = containerId.substring(x + 1, y); version = GetterUtil.getDouble(containerId.substring(y, containerId.length())); }// w ww.jav a2 s . c om } String languageId = LanguageUtil.getLanguageId(request); String fieldName = ParamUtil.getString(request, "fieldName"); String fieldData = ParamUtil.getString(request, "fieldData"); if (fieldName.startsWith("journal-content-field-name-")) { fieldName = fieldName.substring(27, fieldName.length()); } JournalArticle article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId, version); String content = article.getContent(); Document doc = SAXReaderUtil.read(content); if (_log.isDebugEnabled()) { _log.debug("Before\n" + content); } String path = "/root/dynamic-element[@name='" + fieldName + "']/dynamic-content[@language-id='" + languageId + "']"; Node node = doc.selectSingleNode(path); if (node == null) { path = "/root/dynamic-element[@name='" + fieldName + "']/dynamic-content"; node = doc.selectSingleNode(path); } node.setText(fieldData); content = DDMXMLUtil.formatXML(doc); if (_log.isDebugEnabled()) { _log.debug("After\n" + content); } JournalArticleServiceUtil.updateContent(groupId, articleId, version, content); ServletResponseUtil.write(response, fieldData); }
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 ww w. j av a 2 s . c om 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; }/* w w w.j a va2 s . co m*/ 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 ww. j a v a2 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.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; }/*from w w w .j a v a2s . c om*/ 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; }// w w w .ja va2 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; }