Example usage for com.liferay.portal.kernel.xml XPath booleanValueOf

List of usage examples for com.liferay.portal.kernel.xml XPath booleanValueOf

Introduction

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

Prototype

public boolean booleanValueOf(Object context);

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.internal.util.DDMXMLImpl.java

License:Open Source License

@Override
public Fields getFields(DDMStructure structure, XPath xPath, String xml, List<String> fieldNames)
        throws PortalException {

    Document document = null;/*from  w w  w.  ja v a 2s  .  c o  m*/

    try {
        document = _saxReader.read(xml);
    } catch (DocumentException de) {
        if (_log.isDebugEnabled()) {
            _log.debug(de.getMessage(), de);
        }

        return null;
    }

    if ((xPath != null) && !xPath.booleanValueOf(document)) {
        return null;
    }

    Fields fields = new Fields();

    Element rootElement = document.getRootElement();

    List<Element> dynamicElementElements = rootElement.elements("dynamic-element");

    for (Element dynamicElementElement : dynamicElementElements) {
        String fieldName = dynamicElementElement.attributeValue("name");

        if (!structure.hasField(fieldName) || ((fieldNames != null) && !fieldNames.contains(fieldName))) {

            continue;
        }

        String fieldDataType = structure.getFieldDataType(fieldName);

        List<Element> dynamicContentElements = dynamicElementElement.elements("dynamic-content");

        for (Element dynamicContentElement : dynamicContentElements) {
            String fieldValue = dynamicContentElement.getText();

            String languageId = dynamicContentElement.attributeValue("language-id");

            Locale locale = LocaleUtil.fromLanguageId(languageId);

            Serializable fieldValueSerializable = FieldConstants.getSerializable(fieldDataType, fieldValue);

            Field field = fields.get(fieldName);

            if (field == null) {
                field = new Field();

                String defaultLanguageId = dynamicElementElement.attributeValue("default-language-id");

                if (Validator.isNull(defaultLanguageId)) {
                    defaultLanguageId = rootElement.attributeValue("default-locale");
                }

                Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId);

                field.setDefaultLocale(defaultLocale);

                field.setDDMStructureId(structure.getStructureId());
                field.setName(fieldName);
                field.setValue(locale, fieldValueSerializable);

                fields.put(field);
            } else {
                field.addValue(locale, fieldValueSerializable);
            }
        }
    }

    return fields;
}

From source file:com.liferay.portlet.dynamicdatamapping.service.impl.DDMStructureLocalServiceImpl.java

License:Open Source License

protected void appendNewStructureRequiredFields(DDMStructure structure, Document templateDocument) {

    String xsd = structure.getXsd();

    Document structureDocument = null;

    try {/*w  w w.  jav a2 s . c o  m*/
        structureDocument = SAXReaderUtil.read(xsd);
    } catch (DocumentException de) {
        if (_log.isWarnEnabled()) {
            _log.warn(de, de);
        }

        return;
    }

    Element templateElement = templateDocument.getRootElement();

    XPath structureXPath = SAXReaderUtil
            .createXPath("//dynamic-element[.//meta-data/entry[@name=\"required\"]=" + "\"true\"]");

    List<Node> nodes = structureXPath.selectNodes(structureDocument);

    Iterator<Node> itr = nodes.iterator();

    while (itr.hasNext()) {
        Element element = (Element) itr.next();

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

        XPath templateXPath = SAXReaderUtil.createXPath("//dynamic-element[@name=\"" + name + "\"]");

        if (!templateXPath.booleanValueOf(templateDocument)) {
            templateElement.add(element.createCopy());
        }
    }
}

From source file:com.liferay.portlet.dynamicdatamapping.storage.XMLStorageAdapter.java

License:Open Source License

@Override
protected int doQueryCount(long ddmStructureId, Condition condition) throws Exception {

    XPath conditionXPath = null;

    if (condition != null) {
        conditionXPath = _parseCondition(condition);
    }/* www  .j  a v  a 2 s.  co  m*/

    int count = 0;

    long[] classPKs = _getStructureClassPKs(ddmStructureId);

    for (long classPK : classPKs) {
        DDMContent ddmContent = DDMContentLocalServiceUtil.getContent(classPK);

        Document document = SAXReaderUtil.read(ddmContent.getXml());

        if ((conditionXPath == null) || ((conditionXPath != null) && conditionXPath.booleanValueOf(document))) {

            count++;
        }
    }

    return count;
}

From source file:com.liferay.portlet.dynamicdatamapping.storage.XMLStorageAdapter.java

License:Open Source License

private List<Fields> _doQuery(long ddmStructureId, long[] classPKs, List<String> fieldNames,
        Condition condition, OrderByComparator orderByComparator) throws Exception {

    List<Fields> fieldsList = new ArrayList<Fields>();

    XPath conditionXPath = null;

    if (condition != null) {
        conditionXPath = _parseCondition(condition);
    }/*from w  w  w.  jav  a  2 s. c  o  m*/

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getDDMStructure(ddmStructureId);

    for (long classPK : classPKs) {
        DDMContent ddmContent = DDMContentLocalServiceUtil.getContent(classPK);

        Document document = SAXReaderUtil.read(ddmContent.getXml());

        if ((conditionXPath != null) && !conditionXPath.booleanValueOf(document)) {

            continue;
        }

        Fields fields = new Fields();

        Element rootElement = document.getRootElement();

        List<Element> dynamicElementElements = rootElement.elements("dynamic-element");

        for (Element dynamicElementElement : dynamicElementElements) {
            String fieldName = dynamicElementElement.attributeValue("name");
            String fieldValue = dynamicElementElement.elementText("dynamic-content");

            if (!ddmStructure.hasField(fieldName)
                    || ((fieldNames != null) && !fieldNames.contains(fieldName))) {

                continue;
            }

            String fieldDataType = ddmStructure.getFieldDataType(fieldName);

            Serializable fieldValueSerializable = FieldConstants.getSerializable(fieldDataType, fieldValue);

            Field field = new Field(ddmStructureId, fieldName, fieldValueSerializable);

            fields.put(field);
        }

        fieldsList.add(fields);
    }

    if (orderByComparator != null) {
        Collections.sort(fieldsList, orderByComparator);
    }

    return fieldsList;
}