Example usage for javax.xml.xpath XPathExpressionException XPathExpressionException

List of usage examples for javax.xml.xpath XPathExpressionException XPathExpressionException

Introduction

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

Prototype

public XPathExpressionException(Throwable cause) 

Source Link

Document

Constructs a new XPathExpressionException with the specified cause .

Usage

From source file:blueprint.sdk.util.config.Config.java

/**
 * Get value from given XPath//from  w  ww.ja v a  2s  . c  o  m
 *
 * @param xpath XPath to evaluate
 * @return boolean value
 * @throws XPathExpressionException
 */
public boolean getBoolean(String xpath) throws XPathExpressionException {
    try {
        return Boolean.parseBoolean(getString(xpath));
    } catch (NumberFormatException e) {
        throw new XPathExpressionException("evaluated result of '" + xpath + "' is not an Integer");
    }
}

From source file:blueprint.sdk.util.config.Config.java

/**
 * Get value from given XPath//from  w ww  . j a v a2  s. c  om
 *
 * @param xpath XPath to evaluate
 * @return int value
 * @throws XPathExpressionException
 */
public int getInt(String xpath) throws XPathExpressionException {
    try {
        return Integer.parseInt(getString(xpath));
    } catch (NumberFormatException e) {
        throw new XPathExpressionException("evaluated result of '" + xpath + "' is not an Integer");
    }
}

From source file:org.openhim.mediator.denormalization.CSDRequestActor.java

private String getXPAthExpressionForQueryType(BaseResolveIdentifier query) throws XPathExpressionException {
    if (query instanceof ResolveHealthcareWorkerIdentifier) {
        return "//CSD/providerDirectory/provider/@entityID";
    } else if (query instanceof ResolveFacilityIdentifier) {
        return "//CSD/facilityDirectory/facility/@entityID";
    }//w  w  w  .  java2s .co m

    throw new XPathExpressionException("Cannot create expression for unknown BaseResolveIdentifier class");
}

From source file:blueprint.sdk.util.config.Config.java

/**
 * Get value from given XPath/* w  ww  .j  a v  a  2s . c  om*/
 *
 * @param xpath XPath to evaluate
 * @return values as Boolean[]
 * @throws XPathExpressionException
 */
public Boolean[] getBooleanArray(String xpath) throws XPathExpressionException {
    List<Boolean> result = new ArrayList<>(10);

    Iterator<Pointer> nodeIter = JXPathHelper.evaluateIteratorPointers(xpath, context);
    while (nodeIter.hasNext()) {
        Pointer nodePtr = nodeIter.next();

        String value = (String) nodePtr.getValue();
        value = resolveProperty(value);
        try {
            result.add(Boolean.parseBoolean(value));
        } catch (NumberFormatException e) {
            throw new XPathExpressionException("evaluated result of '" + xpath + "' is not a Boolean");
        }
    }

    if (result.size() == 0) {
        warnEmptyValue(xpath, null);
    }

    return result.toArray(new Boolean[result.size()]);
}

From source file:blueprint.sdk.util.config.Config.java

/**
 * Get value from given XPath//www  .j a v a2 s.  c o  m
 *
 * @param xpath XPath to evaluate
 * @return values Integer[]
 * @throws XPathExpressionException
 */
public Integer[] getIntArray(String xpath) throws XPathExpressionException {
    List<Integer> result = new ArrayList<>(10);

    Iterator<Pointer> nodeIter = JXPathHelper.evaluateIteratorPointers(xpath, context);
    while (nodeIter.hasNext()) {
        Pointer nodePtr = nodeIter.next();

        String value = (String) nodePtr.getValue();
        value = resolveProperty(value);
        try {
            result.add(Integer.parseInt(value));
        } catch (NumberFormatException e) {
            throw new XPathExpressionException("evaluated result of '" + xpath + "' is not an Integer");
        }
    }

    if (result.size() == 0) {
        warnEmptyValue(xpath, null);
    }

    return result.toArray(new Integer[result.size()]);
}

From source file:com.mercatis.lighthouse3.commons.commons.XmlMuncher.java

/**
 * This method translates an XPath expression into a regular expression that
 * matches on the path of an XML element iff the XPath expression would
 * match that element as well.//from www. j a  v  a  2s .co  m
 * <p/>
 * Note that only simple expressions on elements using *, /:, and //: are
 * supported.
 *
 * @param xpathExpression the XPath expression to translate
 * @return the regular expression equivalent to the XPath expression.
 * @throws XPathExpressionException in case of trouble with the XPath expression.
 */
private Pattern translateXPathExpressionToRegexp(String xpathExpression) throws XPathExpressionException {
    StringBuilder regularExpression = new StringBuilder("^");

    for (String token : this.tokenizeXPathExpression(xpathExpression)) {
        if (XPATH_DIRECT_CHILD.equals(token))
            regularExpression.append(Pattern.quote("/"));
        else if (XPATH_ANY_ELEMENT.equals(token))
            regularExpression.append("([A-Za-z0-9_:]+)");
        else if (XPATH_INDIRECT_CHILD.equals(token))
            regularExpression.append("(").append(Pattern.quote("/")).append("[A-Za-z0-9_:]*)+");
        else
            regularExpression.append("(").append(Pattern.quote(token)).append(")");
    }

    try {
        return Pattern.compile(regularExpression.toString());
    } catch (PatternSyntaxException e) {
        throw new XPathExpressionException(e);
    }
}

From source file:com.mnxfst.testing.server.cfg.PTestServerConfigurationParser.java

/**
 * Evaluates the given expression on the referenced document into a result object of type string
 * @param expression/*from  www . ja  va 2  s.co  m*/
 * @param document
 * @return
 * @throws XPathExpressionException
 */
protected String evaluateString(XPathExpression expression, Object document) throws XPathExpressionException {
    if (expression == null)
        throw new XPathExpressionException("Null is not a valid expression");
    if (document == null)
        throw new XPathExpressionException("An xpath expression must not be applied to a NULL document");

    return (String) expression.evaluate(document, XPathConstants.STRING);
}

From source file:com.mnxfst.testing.server.cfg.PTestServerConfigurationParser.java

/**
 * Evaluates the given expression on the referenced document and returns a result object of type string
 * @param expression//from w w  w.  java2s  . co  m
 * @param document
 * @return
 * @throws XPathExpressionException
 */
protected Integer evaluateInteger(XPathExpression expression, Object document) throws XPathExpressionException {

    String value = evaluateString(expression, document);
    if (value != null && !value.isEmpty()) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new XPathExpressionException(
                    "Failed to parse numerical value from evaluate string '" + value + "'");
        }
    }
    return null;
}

From source file:com.mnxfst.testing.server.cfg.PTestServerConfigurationParser.java

/**
 * Evaluates the given expression on the referenced document and returns a result object of type {@link NodeList} 
 * @param expression//from  w  w  w.  ja  va 2  s. c o  m
 * @param document
 * @return
 * @throws XPathExpressionException
 */
protected NodeList evaluateNodeList(XPathExpression expression, Object document)
        throws XPathExpressionException {
    if (expression == null)
        throw new XPathExpressionException("Null is not a valid expression");
    if (document == null)
        throw new XPathExpressionException("An xpath expression must not be applied to a NULL document");

    return (NodeList) expression.evaluate(document, XPathConstants.NODESET);
}

From source file:de.codesourcery.jasm16.ide.ProjectConfiguration.java

private String getValue(XPathExpression expr, Document doc) throws XPathExpressionException {
    List<String> values = getValues(expr, doc);
    if (values.isEmpty()) {
        throw new XPathExpressionException("Project XML lacks node matching " + expr);
    }//from w  ww  .  j  ava2s.  co m
    if (values.size() != 1) {
        throw new XPathExpressionException("Project XML contains more than one node matching " + expr);
    }
    return values.get(0);
}