Example usage for com.liferay.portal.kernel.xml QName getNamespace

List of usage examples for com.liferay.portal.kernel.xml QName getNamespace

Introduction

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

Prototype

public Namespace getNamespace();

Source Link

Usage

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;//  w  ww  .j a  v a 2  s  .  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);
}

From source file:it.smc.calendar.sync.caldav.BasePropsProcessor.java

License:Open Source License

protected void processCustomProperties(Set<QName> props) throws Exception {

    WebDAVProps webDavProps = WebDAVPropsLocalServiceUtil.getWebDAVProps(webDAVRequest.getCompanyId(),
            resource.getClassName(), resource.getPrimaryKey());

    Set<QName> customProps = webDavProps.getPropsSet();

    for (QName qname : props) {
        String name = qname.getName();
        Namespace namespace = qname.getNamespace();

        String prefix = namespace.getPrefix();
        String uri = namespace.getURI();

        if (customProps.contains(qname)) {
            String text = webDavProps.getText(name, prefix, uri);

            DocUtil.add(successPropElement, qname, text);
        } else {/*from   w  w  w . java 2s. c om*/
            DocUtil.add(failurePropElement, qname);
        }
    }
}