Search in sources :

Example 1 with Document

use of com.liferay.portal.kernel.xml.Document in project liferay-ide by liferay.

the class MediaWikiImporter method importPages.

@Override
public void importPages(long userId, WikiNode node, InputStream[] inputStreams, Map<String, String[]> options) throws PortalException {
    if ((inputStreams.length < 1) || (inputStreams[0] == null)) {
        throw new PortalException("The pages file is mandatory");
    }
    InputStream pagesInputStream = inputStreams[0];
    InputStream usersInputStream = inputStreams[1];
    InputStream imagesInputStream = inputStreams[2];
    try {
        Document document = SAXReaderUtil.read(pagesInputStream);
        Map<String, String> usersMap = readUsersFile(usersInputStream);
        Element rootElement = document.getRootElement();
        List<String> specialNamespaces = readSpecialNamespaces(rootElement);
        processSpecialPages(userId, node, rootElement, specialNamespaces);
        processRegularPages(userId, node, rootElement, specialNamespaces, usersMap, imagesInputStream, options);
        processImages(userId, node, imagesInputStream);
        moveFrontPage(userId, node, options);
    } catch (DocumentException de) {
        throw new ImportFilesException("Invalid XML file provided");
    } catch (IOException ioe) {
        throw new ImportFilesException("Error reading the files provided");
    } catch (PortalException pe) {
        throw pe;
    } catch (Exception e) {
        throw new PortalException(e);
    }
}
Also used : InputStream(java.io.InputStream) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) Element(com.liferay.portal.kernel.xml.Element) DocumentException(com.liferay.portal.kernel.xml.DocumentException) PortalException(com.liferay.portal.kernel.exception.PortalException) IOException(java.io.IOException) Document(com.liferay.portal.kernel.xml.Document) NoSuchPageException(com.liferay.portlet.wiki.NoSuchPageException) ImportFilesException(com.liferay.portlet.wiki.ImportFilesException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) DocumentException(com.liferay.portal.kernel.xml.DocumentException) IOException(java.io.IOException) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException)

Example 2 with Document

use of com.liferay.portal.kernel.xml.Document 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)

Aggregations

Document (com.liferay.portal.kernel.xml.Document)2 Element (com.liferay.portal.kernel.xml.Element)2 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 JSONWebServiceActionMapping (com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionMapping)1 MethodParameter (com.liferay.portal.kernel.util.MethodParameter)1 DocumentException (com.liferay.portal.kernel.xml.DocumentException)1 NoSuchTagException (com.liferay.portlet.asset.NoSuchTagException)1 ImportFilesException (com.liferay.portlet.wiki.ImportFilesException)1 NoSuchPageException (com.liferay.portlet.wiki.NoSuchPageException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1