List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createDocument
public static Document createDocument(String encoding)
From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java
License:Open Source License
private String _getAssetEntryXml(String assetEntryType, String assetEntryUuid) { String xml = null;//ww w . j av a 2s. co m try { Document document = SAXReaderUtil.createDocument(StringPool.UTF8); Element assetEntryElement = document.addElement("asset-entry"); Element assetEntryTypeElement = assetEntryElement.addElement("asset-entry-type"); assetEntryTypeElement.addText(assetEntryType); Element assetEntryUuidElement = assetEntryElement.addElement("asset-entry-uuid"); assetEntryUuidElement.addText(assetEntryUuid); xml = document.formattedString(StringPool.BLANK); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe); } } return xml; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
private static String _getAssetEntryXml(String assetEntryType, String assetEntryUuid) { String xml = null;//from w ww .j a va 2 s .c o m try { Document document = SAXReaderUtil.createDocument(StringPool.UTF8); Element assetEntryElement = document.addElement("asset-entry"); Element assetEntryTypeElement = assetEntryElement.addElement("asset-entry-type"); assetEntryTypeElement.addText(assetEntryType); Element assetEntryUuidElement = assetEntryElement.addElement("asset-entry-uuid"); assetEntryUuidElement.addText(assetEntryUuid); xml = document.formattedString(StringPool.BLANK); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe); } } return xml; }
From source file:com.liferay.ide.servlet.WebServicesServlet.java
License:Open Source License
protected String getWebServicesXML() { Map<String, Set<JSONWebServiceActionMapping>> jsonWebServiceClazz = getJSONWebServiceClazz(); Document document = SAXReaderUtil.createDocument("UTF-8"); Element root = SAXReaderUtil.createElement("templates"); document.add(root);//from w w w.java 2 s . c om for (String jsonWebServiceClassName : jsonWebServiceClazz.keySet()) { Set<JSONWebServiceActionMapping> jsonWebServiceMappings = jsonWebServiceClazz .get(jsonWebServiceClassName); String className = jsonWebServiceClassName; if (className.endsWith("Impl")) { className = className.substring(0, className.length() - 4); } if (className.endsWith("Service")) { className = className.substring(0, className.length() - 7); } for (JSONWebServiceActionMapping jsonWebServiceActionMapping : jsonWebServiceMappings) { Element element = SAXReaderUtil.createElement("template"); String path = jsonWebServiceActionMapping.getPath(); int pos = path.lastIndexOf(CharPool.SLASH); String actionName = path.substring(pos + 1); element.add( SAXReaderUtil.createAttribute(element, "name", "jsonws-" + className + "-" + actionName)); element.add(SAXReaderUtil.createAttribute(element, "description", "jsonws-" + className + "-" + actionName)); element.add(SAXReaderUtil.createAttribute(element, "context", "javaScript")); element.add(SAXReaderUtil.createAttribute(element, "enabled", "true")); element.add(SAXReaderUtil.createAttribute(element, "autoinsert", "true")); StringBuffer sb = new StringBuffer(); sb.append("Liferay.Service(\n '"); sb.append(path); sb.append("',\n {\n"); MethodParameter[] methodParameters = jsonWebServiceActionMapping.getMethodParameters(); if (methodParameters.length > 0) { for (int t = 0; t < methodParameters.length; t++) { String parameterName = methodParameters[t].getName(); sb.append(" "); sb.append(parameterName); sb.append(":"); sb.append("${"); sb.append(parameterName); sb.append("}"); if (t < methodParameters.length - 1) { sb.append(",\n"); } } element.add(SAXReaderUtil.createAttribute(element, "id", "com.liferay.ide.ui.templates." + className + "." + actionName + methodParameters.length)); } else { element.add(SAXReaderUtil.createAttribute(element, "id", "com.liferay.ide.ui.templates." + className + "." + actionName)); } sb.append("\n },\n function(obj) {\n console.log(obj);\n }\n);"); element.add(SAXReaderUtil.createText(sb.toString())); root.add(element); } } return document.asXML(); }
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;/* w ww . j av a 2 s. c o 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.lms.service.impl.LearningActivityLocalServiceImpl.java
License:Open Source License
@SuppressWarnings("rawtypes") public void saveHashMapToXMLExtraContent(long actId, HashMap<String, String> map) throws SystemException, PortalException { try {/*from w w w. j av a 2 s. com*/ LearningActivity activity = learningActivityPersistence.fetchByPrimaryKey(actId); if (activity != null && !map.isEmpty()) { //Element resultadosXML=SAXReaderUtil.createElement("p2p"); Element resultadosXML = SAXReaderUtil.createElement(getNameLearningActivity(activity.getTypeId())); Document resultadosXMLDoc = SAXReaderUtil.createDocument(resultadosXML); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); Element eleXML = SAXReaderUtil.createElement(String.valueOf(e.getKey())); if (e.getKey().equals("document")) { eleXML.addAttribute("id", String.valueOf(e.getValue())); } else { eleXML.addText(String.valueOf(e.getValue())); } resultadosXML.add(eleXML); } activity.setExtracontent(resultadosXMLDoc.formattedString()); learningActivityPersistence.update(activity, true); } } catch (Exception e) { } }
From source file:com.liferay.portlet.journal.action.GetArticlesAction.java
License:Open Source License
protected byte[] getContent(HttpServletRequest request, List<JournalArticle> articles) throws Exception { long groupId = ParamUtil.getLong(request, "groupId"); String languageId = LanguageUtil.getLanguageId(request); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Map<String, String> tokens = JournalUtil.getTokens(groupId, themeDisplay); Document resultsDoc = SAXReaderUtil.createDocument(StringPool.UTF8); Element resultSetEl = resultsDoc.addElement("result-set"); for (JournalArticle article : articles) { Element resultEl = resultSetEl.addElement("result"); Document articleDoc = SAXReaderUtil.read(article.getContentByLocale(languageId)); resultEl.content().add(articleDoc.getRootElement().createCopy()); resultEl = resultEl.element("root"); JournalUtil.addAllReservedEls(resultEl, tokens, article, languageId); }/*from w w w . ja v a 2 s . c o m*/ return DDMXMLUtil.formatXML(resultsDoc).getBytes(StringPool.UTF8); }
From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
public JournalArticleDisplay getArticleDisplay(JournalArticle article, String templateId, String viewMode, String languageId, int page, String xmlRequest, ThemeDisplay themeDisplay) throws PortalException, SystemException { String content = null;//from ww w. j av a 2 s . c o m if (page < 1) { page = 1; } int numberOfPages = 1; boolean paginate = false; boolean pageFlow = false; boolean cacheable = true; if (Validator.isNull(xmlRequest)) { xmlRequest = "<request />"; } Map<String, String> tokens = JournalUtil.getTokens(article.getGroupId(), themeDisplay, xmlRequest); tokens.put("article_resource_pk", String.valueOf(article.getResourcePrimKey())); String defaultTemplateId = article.getTemplateId(); if (article.isTemplateDriven()) { if (Validator.isNull(templateId)) { templateId = defaultTemplateId; } tokens.put("structure_id", article.getStructureId()); tokens.put("template_id", templateId); } String xml = article.getContent(); try { Document document = null; Element rootElement = null; if (article.isTemplateDriven()) { document = SAXReaderUtil.read(xml); rootElement = document.getRootElement(); Document requestDocument = SAXReaderUtil.read(xmlRequest); List<Element> pages = rootElement.elements("page"); if (!pages.isEmpty()) { pageFlow = true; String targetPage = requestDocument .valueOf("/request/parameters/parameter[name='targetPage']/" + "value"); Element pageElement = null; if (Validator.isNotNull(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; } } rootElement.add(requestDocument.getRootElement().createCopy()); JournalUtil.addAllReservedEls(rootElement, tokens, article, languageId); xml = DDMXMLUtil.formatXML(document); } } catch (DocumentException de) { throw new SystemException(de); } catch (IOException ioe) { throw new SystemException(ioe); } try { if (_log.isDebugEnabled()) { _log.debug( "Transforming " + article.getArticleId() + " " + article.getVersion() + " " + languageId); } String script = null; String langType = null; if (article.isTemplateDriven()) { // 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 exit, use the // default one. If the default one does not exist, throw an // exception. JournalTemplate template = null; try { template = journalTemplatePersistence.findByG_T(article.getGroupId(), templateId); } catch (NoSuchTemplateException nste1) { try { Group companyGroup = groupLocalService.getCompanyGroup(article.getCompanyId()); template = journalTemplatePersistence.findByG_T(companyGroup.getGroupId(), templateId); tokens.put("company_group_id", String.valueOf(companyGroup.getGroupId())); } catch (NoSuchTemplateException nste2) { if (!defaultTemplateId.equals(templateId)) { template = journalTemplatePersistence.findByG_T(article.getGroupId(), defaultTemplateId); } else { throw nste1; } } } script = template.getXsl(); langType = template.getLangType(); cacheable = template.isCacheable(); } content = JournalUtil.transform(themeDisplay, tokens, viewMode, languageId, xml, script, langType); if (!pageFlow) { String[] pieces = StringUtil.split(content, PropsValues.JOURNAL_ARTICLE_TOKEN_PAGE_BREAK); 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.getAvailableLocales(), content, article.getType(), article.getStructureId(), templateId, article.isSmallImage(), article.getSmallImageId(), article.getSmallImageURL(), numberOfPages, page, paginate, cacheable); }
From source file:com.slemarchand.peoplepublisher.util.PeoplePublisherImpl.java
License:Open Source License
private String _getUserXml(String screenName) { String xml = null;//from w ww .j a va2s .c om try { Document document = SAXReaderUtil.createDocument(StringPool.UTF8); Element userElement = document.addElement("user"); Element screenNameElement = userElement.addElement("screen-name"); screenNameElement.addText(screenName); xml = document.formattedString(StringPool.BLANK); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe); } } return xml; }