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

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

Introduction

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

Prototype

public Element getParent();

Source Link

Usage

From source file:com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl.java

License:Open Source License

public Map<String, String> getFields(String fieldName, String attributeName, String attributeValue,
        String locale) {//from  w  ww . j a  v a  2  s.  c  o  m

    try {
        StringBundler sb = new StringBundler(7);

        sb.append("//dynamic-element[@name=\"");
        sb.append(fieldName);
        sb.append("\"] //dynamic-element[@");
        sb.append(attributeName);
        sb.append("=\"");
        sb.append(attributeValue);
        sb.append("\"]");

        XPath xPathSelector = SAXReaderUtil.createXPath(sb.toString());

        Node node = xPathSelector.selectSingleNode(getDocument());

        if (node != null) {
            return _getField((Element) node.asXPathResult(node.getParent()), locale);
        }
    } catch (Exception e) {
        _log.error(e, e);
    }

    return null;
}

From source file:com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl.java

License:Open Source License

private Map<String, String> _getField(Element element, String locale) {
    Map<String, String> field = new HashMap<String, String>();

    List<String> availableLocales = getAvailableLocales();

    if ((locale != null) && !(availableLocales.contains(locale))) {
        locale = getDefaultLocale();/*  ww  w  .ja va  2 s  .  c  o m*/
    }

    String xPathExpression = "meta-data[@locale=\"".concat(locale).concat("\"]");

    XPath xPathSelector = SAXReaderUtil.createXPath(xPathExpression);

    Node node = xPathSelector.selectSingleNode(element);

    Element metaDataElement = (Element) node.asXPathResult(node.getParent());

    if (metaDataElement != null) {
        List<Element> childMetaDataElements = metaDataElement.elements();

        for (Element childMetaDataElement : childMetaDataElements) {
            String name = childMetaDataElement.attributeValue("name");
            String value = childMetaDataElement.getText();

            field.put(name, value);
        }
    }

    for (Attribute attribute : element.attributes()) {
        field.put(attribute.getName(), attribute.getValue());
    }

    return field;
}

From source file:it.smc.calendar.sync.caldav.util.CalDAVUtil.java

License:Open Source License

public static Element getReportDateFilter() throws InvalidRequestException {
    try {/*from  w w w  . java2 s.  co  m*/
        Document document = CalDAVRequestThreadLocal.getRequestDocument();

        String xPathExpression = "//*[local-name()='time-range']";

        XPath xPathSelector = SAXReaderUtil.createXPath(xPathExpression);

        Node node = xPathSelector.selectSingleNode(document);

        if (node == null) {
            return null;
        }

        Element timeRangeElement = (Element) node.asXPathResult(node.getParent());

        return timeRangeElement;
    } catch (Exception e) {
        throw new InvalidRequestException(e);
    }
}