Example usage for com.liferay.portal.kernel.util FileUtil read

List of usage examples for com.liferay.portal.kernel.util FileUtil read

Introduction

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

Prototype

public static String read(String fileName) throws IOException 

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 {/* w w  w .  j  a va  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));
            }
        }
    }
}

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;//from w w  w. j  a  v a 2 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  w w  .  j  av a 2  s  . c o  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:com.slemarchand.sqlqueryscripting.scripting.sqlquery.SQLQueryExecutor.java

License:Open Source License

public Map<String, Object> eval(Set<String> allowedClasses, Map<String, Object> inputObjects,
        Set<String> outputNames, File script, ClassLoader... classLoaders) throws ScriptingException {
    try {/* w ww  .  j a  v a  2 s.c om*/
        return eval(allowedClasses, inputObjects, outputNames, FileUtil.read(script));
    } catch (IOException e) {
        throw new ScriptingException(e);
    }
}