Search in sources :

Example 16 with Element

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();
}
Also used : JSONWebServiceActionMapping(com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionMapping) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Element(com.liferay.portal.kernel.xml.Element) Document(com.liferay.portal.kernel.xml.Document) MethodParameter(com.liferay.portal.kernel.util.MethodParameter)

Example 17 with Element

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());
        }
    }
}
Also used : AssetTag(com.liferay.portlet.asset.model.AssetTag) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException) SystemException(com.liferay.portal.kernel.exception.SystemException) ProgressTracker(com.liferay.portal.kernel.util.ProgressTracker) ServiceContext(com.liferay.portal.service.ServiceContext) Element(com.liferay.portal.kernel.xml.Element)

Example 18 with Element

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;
}
Also used : Attribute(com.liferay.portal.kernel.xml.Attribute) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) Element(com.liferay.portal.kernel.xml.Element) ArrayList(java.util.ArrayList)

Example 19 with Element

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;
}
Also used : Element(com.liferay.portal.kernel.xml.Element)

Example 20 with Element

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);
    }
}
Also used : Element(com.liferay.portal.kernel.xml.Element) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

Element (com.liferay.portal.kernel.xml.Element)22 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)5 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)5 ServiceContext (com.liferay.portal.service.ServiceContext)4 InputStream (java.io.InputStream)4 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)3 SystemException (com.liferay.portal.kernel.exception.SystemException)3 UnsyncByteArrayInputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)3 NoSuchTagException (com.liferay.portlet.asset.NoSuchTagException)3 ImportFilesException (com.liferay.portlet.wiki.ImportFilesException)3 Artist (org.liferay.jukebox.model.Artist)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 KBFolder (com.liferay.knowledgebase.model.KBFolder)2 PortalException (com.liferay.portal.kernel.exception.PortalException)2 ProgressTracker (com.liferay.portal.kernel.util.ProgressTracker)2 Document (com.liferay.portal.kernel.xml.Document)2 DocumentException (com.liferay.portal.kernel.xml.DocumentException)2 NoSuchFileException (com.liferay.portlet.documentlibrary.NoSuchFileException)2 NoSuchPageException (com.liferay.portlet.wiki.NoSuchPageException)2 IOException (java.io.IOException)2