use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class WebServicesServlet method getWebServicesXML.
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);
}
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();
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class MediaWikiImporter method processSpecialPages.
protected void processSpecialPages(long userId, WikiNode node, Element rootElement, List<String> specialNamespaces) throws PortalException {
ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();
List<Element> pageElements = rootElement.elements("page");
for (int i = 0; i < pageElements.size(); i++) {
Element pageElement = pageElements.get(i);
String title = pageElement.elementText("title");
if (!title.startsWith("Category:")) {
if (isSpecialMediaWikiPage(title, specialNamespaces)) {
rootElement.remove(pageElement);
}
continue;
}
String categoryName = title.substring("Category:".length());
categoryName = normalize(categoryName, 75);
Element revisionElement = pageElement.element("revision");
String description = revisionElement.elementText("text");
description = normalizeDescription(description);
try {
AssetTag assetTag = null;
try {
assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
} catch (NoSuchTagException nste) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(node.getGroupId());
assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
if (PropsValues.ASSET_TAG_PROPERTIES_ENABLED && Validator.isNotNull(description)) {
AssetTagPropertyLocalServiceUtil.addTagProperty(userId, assetTag.getTagId(), "description", description);
}
}
} catch (SystemException se) {
_log.error(se, se);
}
if ((i % 5) == 0) {
progressTracker.setPercent((i * 10) / pageElements.size());
}
}
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class MediaWikiImporter method readSpecialNamespaces.
protected List<String> readSpecialNamespaces(Element root) throws ImportFilesException {
List<String> namespaces = new ArrayList<String>();
Element siteinfoElement = root.element("siteinfo");
if (siteinfoElement == null) {
throw new ImportFilesException("Invalid pages XML file");
}
Element namespacesElement = siteinfoElement.element("namespaces");
List<Element> namespaceElements = namespacesElement.elements("namespace");
for (Element namespaceElement : namespaceElements) {
Attribute attribute = namespaceElement.attribute("key");
String value = attribute.getValue();
if (!value.equals("0")) {
namespaces.add(namespaceElement.getText());
}
}
return namespaces;
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class AdminPortletDataHandler method doImportData.
@Override
protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception {
portletDataContext.importPortletPermissions(RESOURCE_NAME);
Element kbArticlesElement = portletDataContext.getImportDataGroupElement(KBArticle.class);
List<Element> kbArticleElements = kbArticlesElement.elements();
for (Element kbArticleElement : kbArticleElements) {
StagedModelDataHandlerUtil.importStagedModel(portletDataContext, kbArticleElement);
}
Element kbTemplatesElement = portletDataContext.getImportDataGroupElement(KBTemplate.class);
List<Element> kbTemplateElements = kbTemplatesElement.elements();
for (Element kbTemplateElement : kbTemplateElements) {
StagedModelDataHandlerUtil.importStagedModel(portletDataContext, kbTemplateElement);
}
Element kbCommentsElement = portletDataContext.getImportDataGroupElement(KBComment.class);
List<Element> kbCommentElements = kbCommentsElement.elements();
for (Element kbCommentElement : kbCommentElements) {
StagedModelDataHandlerUtil.importStagedModel(portletDataContext, kbCommentElement);
}
return null;
}
use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.
the class KBArticleStagedModelDataHandler method exportKBArticleAttachments.
protected void exportKBArticleAttachments(PortletDataContext portletDataContext, Element kbArticleElement, KBArticle kbArticle) throws Exception {
List<FileEntry> attachmentsFileEntries = kbArticle.getAttachmentsFileEntries();
for (FileEntry fileEntry : attachmentsFileEntries) {
String path = ExportImportPathUtil.getModelPath(kbArticle, fileEntry.getTitle());
Element fileEntryElement = portletDataContext.getExportDataElement(fileEntry);
fileEntryElement.addAttribute("path", path);
fileEntryElement.addAttribute("file-name", fileEntry.getTitle());
portletDataContext.addZipEntry(path, fileEntry.getContentStream());
portletDataContext.addReferenceElement(kbArticle, kbArticleElement, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK, false);
}
}
Aggregations