Example usage for javax.xml.xpath XPathConstants STRING

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

Introduction

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

Prototype

QName STRING

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

Click Source Link

Document

The XPath 1.0 string data type.

Maps to Java String .

Usage

From source file:Main.java

public static String get(String path, Node e) {
    return (String) evaluateXPath(path, e, XPathConstants.STRING);
}

From source file:com.digitalpebble.stormcrawler.util.RefreshTag.java

public static String extractRefreshURL(DocumentFragment doc) {
    String value;// w  ww  .  ja  va2 s. c  o m
    try {
        value = (String) expression.evaluate(doc, XPathConstants.STRING);
    } catch (XPathExpressionException e) {
        return null;
    }
    if (StringUtils.isBlank(value))
        return null;
    // 0;URL=http://www.apollocolors.com/site
    if (matcher.reset(value).matches()) {
        return matcher.group(1);
    }
    return null;
}

From source file:Main.java

public static String evaluateStringXPath(final Document document, final XPathExpression expression)
        throws XPathExpressionException {
    notNull(document);// w  w  w.j  av a  2  s  . c  om
    notNull(expression);

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

From source file:Main.java

/**
 * <p>//from   ww w .jav  a 2 s  . com
 * Evaluates the given XPath expression in the context of the given item, with
 * the expectation of a string result.
 * </p>
 * 
 * @param xpe
 *          An XPath expression.
 * @param item
 *          A context item.
 * @return The result of the evaluation as a {@link String}.
 * @throws XPathExpressionException
 *           if the evaluation fails
 * @since 1.67.5
 * @see XPathConstants#STRING
 */
public static String evaluateString(XPathExpression xpe, Object item) throws XPathExpressionException {
    return (String) xpe.evaluate(item, XPathConstants.STRING);
}

From source file:Main.java

public static String findInXml(String xml, String xpath) {
    try {/*from  ww w  . ja v a2 s .  c  o  m*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(new EntityResolver() {
            @Override
            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                //                    if (systemId.contains("foo.dtd")) {
                return new InputSource(new StringReader(""));
                //                    } else {
                //                        return null;
                //                    }
            }
        });
        Document doc = builder.parse(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPathExpression expr = xPathfactory.newXPath().compile(xpath);
        return (String) expr.evaluate(doc, XPathConstants.STRING);
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}

From source file:org.opencastproject.remotetest.util.JobUtils.java

/**
 * Checks whether the given workflow is in the requested state.
 * // www.  j  av  a 2 s. c  o  m
 * @param jobId
 *          identifier of the workflow
 * @param state
 *          the state that the workflow is expected to be in
 * @return <code>true</code> if the workflow is in the expected state
 * @throws IllegalStateException
 *           if the specified workflow can't be found
 */
public static boolean isJobInState(String jobId, String state) throws IllegalStateException, Exception {
    String jobXml = getJobAsXml(jobId);
    String currentState = (String) Utils.xpath(jobXml, "/*[local-name() = 'job']/@status",
            XPathConstants.STRING);
    return state.equalsIgnoreCase(currentState);
}

From source file:eu.planets_project.tb.utils.XCDLParser.java

/**
 * //from  w ww.  ja v  a  2s. c o  m
 * @param xcdlDoc
 * @return
 * @throws XPathExpressionException
 */
public static List<MeasurementImpl> parseXCDL(Document xcdlDoc) throws XPathExpressionException {
    List<MeasurementImpl> props = new Vector<MeasurementImpl>();

    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList nodes = (NodeList) xpath.evaluate("/*//property", xcdlDoc, XPathConstants.NODESET);

    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        String name = (String) xpath.evaluate("./name", n, XPathConstants.STRING);
        String id = (String) xpath.evaluate("./name/@id", n, XPathConstants.STRING);
        // Loop through the property definitions and patch them into Property objects.
        MeasurementImpl m = new MeasurementImpl(makePropertyUri(id, name),
                (String) xpath.evaluate("./valueSet/labValue/val", n, XPathConstants.STRING));
        // FIXME Unify this construction: See also XCDLService.createPropertyFromFFProp
        //            m.setType( "xcdl:" + (String) xpath.evaluate( "./valueSet/labValue/type", n,  XPathConstants.STRING) );

        props.add(m);
    }

    return props;
}

From source file:com.thinkbiganalytics.feedmgr.nifi.NifiTemplateParser.java

/**
 * @param nifiTemplate the nifi template xml string
 * @return the name of the template//from w  w w  .  j  a  v a 2  s  . co  m
 */
public static String getTemplateName(String nifiTemplate)
        throws ParserConfigurationException, XPathExpressionException, IOException, SAXException {

    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();

    InputSource source = new InputSource(new StringReader(nifiTemplate));
    String name = (String) xpath.evaluate("/template/name", source, XPathConstants.STRING);
    return name;
}

From source file:Main.java

public static String getString(String xPathExpression, Node node) throws XPathExpressionException {
    return (String) xPath.evaluate(xPathExpression, node, XPathConstants.STRING);
}

From source file:Main.java

private static String getEmployeeNameById(Document doc, XPath xpath, int id) throws Exception {
    String name = null;/*w w w. j av  a  2s.  co m*/
    XPathExpression expr = xpath.compile("/Employees/Employee[@id='" + id + "']/name/text()");
    name = (String) expr.evaluate(doc, XPathConstants.STRING);
    return name;
}