List of usage examples for com.liferay.portal.kernel.xml Document add
public void add(Comment comment);
From source file:com.hrportal.service.impl.WebArticleHelperLocalServiceImpl.java
License:Open Source License
public Document generateAssetCategoryHierarchyDocument() { Document doc = SAXReaderUtil.createDocument(); doc.add(SAXReaderUtil.createElement("v")); Element vocabulariesElem = doc.getRootElement(); ServiceContext sc = ServiceContextThreadLocal.getServiceContext(); HashMap<String, Element> map = new HashMap<String, Element>(); try {/*from www . j av a 2 s. com*/ // Group globalGroup = GroupLocalServiceUtil.getCompanyGroup(sc.getCompanyId()); List<AssetVocabulary> vocabularies = AssetVocabularyLocalServiceUtil .getCompanyVocabularies(sc.getCompanyId()); for (AssetVocabulary vocab : vocabularies) { Element vocabElem = generateAssetVocabularyElement(vocab); vocabulariesElem.add(vocabElem); map.put("v".concat(String.valueOf(vocab.getVocabularyId())), vocabElem); } List<AssetCategory> catList = AssetCategoryLocalServiceUtil.getCategories(); for (AssetCategory cat : catList) { Element catElem = generateAssetCategoryElement(cat); map.put(String.valueOf(cat.getCategoryId()), catElem); } for (AssetCategory cat : catList) { Element catElem = map.get(String.valueOf(cat.getCategoryId())); Element vocabElem = map.get("v".concat(String.valueOf(cat.getVocabularyId()))); Element parentCatElem = map.get(String.valueOf(cat.getParentCategoryId())); if (parentCatElem != null) { parentCatElem.add(catElem); } else { vocabElem.add(catElem); } } } catch (Exception e) { _log.error("", e); } return doc; }
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); 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); }/*ww w . ja va 2s . c o m*/ 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 w w w . j a v a 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); }