Example usage for com.liferay.portal.kernel.xml Node getText

List of usage examples for com.liferay.portal.kernel.xml Node getText

Introduction

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

Prototype

public String getText();

Source Link

Usage

From source file:com.liferay.journal.verify.JournalServiceVerifyProcess.java

License:Open Source License

protected void updateLinkToLayoutElements(long groupId, Element element) {
    Element dynamicContentElement = element.element("dynamic-content");

    Node node = dynamicContentElement.node(0);

    String text = node.getText();

    if (!text.isEmpty() && !text.endsWith(StringPool.AT + groupId)) {
        node.setText(dynamicContentElement.getStringValue() + StringPool.AT + groupId);
    }//from w  w  w  .  j a v a 2  s  .  c o  m
}

From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java

License:Open Source License

public static String getXmlDocument(JournalArticle journalArticle, String key) {
    String title = "";
    try {/*from   w  w  w .ja v  a  2  s.  co m*/
        String myContent = journalArticle.getContent();
        com.liferay.portal.kernel.xml.Document document = SAXReaderUtil.read(new StringReader(myContent));
        String keyNode = "/root/dynamic-element[@name='" + key + "']/dynamic-content";
        Node node = document.selectSingleNode(keyNode);
        if (null != node && node.getText().length() > 0) {
            title = node.getText();
        }
    } catch (Exception e) {
        log.error("error while getting value", e);
    }
    return title;
}

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  .ja v  a 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:it.smc.calendar.sync.caldav.methods.ReportMethodImpl.java

License:Open Source License

@Override
protected void addResponse(WebDAVStorage storage, WebDAVRequest webDAVRequest, Resource resource,
        Set<QName> props, Element multistatusElement, long depth) throws Exception {

    List<CalendarBooking> calendarBookings = null;

    List<Node> hrefNodes = CalDAVRequestThreadLocal.getRequestDocument()
            .selectNodes("//*[local-name()='href']");

    if ((hrefNodes.size() > 0) && CalDAVUtil.isCalendarBookingRequest(webDAVRequest)) {

        calendarBookings = new ArrayList<CalendarBooking>();

        CalendarBooking calendarBooking;

        for (Node hrefNode : hrefNodes) {
            calendarBooking = CalDAVUtil.getCalendarBookingFromURL(hrefNode.getText());

            if (calendarBooking != null) {
                calendarBookings.add(calendarBooking);
            }// ww w . j a v  a  2 s . co m
        }
    } else {
        Calendar calendar = (Calendar) resource.getModel();

        Date startDate = null;
        Date endDate = null;

        Element timeRangeElement = CalDAVUtil.getReportDateFilter();

        if ((timeRangeElement != null) && (timeRangeElement.attribute("start") != null)) {

            String startDateStr = timeRangeElement.attribute("start").getValue();

            startDate = new net.fortuna.ical4j.model.Date(startDateStr);
        }

        if ((timeRangeElement != null) && (timeRangeElement.attribute("end") != null)) {

            String endDateStr = timeRangeElement.attribute("end").getValue();

            endDate = new net.fortuna.ical4j.model.Date(endDateStr);
        }

        calendarBookings = CalendarUtil.getCalendarBookings(webDAVRequest.getPermissionChecker(), calendar,
                startDate, endDate);
    }

    for (CalendarBooking calendarBooking : calendarBookings) {
        try {
            addCalendarBookingData(webDAVRequest, resource, calendarBooking, multistatusElement);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }
    }
}