Example usage for javax.xml.xpath XPathConstants BOOLEAN

List of usage examples for javax.xml.xpath XPathConstants BOOLEAN

Introduction

In this page you can find the example usage for javax.xml.xpath XPathConstants BOOLEAN.

Prototype

QName BOOLEAN

To view the source code for javax.xml.xpath XPathConstants BOOLEAN.

Click Source Link

Document

The XPath 1.0 boolean data type.

Maps to Java Boolean .

Usage

From source file:de.qucosa.webapi.v1.DocumentResource.java

private void updateFileElementsInPlace(Document targetDocument, Document updateDocument,
        List<FileUpdateOperation> fileUpdateOperations, Element targetRoot, Element updateRoot,
        List<String> purgeDatastreamList) throws XPathExpressionException, FedoraClientException, IOException {
    List<Node> targetFileNodes = getChildNodesByName(targetRoot, "File");
    List<Node> updateFileNodes = getChildNodesByName(updateRoot, "File");
    for (Node targetNode : targetFileNodes) {
        Node idAttr = targetNode.getAttributes().getNamedItem("id");
        if (idAttr != null) {
            String idAttrValue = idAttr.getTextContent();
            if (!idAttrValue.isEmpty() && !((Boolean) xPath.evaluate("//File[@id='" + idAttrValue + "']",
                    updateDocument, XPathConstants.BOOLEAN))) {
                purgeDatastreamList.add(DSID_QUCOSA_ATT.concat(idAttrValue));
            }/*from   ww  w. ja v a2  s  .  c o m*/
        }
    }
    for (Node updateNode : updateFileNodes) {
        Node idAttr = updateNode.getAttributes().getNamedItem("id");
        if (idAttr == null) {
            targetDocument.adoptNode(updateNode);
            targetRoot.appendChild(updateNode);
        } else {
            String idAttrValue = idAttr.getTextContent();
            Node targetNode = (Node) xPath.evaluate("//File[@id='" + idAttrValue + "']", targetDocument,
                    XPathConstants.NODE);
            FileUpdateOperation fupo = updateFileNodeWith((Element) targetNode, (Element) updateNode);
            fupo.setDsid(DSID_QUCOSA_ATT.concat(idAttrValue));
            fileUpdateOperations.add(fupo);
        }
    }
}

From source file:de.qucosa.webapi.v1.DocumentResource.java

private void assertBasicDocumentProperties(Document qucosaDocument) throws Exception {
    assertXPathNodeExists("/Opus[@version='2.0']", "No Opus node with version '2.0'.", qucosaDocument);
    assertXPathNodeExists("/Opus/Opus_Document", "No Opus_Document node found.", qucosaDocument);
    if ((Boolean) xPath.evaluate("/Opus/Opus_Document/PersonAuthor[1]", qucosaDocument,
            XPathConstants.BOOLEAN)) {
        assertXPathNodeExists("/Opus/Opus_Document/PersonAuthor[1]/LastName",
                "No PersonAuthor node with LastName node found.", qucosaDocument);
    }//from   w  w w. j av a  2  s.  c  om
    assertXPathNodeExists("/Opus/Opus_Document/TitleMain[1]/Value", "No TitleMain node found.", qucosaDocument);
}

From source file:net.ymate.framework.commons.XPathHelper.java

public Boolean getBooleanValue(String expression) throws XPathExpressionException {
    return (Boolean) __doEvaluate(expression, null, XPathConstants.BOOLEAN);
}

From source file:net.ymate.framework.commons.XPathHelper.java

public Boolean getBooleanValue(Object item, String expression) throws XPathExpressionException {
    return (Boolean) __doEvaluate(expression, item, XPathConstants.BOOLEAN);
}

From source file:nz.co.testamation.core.matcher.HasXPathMatcher.java

public boolean matchesSafely(Node item) {
    String xPathResult;//from  w  ww . ja v  a 2 s  . c om
    boolean matched;
    try {
        if (hasMatchers()) {
            xPathResult = (String) compiledXPath.evaluate(item, XPathConstants.STRING);
            matched = getMatcher().matches(xPathResult);
        } else {
            matched = (Boolean) compiledXPath.evaluate(item, XPathConstants.BOOLEAN);
            xPathResult = Boolean.toString(matched);
        }
    } catch (XPathExpressionException e) {
        xPathResult = "Failed to execute xpath: " + xpathString;
        matched = false;
    }

    if (!matched) {
        String matcherDescription = null;
        if (getMatcher() != null) {
            Description description = new StringDescription();
            getMatcher().describeTo(description);
            matcherDescription = description.toString();
        }
        logger.info(String.format("XPath failed: %s%s", xpathString,
                matcherDescription != null ? ",  actual: '" + xPathResult + "', expected: " + matcherDescription
                        : ""));
    }
    return matched;
}

From source file:org.apache.camel.builder.xml.XPathBuilder.java

public boolean matches(Exchange exchange) {
    Object booleanResult = evaluateAs(exchange, XPathConstants.BOOLEAN);
    return exchange.getContext().getTypeConverter().convertTo(Boolean.class, booleanResult);
}

From source file:org.apache.camel.builder.xml.XPathBuilder.java

/**
 * Sets the expression result type to boolean
 *
 * @return the current builder//from  ww w .  j av  a2s  .  c  o m
 */
public XPathBuilder booleanResult() {
    resultQName = XPathConstants.BOOLEAN;
    return this;
}

From source file:org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime.java

/**
 * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluateAsBoolean(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext)
 *//* w  w  w .  jav a  2s.c  o m*/
public boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx)
        throws FaultException, EvaluationException {
    return (Boolean) evaluate(cexp, ctx, XPathConstants.BOOLEAN);
}

From source file:org.apache.ode.bpel.elang.xquery10.runtime.XQuery10ExpressionRuntime.java

/**
 * Cast XQuery sequence into an opaque list
 *
 * @param type type/*from w  w  w.j a v  a  2s.  c o  m*/
 * @param result result
 *
 * @return value
 *
 * @throws XQException XQException
 */
private Object getResultValue(QName type, XQResultSequence result) throws XQException {
    Document document = DOMUtils.newDocument();
    Object resultValue = null;
    if (XPathConstants.NODESET.equals(type)) {
        List list = new ArrayList();

        while (result.next()) {
            Object itemValue = getItemValue(result.getItem());
            if (itemValue instanceof Document) {
                itemValue = DOMUtils.cloneNode(document, ((Document) itemValue).getDocumentElement());
            } else if (itemValue instanceof Node) {
                itemValue = DOMUtils.cloneNode(document, (Node) itemValue);
            }

            if (itemValue != null) {
                list.add(itemValue);
            }
        }

        resultValue = list;
    } else if (XPathConstants.NODE.equals(type)) {
        XQItem item = null;
        if (result.count() > 0) {
            result.first();
            if (result.isOnItem()) {
                item = result.getItem();
            }
        }
        if (item != null) {
            resultValue = getItemValue(item);
            if (resultValue instanceof Node) {
                resultValue = DOMUtils.cloneNode(document, (Node) resultValue);
            }
        }
    } else if (XPathConstants.STRING.equals(type)) {
        resultValue = result.getSequenceAsString(new Properties());
    } else if (XPathConstants.NUMBER.equals(type)) {
        resultValue = result.getSequenceAsString(new Properties());
        resultValue = Integer.parseInt((String) resultValue);
    } else if (XPathConstants.BOOLEAN.equals(type)) {
        resultValue = result.getSequenceAsString(new Properties());
        resultValue = Boolean.parseBoolean((String) resultValue);
    }
    return resultValue;
}

From source file:org.apache.ode.bpel.rtrep.v1.xpath10.jaxp.JaxpXPath10ExpressionRuntime.java

public boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx) throws FaultException {
    return (Boolean) evaluate(cexp, ctx, XPathConstants.BOOLEAN);
}