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

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

Introduction

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

Prototype

public static Document read(URL url, boolean validate) throws DocumentException 

Source Link

Usage

From source file:com.liferay.maven.plugins.compatibility.WSDDBuilder.java

License:Open Source License

public void build() throws Exception {
    if (!FileUtil.exists(_serverConfigFileName)) {
        ClassLoader classLoader = getClass().getClassLoader();

        String serverConfigContent = StringUtil.read(classLoader,
                "com/liferay/portal/tools/dependencies/server-config.wsdd");

        FileUtil.write(_serverConfigFileName, serverConfigContent);
    }/* w ww .j  a  va2 s  . co m*/

    Document document = SAXReaderUtil.read(new File(_fileName), true);

    Element rootElement = document.getRootElement();

    String packagePath = rootElement.attributeValue("package-path");

    Element portletElement = rootElement.element("portlet");
    Element namespaceElement = rootElement.element("namespace");

    if (portletElement != null) {
        _portletShortName = portletElement.attributeValue("short-name");
    } else {
        _portletShortName = namespaceElement.getText();
    }

    _outputPath += StringUtil.replace(packagePath, ".", "/") + "/service/http";

    _packagePath = packagePath;

    List<Element> entityElements = rootElement.elements("entity");

    for (Element entityElement : entityElements) {
        String entityName = entityElement.attributeValue("name");

        boolean remoteService = GetterUtil.getBoolean(entityElement.attributeValue("remote-service"), true);

        if (remoteService) {
            _createServiceWSDD(entityName);

            WSDDMerger.merge(_outputPath + "/" + entityName + "Service_deploy.wsdd", _serverConfigFileName);
        }
    }
}

From source file:com.liferay.portlet.PortletBagFactory.java

License:Open Source License

protected Router newFriendlyURLRouter(Portlet portlet) throws Exception {
    if (Validator.isNull(portlet.getFriendlyURLRoutes())) {
        return null;
    }//  w  w  w. j  av a 2  s .com

    Router router = new RouterImpl();

    String xml = getContent(portlet.getFriendlyURLRoutes());

    Document document = SAXReaderUtil.read(xml, true);

    Element rootElement = document.getRootElement();

    for (Element routeElement : rootElement.elements("route")) {
        String pattern = routeElement.elementText("pattern");

        Route route = router.addRoute(pattern);

        for (Element generatedParameterElement : routeElement.elements("generated-parameter")) {

            String name = generatedParameterElement.attributeValue("name");
            String value = generatedParameterElement.getText();

            route.addGeneratedParameter(name, value);
        }

        for (Element ignoredParameterElement : routeElement.elements("ignored-parameter")) {

            String name = ignoredParameterElement.attributeValue("name");

            route.addIgnoredParameter(name);
        }

        for (Element implicitParameterElement : routeElement.elements("implicit-parameter")) {

            String name = implicitParameterElement.attributeValue("name");
            String value = implicitParameterElement.getText();

            route.addImplicitParameter(name, value);
        }

        for (Element overriddenParameterElement : routeElement.elements("overridden-parameter")) {

            String name = overriddenParameterElement.attributeValue("name");
            String value = overriddenParameterElement.getText();

            route.addOverriddenParameter(name, value);
        }
    }

    return router;
}

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  .ja  va 2  s . 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));
            }
        }
    }
}