Example usage for com.liferay.portal.kernel.xml SAXReaderUtil createXPath

List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createXPath

Introduction

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

Prototype

public static XPath createXPath(String xPathExpression, String prefix, String namespace) 

Source Link

Usage

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

License:Open Source License

protected void processDeclarativeReferences(Attributes attributes) throws IOException {

    // References from web.xml

    File xml = new File(_deployedAppFolder, "WEB-INF/web.xml");

    if (xml.exists()) {
        String content = FileUtil.read(xml);

        Document document = null;

        try {/*from  www.java 2s .  co  m*/
            document = SAXReaderUtil.read(content, false);
        } catch (DocumentException de) {
            throw new IOException(de);
        }

        Element rootElement = document.getRootElement();

        for (String classReference : _WEBXML_CLASSREFERENCE_ELEMENTS) {
            XPath xPath = SAXReaderUtil.createXPath(classReference, "x", "http://java.sun.com/xml/ns/j2ee");

            List<Node> selectNodes = xPath.selectNodes(rootElement);

            for (Node node : selectNodes) {
                String value = node.getText().trim();

                int pos = value.lastIndexOf(StringPool.PERIOD);

                _referencedPackages.add(value.substring(0, pos));
            }
        }
    }

    // References from portlet.xml

    xml = new File(_deployedAppFolder, "WEB-INF/portlet.xml");

    if (xml.exists()) {
        String content = FileUtil.read(xml);

        Document document = null;

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

        Element rootElement = document.getRootElement();

        for (String classReference : _PORTLETXML_CLASSREFERENCE_ELEMENTS) {
            XPath xPath = SAXReaderUtil.createXPath(classReference, "x",
                    "http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd");

            List<Node> selectNodes = xPath.selectNodes(rootElement);

            for (Node node : selectNodes) {
                String value = node.getText().trim();

                int pos = value.lastIndexOf(StringPool.PERIOD);

                _referencedPackages.add(value.substring(0, pos));
            }
        }
    }

    // References from liferay-web.xml

    // TODO do we really need this?

    // References from liferay-portlet.xml

    xml = new File(_deployedAppFolder, "WEB-INF/liferay-portlet.xml");

    if (xml.exists()) {
        String content = FileUtil.read(xml);

        Document document = null;

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

        Element rootElement = document.getRootElement();

        for (String classReference : _LIFERAYPORTLETXML_CLASSREFERENCE_ELEMENTS) {
            XPath xPath = SAXReaderUtil.createXPath(classReference);

            List<Node> selectNodes = xPath.selectNodes(rootElement);

            for (Node node : selectNodes) {
                String value = node.getText().trim();

                int pos = value.lastIndexOf(StringPool.PERIOD);

                _referencedPackages.add(value.substring(0, pos));
            }
        }
    }
}