List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createElement
public static Element createElement(String name)
From source file:com.liferay.exportimport.test.util.ExportImportTestUtil.java
License:Open Source License
public static PortletDataContext getImportPortletDataContext(long companyId, long groupId, Map<String, String[]> parameterMap) throws Exception { TestReaderWriter testReaderWriter = new TestReaderWriter(); Document document = SAXReaderUtil.createDocument(); Element manifestRootElement = document.addElement("root"); manifestRootElement.addElement("header"); testReaderWriter.addEntry("/manifest.xml", document.asXML()); PortletDataContext portletDataContext = PortletDataContextFactoryUtil.createImportPortletDataContext( companyId, groupId, parameterMap, new TestUserIdStrategy(), testReaderWriter); Element rootElement = SAXReaderUtil.createElement("root"); portletDataContext.setImportDataRootElement(rootElement); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); return portletDataContext; }
From source file:com.liferay.exportimport.test.util.lar.BaseStagedModelDataHandlerTestCase.java
License:Open Source License
protected void initExport(Group exportGroup) throws Exception { zipWriter = ZipWriterFactoryUtil.getZipWriter(); portletDataContext = PortletDataContextFactoryUtil.createExportPortletDataContext( exportGroup.getCompanyId(), exportGroup.getGroupId(), getParameterMap(), getStartDate(), getEndDate(), zipWriter);/*from w w w . j av a2s .co m*/ portletDataContext.setExportImportProcessId(BaseStagedModelDataHandlerTestCase.class.getName()); rootElement = SAXReaderUtil.createElement("root"); portletDataContext.setExportDataRootElement(rootElement); missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); }
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);/*ww w . ja v a 2s. 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.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 .j ava 2s. com 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.util.impl.JournalUtil.java
License:Open Source License
private static void _addElementOptions(Element curContentElement, Element newContentElement) { List<Element> newElementOptions = newContentElement.elements("option"); for (Element newElementOption : newElementOptions) { Element curElementOption = SAXReaderUtil.createElement("option"); curElementOption.addCDATA(newElementOption.getText()); curContentElement.add(curElementOption); }/*from w w w . j a v a 2 s .c o m*/ }
From source file:com.liferay.journal.util.impl.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 {//w ww.jav a2 s . c om curIndexTypeAttribute.setValue(newIndexTypeAttribute.getValue()); } } List<Element> elements = newElement.elements("dynamic-content"); if ((elements == null) || elements.isEmpty()) { return; } Element newContentElement = elements.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.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 ww .j a va 2 s . c o m*/ 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.util.JournalUtil.java
License:Open Source License
public static void addReservedEl(Element rootElement, Map<String, String> tokens, String name, String value) { // XML/*from w w w.ja va 2s . co m*/ if (rootElement != null) { Element dynamicElementElement = SAXReaderUtil.createElement("dynamic-element"); Attribute nameAttribute = SAXReaderUtil.createAttribute(dynamicElementElement, "name", name); dynamicElementElement.add(nameAttribute); Attribute typeAttribute = SAXReaderUtil.createAttribute(dynamicElementElement, "type", "text"); dynamicElementElement.add(typeAttribute); Element dynamicContentElement = SAXReaderUtil.createElement("dynamic-content"); //dynamicContentElement.setText("<![CDATA[" + value + "]]>"); dynamicContentElement.setText(value); dynamicElementElement.add(dynamicContentElement); rootElement.add(dynamicElementElement); } // Tokens tokens.put(StringUtil.replace(name, CharPool.DASH, CharPool.UNDERLINE), value); }
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 va2s.co 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.web.extender.internal.webbundle.WebBundleProcessor.java
License:Open Source License
protected void processLiferayPortletXML(String webContextpath) throws IOException { File liferayPortletXMLFile = new File(_deployedAppFolder, "WEB-INF/liferay-portlet.xml"); if (!liferayPortletXMLFile.exists()) { return;/*from w ww . j a va 2 s . c o m*/ } String content = FileUtil.read(liferayPortletXMLFile); Document liferayPortletXMLDoc = null; try { liferayPortletXMLDoc = SAXReaderUtil.read(content); } catch (DocumentException de) { throw new IOException(de); } Element rootEl = liferayPortletXMLDoc.getRootElement(); List<Element> portletElements = rootEl.elements("portlet"); for (Element portletElement : portletElements) { Element previousChild = portletElement.element("virtual-path"); if (previousChild == null) { previousChild = portletElement.element("icon"); } if (previousChild == null) { previousChild = portletElement.element("portlet-name"); } Element strutsPathElement = portletElement.element("struts-path"); if (strutsPathElement == null) { List<Node> children = portletElement.content(); int pos = children.indexOf(previousChild); strutsPathElement = SAXReaderUtil.createElement("struts-path"); strutsPathElement.setText("osgi".concat(webContextpath)); children.add(pos + 1, strutsPathElement); } else { String strutsPath = strutsPathElement.getTextTrim(); if (!strutsPath.startsWith(StringPool.SLASH)) { strutsPath = StringPool.SLASH.concat(strutsPath); } strutsPath = "osgi".concat(webContextpath).concat(strutsPath); strutsPathElement.setText(strutsPath); } } content = DDMXMLUtil.formatXML(liferayPortletXMLDoc); FileUtil.write(liferayPortletXMLFile, content); }