Example usage for com.liferay.portal.kernel.xml Element content

List of usage examples for com.liferay.portal.kernel.xml Element content

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Element content.

Prototype

public List<Node> content();

Source Link

Usage

From source file:com.liferay.portlet.journal.action.GetArticlesAction.java

License:Open Source License

protected byte[] getContent(HttpServletRequest request, List<JournalArticle> articles) throws Exception {

    long groupId = ParamUtil.getLong(request, "groupId");

    String languageId = LanguageUtil.getLanguageId(request);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Map<String, String> tokens = JournalUtil.getTokens(groupId, themeDisplay);

    Document resultsDoc = SAXReaderUtil.createDocument(StringPool.UTF8);

    Element resultSetEl = resultsDoc.addElement("result-set");

    for (JournalArticle article : articles) {
        Element resultEl = resultSetEl.addElement("result");

        Document articleDoc = SAXReaderUtil.read(article.getContentByLocale(languageId));

        resultEl.content().add(articleDoc.getRootElement().createCopy());

        resultEl = resultEl.element("root");

        JournalUtil.addAllReservedEls(resultEl, tokens, article, languageId);
    }/*from w w w  . j a va 2s  . co m*/

    return DDMXMLUtil.formatXML(resultsDoc).getBytes(StringPool.UTF8);
}

From source file:com.liferay.portlet.journal.model.impl.JournalStructureImpl.java

License:Open Source License

public String getMergedXsd() {
    String parentStructureId = getParentStructureId();

    String xsd = getXsd();/*w ww  .  j  a v  a  2s  . c  o  m*/

    if (Validator.isNull(parentStructureId)) {
        return xsd;
    }

    try {
        JournalStructure parentStructure = null;

        try {
            parentStructure = JournalStructureLocalServiceUtil.getStructure(getGroupId(), parentStructureId);
        } catch (NoSuchStructureException nsse) {
            Group group = GroupLocalServiceUtil.getGroup(getGroupId());

            Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(group.getCompanyId());

            if (getGroupId() == companyGroup.getGroupId()) {
                throw new NoSuchStructureException();
            }

            parentStructure = JournalStructureLocalServiceUtil.getStructure(companyGroup.getGroupId(),
                    parentStructureId);
        }

        Document doc = SAXReaderUtil.read(getXsd());

        Element root = doc.getRootElement();

        Document parentDoc = SAXReaderUtil.read(parentStructure.getMergedXsd());

        Element parentRoot = parentDoc.getRootElement();

        addParentStructureId(parentRoot, parentStructureId);

        root.content().addAll(0, parentRoot.content());

        xsd = root.asXML();
    } catch (Exception e) {
    }

    return xsd;
}

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;// w  w  w.  j av  a2  s  .  c om
    }

    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);
}

From source file:com.liferay.web.extender.internal.webbundle.WebBundleProcessor.java

License:Open Source License

protected void processPortletXML(String webContextpath) throws IOException {
    File portletXMLFile = new File(_deployedAppFolder, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);

    if (!portletXMLFile.exists()) {
        return;/*from  w  ww. ja  va 2s  .co m*/
    }

    String content = FileUtil.read(portletXMLFile);

    Document document = null;

    try {
        document = SAXReaderUtil.read(content);
    } catch (DocumentException de) {
        throw new IOException(de);
    }

    Element rootElement = document.getRootElement();

    List<Element> portletElements = rootElement.elements("portlet");

    for (Element portletElement : portletElements) {
        String portletName = portletElement.elementText("portlet-name");

        String invokerPortletName = "osgi".concat(webContextpath).concat(StringPool.SLASH).concat(portletName);

        XPath xPath = SAXReaderUtil.createXPath(_INVOKER_PORTLET_NAME_XPATH);

        Element invokerPortletNameEl = (Element) xPath.selectSingleNode(portletElement);

        if (invokerPortletNameEl == null) {
            Element portletClassElement = portletElement.element("portlet-class");

            List<Node> children = portletElement.content();

            int pos = children.indexOf(portletClassElement);

            QName qName = rootElement.getQName();

            Element initParamElement = SAXReaderUtil
                    .createElement(SAXReaderUtil.createQName("init-param", qName.getNamespace()));

            initParamElement.addElement("name").setText("com.liferay.portal.invokerPortletName");
            initParamElement.addElement("value").setText(invokerPortletName);

            children.add(pos + 1, initParamElement);
        } else {
            Element valueElement = invokerPortletNameEl.element("value");

            invokerPortletName = valueElement.getTextTrim();

            if (!invokerPortletName.startsWith(StringPool.SLASH)) {
                invokerPortletName = StringPool.SLASH.concat(invokerPortletName);
            }

            invokerPortletName = "osgi".concat(webContextpath).concat(invokerPortletName);

            valueElement.setText(invokerPortletName);
        }
    }

    content = DDMXMLUtil.formatXML(document);

    FileUtil.write(portletXMLFile, content);
}