Example usage for org.apache.commons.jxpath.xml DocumentContainer DocumentContainer

List of usage examples for org.apache.commons.jxpath.xml DocumentContainer DocumentContainer

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.xml DocumentContainer DocumentContainer.

Prototype

public DocumentContainer(URL xmlURL) 

Source Link

Document

Use this constructor if the desired model is DOM.

Usage

From source file:com.photon.maven.plugins.android.AbstractAndroidMojo.java

protected String extractPackageNameFromAndroidManifest(File androidManifestFile) throws MojoExecutionException {
    final URL xmlURL;
    try {//from   www .  jav a2 s.  c  o  m
        xmlURL = androidManifestFile.toURI().toURL();
    } catch (MalformedURLException e) {
        throw new MojoExecutionException(
                "Error while trying to figure out package name from inside AndroidManifest.xml file "
                        + androidManifestFile,
                e);
    }
    final DocumentContainer documentContainer = new DocumentContainer(xmlURL);
    final Object packageName = JXPathContext.newContext(documentContainer).getValue("manifest/@package",
            String.class);
    return (String) packageName;
}

From source file:com.photon.maven.plugins.android.AbstractAndroidMojo.java

/**
 * Attempts to find the instrumentation test runner from inside the
 * AndroidManifest.xml file.//from  w w  w . j a v  a 2 s  .c o  m
 * 
 * @param androidManifestFile
 *            the AndroidManifest.xml file to inspect.
 * @return the instrumentation test runner declared in AndroidManifest.xml,
 *         or {@code null} if it is not declared.
 * @throws MojoExecutionException
 */
protected String extractInstrumentationRunnerFromAndroidManifest(File androidManifestFile)
        throws MojoExecutionException {
    final URL xmlURL;
    try {
        xmlURL = androidManifestFile.toURI().toURL();
    } catch (MalformedURLException e) {
        throw new MojoExecutionException(
                "Error while trying to figure out instrumentation runner from inside AndroidManifest.xml file "
                        + androidManifestFile,
                e);
    }
    final DocumentContainer documentContainer = new DocumentContainer(xmlURL);
    final Object instrumentationRunner;
    try {
        instrumentationRunner = JXPathContext.newContext(documentContainer)
                .getValue("manifest//instrumentation/@android:name", String.class);
    } catch (JXPathNotFoundException e) {
        return null;
    }
    return (String) instrumentationRunner;
}

From source file:com.jayway.maven.plugins.android.AbstractAndroidMojo.java

/**
 * Attempts to find the instrumentation test runner from inside the AndroidManifest.xml file.
 *
 * @param manifestFile the AndroidManifest.xml file to inspect.
 * @return the instrumentation test runner declared in AndroidManifest.xml, or {@code null} if it is not declared.
 * @throws MojoExecutionException//from ww  w .j a  va 2  s  .co m
 */
protected String extractInstrumentationRunnerFromAndroidManifest(File manifestFile)
        throws MojoExecutionException {
    final URL xmlURL;
    try {
        xmlURL = manifestFile.toURI().toURL();
    } catch (MalformedURLException e) {
        throw new MojoExecutionException(
                "Error while trying to figure out instrumentation runner from inside AndroidManifest.xml file "
                        + manifestFile,
                e);
    }
    final DocumentContainer documentContainer = new DocumentContainer(xmlURL);
    final Object instrumentationRunner;
    try {
        instrumentationRunner = JXPathContext.newContext(documentContainer)
                .getValue("manifest//instrumentation/@android:name", String.class);
    } catch (JXPathNotFoundException e) {
        return null;
    }
    return (String) instrumentationRunner;
}