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.google.apps.connector.GHelperUtil.java
License:Open Source License
public static Document getDocument(GAuthenticator gAuthenticator, String url) throws GoogleAppsException { try {//from w w w . ja v a 2 s.c o m if (_log.isInfoEnabled()) { _log.info("getDocument request " + url); } Http.Options options = _getOptions(gAuthenticator); options.setLocation(url); String xml = HttpUtil.URLtoString(options); if (_log.isInfoEnabled()) { _log.info("getDocument response " + xml); } return SAXReaderUtil.read(new UnsyncStringReader(xml)); } catch (DocumentException de) { throw new GoogleAppsException(de); } catch (IOException ioe) { throw new GoogleAppsException(ioe); } }
From source file:com.liferay.httpservice.internal.definition.WebXMLDefinitionLoader.java
License:Open Source License
public WebXMLDefinitionLoader() throws DocumentException { Class<?> clazz = getClass(); Document document = SAXReaderUtil.read( clazz.getResource("/com/liferay/httpservice/internal/servlet/dependencies/" + "default-web.xml")); _defaultWebXmlRootElement = document.getRootElement(); }
From source file:com.liferay.httpservice.internal.definition.WebXMLDefinitionLoader.java
License:Open Source License
public WebXMLDefinition loadWebXML(Bundle bundle) throws DocumentException, IllegalAccessException, InstantiationException { WebXMLDefinition webXML = new WebXMLDefinition(); readContextParameters(bundle, _defaultWebXmlRootElement, webXML); readFilters(bundle, _defaultWebXmlRootElement, webXML); readListeners(bundle, _defaultWebXmlRootElement, webXML); readServlets(bundle, _defaultWebXmlRootElement, webXML); URL url = bundle.getEntry("WEB-INF/web.xml"); if (url != null) { Document document = SAXReaderUtil.read(url); Element rootElement = document.getRootElement(); readContextParameters(bundle, rootElement, webXML); readFilters(bundle, rootElement, webXML); readListeners(bundle, rootElement, webXML); readServlets(bundle, rootElement, webXML); }/*from w w w . j av a 2 s . co m*/ return webXML; }
From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java
License:Open Source License
public static String getServletContextName(Bundle bundle, boolean generate) { Dictionary<String, String> headers = bundle.getHeaders(); String webContextPath = headers.get("Web-ContextPath"); if (Validator.isNotNull(webContextPath)) { return webContextPath.substring(1); }/*from w w w. ja v a 2 s .c om*/ String deploymentContext = null; try { String pluginPackageXml = HttpUtil .URLtoString(bundle.getResource("/WEB-INF/liferay-plugin-package.xml")); if (pluginPackageXml != null) { Document document = SAXReaderUtil.read(pluginPackageXml); Element rootElement = document.getRootElement(); deploymentContext = GetterUtil.getString(rootElement.elementText("recommended-deployment-context")); } else { String pluginPackageProperties = HttpUtil .URLtoString(bundle.getResource("/WEB-INF/liferay-plugin-package.properties")); if (pluginPackageProperties != null) { if (_log.isDebugEnabled()) { _log.debug("Reading plugin package from " + "liferay-plugin-package.properties"); } Properties properties = PropertiesUtil.load(pluginPackageProperties); deploymentContext = GetterUtil .getString(properties.getProperty("recommended-deployment-context"), deploymentContext); } } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } } if (Validator.isNull(deploymentContext) && generate) { deploymentContext = PortalUtil.getJsSafePortletId(bundle.getSymbolicName()); } if (Validator.isNotNull(deploymentContext) && deploymentContext.startsWith(StringPool.SLASH)) { deploymentContext = deploymentContext.substring(1); } return deploymentContext; }
From source file:com.liferay.journal.content.web.internal.JournalContentPortletLayoutListener.java
License:Open Source License
protected String getRuntimePortletId(String xml) throws Exception { Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); String portletName = rootElement.attributeValue("name"); String instanceId = rootElement.attributeValue("instance"); PortletInstance portletInstance = new PortletInstance(portletName, instanceId); return portletInstance.getPortletInstanceKey(); }
From source file:com.liferay.journal.internal.exportimport.content.processor.ImageImportDDMFormFieldValueTransformer.java
License:Open Source License
private void _setContent(String content) { try {//from w ww. ja v a2 s.c o m _document = SAXReaderUtil.read(content); } catch (DocumentException de) { if (_log.isDebugEnabled()) { _log.debug("Invalid content:\n" + content); } } }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalArticleExportImportContentProcessor.java
License:Open Source License
protected String replaceExportJournalArticleReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content, boolean exportReferencedContent) throws Exception { Group group = _groupLocalService.fetchGroup(portletDataContext.getGroupId()); if (group.isStagingGroup()) { group = group.getLiveGroup();/*from w w w . j a v a2 s . c o m*/ } if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(JournalPortletKeys.JOURNAL)) { return content; } Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='ddm-journal-article']"); 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 jsonData = dynamicContentElement.getStringValue(); JSONObject jsonObject = _jsonFactory.createJSONObject(jsonData); long classPK = GetterUtil.getLong(jsonObject.get("classPK")); JournalArticle journalArticle = _journalArticleLocalService.fetchLatestArticle(classPK); if (journalArticle == null) { if (_log.isInfoEnabled()) { StringBundler messageSB = new StringBundler(); messageSB.append("Staged model with class name "); messageSB.append(stagedModel.getModelClassName()); messageSB.append(" and primary key "); messageSB.append(stagedModel.getPrimaryKeyObj()); messageSB.append(" references missing journal "); messageSB.append("article with class primary key "); messageSB.append(classPK); _log.info(messageSB.toString()); } continue; } String journalArticleReference = "[$journal-article-reference=" + journalArticle.getPrimaryKey() + "$]"; if (_log.isDebugEnabled()) { _log.debug("Replacing " + jsonData + " with " + journalArticleReference); } dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(journalArticleReference); if (exportReferencedContent) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel, journalArticle, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } else { Element entityElement = portletDataContext.getExportDataElement(stagedModel); portletDataContext.addReferenceElement(stagedModel, entityElement, journalArticle, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } } } return document.asXML(); }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalArticleExportImportContentProcessor.java
License:Open Source License
protected void validateJournalArticleReferences(String content) throws PortalException { List<Throwable> throwables = new ArrayList<>(); try {/*from w w w . j av a 2s . c o m*/ Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='ddm-journal-article']"); 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 json = dynamicContentElement.getStringValue(); if (Validator.isNull(json)) { if (_log.isDebugEnabled()) { _log.debug("No journal article reference is specified"); } continue; } JSONObject jsonObject = _jsonFactory.createJSONObject(json); long classPK = GetterUtil.getLong(jsonObject.get("classPK")); JournalArticle journalArticle = _journalArticleLocalService.fetchLatestArticle(classPK); if (journalArticle == null) { Throwable throwable = new NoSuchArticleException( "No JournalArticle exists with the key " + "{resourcePrimKey=" + classPK + "}"); throwables.add(throwable); } } } } catch (DocumentException de) { if (_log.isDebugEnabled()) { _log.debug("Invalid content:\n" + content); } } if (!throwables.isEmpty()) { throw new PortalException( new BulkException("Unable to validate journal article references", throwables)); } }
From source file:com.liferay.journal.internal.upgrade.v0_0_5.UpgradeJournal.java
License:Open Source License
protected String convertStaticContentToDynamic(String content) throws Exception { Document document = SAXReaderUtil.read(content); Document newDocument = SAXReaderUtil.createDocument(); Element rootElement = document.getRootElement(); String availableLocales = GetterUtil.getString(rootElement.attributeValue("available-locales"), _getDefaultLanguageId());//from ww w. java2 s . co m String defaultLocale = GetterUtil.getString(rootElement.attributeValue("default-locale"), _getDefaultLanguageId()); Element newRootElement = SAXReaderUtil.createElement("root"); newRootElement.addAttribute("available-locales", availableLocales); newRootElement.addAttribute("default-locale", defaultLocale); newDocument.add(newRootElement); Element dynamicElementElement = SAXReaderUtil.createElement("dynamic-element"); dynamicElementElement.addAttribute("name", "content"); dynamicElementElement.addAttribute("type", "text_area"); dynamicElementElement.addAttribute("index-type", "text"); dynamicElementElement.addAttribute("index", String.valueOf(0)); newRootElement.add(dynamicElementElement); List<Element> staticContentElements = rootElement.elements("static-content"); for (Element staticContentElement : staticContentElements) { String languageId = GetterUtil.getString(staticContentElement.attributeValue("language-id"), _getDefaultLanguageId()); String text = staticContentElement.getText(); Element dynamicContentElement = SAXReaderUtil.createElement("dynamic-content"); dynamicContentElement.addAttribute("language-id", languageId); dynamicContentElement.addCDATA(text); dynamicElementElement.add(dynamicContentElement); } return XMLUtil.formatXML(newDocument); }
From source file:com.liferay.journal.internal.upgrade.v0_0_5.UpgradeJournal.java
License:Open Source License
protected Set<String> getArticleFieldNames(long articleId) throws Exception { Set<String> articleFieldNames = new HashSet<>(); try (LoggingTimer loggingTimer = new LoggingTimer()) { String sql = "select JournalArticle.content from JournalArticle where " + "JournalArticle.id_ = ?"; try (PreparedStatement ps = connection.prepareStatement(sql)) { ps.setLong(1, articleId);/* www . ja v a 2 s . c om*/ try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { String content = rs.getString("content"); Document document = SAXReaderUtil.read(content); Element rootElement = document.getRootElement(); articleFieldNames = getArticleDynamicElements(rootElement); } } } } return articleFieldNames; }