Search in sources :

Example 31 with XPath

use of javax.xml.xpath.XPath in project flyway by flyway.

the class MavenTestCase method getPomVersion.

/**
     * Retrieves the version embedded in the project pom. Useful for running these tests in IntelliJ.
     *
     * @return The POM version.
     */
private String getPomVersion() {
    try {
        File pom = new File("pom.xml");
        if (!pom.exists()) {
            return "unknown";
        }
        XPath xPath = XPathFactory.newInstance().newXPath();
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(false);
        Document document = documentBuilderFactory.newDocumentBuilder().parse(pom);
        return xPath.evaluate("/project/version", document);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to read POM version", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) File(java.io.File)

Example 32 with XPath

use of javax.xml.xpath.XPath in project buck by facebook.

the class AndroidXPathFactory method newXPath.

/**
     * Creates a new XPath object, specifying which prefix in the query is used for the
     * android namespace.
     * @param androidPrefix The namespace prefix.
     */
public static XPath newXPath(String androidPrefix) {
    XPath xpath = sFactory.newXPath();
    xpath.setNamespaceContext(new AndroidNamespaceContext(androidPrefix));
    return xpath;
}
Also used : XPath(javax.xml.xpath.XPath)

Example 33 with XPath

use of javax.xml.xpath.XPath in project buck by facebook.

the class AndroidXPathFactory method newXPath.

/**
     * Creates a new XPath object using the default prefix for the android namespace.
     * @see #DEFAULT_NS_PREFIX
     */
public static XPath newXPath() {
    XPath xpath = sFactory.newXPath();
    xpath.setNamespaceContext(AndroidNamespaceContext.getDefault());
    return xpath;
}
Also used : XPath(javax.xml.xpath.XPath)

Example 34 with XPath

use of javax.xml.xpath.XPath in project flyway by flyway.

the class AntLargeTest method getPomVersion.

/**
     * Retrieves the version embedded in the project pom. Useful for running these tests in IntelliJ.
     *
     * @return The POM version.
     */
private String getPomVersion() {
    try {
        File pom = new File("pom.xml");
        if (!pom.exists()) {
            return "unknown";
        }
        XPath xPath = XPathFactory.newInstance().newXPath();
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(false);
        Document document = documentBuilderFactory.newDocumentBuilder().parse(pom);
        return xPath.evaluate("/project/version", document);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to read POM version", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) File(java.io.File)

Example 35 with XPath

use of javax.xml.xpath.XPath in project flyway by flyway.

the class CommandLineLargeTest method getPomVersion.

/**
     * Retrieves the version embedded in the project pom. Useful for running these tests in IntelliJ.
     *
     * @return The POM version.
     */
protected String getPomVersion() {
    try {
        File pom = new File("pom.xml");
        if (!pom.exists()) {
            return "unknown";
        }
        XPath xPath = XPathFactory.newInstance().newXPath();
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(false);
        Document document = documentBuilderFactory.newDocumentBuilder().parse(pom);
        return xPath.evaluate("/project/version", document);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to read POM version", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

XPath (javax.xml.xpath.XPath)197 Document (org.w3c.dom.Document)107 NodeList (org.w3c.dom.NodeList)99 XPathExpressionException (javax.xml.xpath.XPathExpressionException)70 Node (org.w3c.dom.Node)70 XPathExpression (javax.xml.xpath.XPathExpression)69 XPathFactory (javax.xml.xpath.XPathFactory)59 DocumentBuilder (javax.xml.parsers.DocumentBuilder)45 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 IOException (java.io.IOException)32 Element (org.w3c.dom.Element)32 Test (org.junit.Test)25 InputSource (org.xml.sax.InputSource)23 SAXException (org.xml.sax.SAXException)21 File (java.io.File)19 ArrayList (java.util.ArrayList)19 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)18 HashMap (java.util.HashMap)16 InputStream (java.io.InputStream)12 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)11