com.android.io.StreamException Java Examples

The following examples show how to use com.android.io.StreamException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidProjectManager.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void copyLibrary(AndroidAppProject project, boolean useCompatLibrary)
        throws IOException, StreamException, SAXException, ParserConfigurationException {
    if (useCompatLibrary) {
        //v7
        addLib(project, "libs/27.1.1/android.arch.core-common-1.1.0.jar", "android.arch.core-common-1.1.0.jar");
        addLib(project, "libs/27.1.1/android.arch.core-runtime-1.1.0.aar", "android.arch.core-runtime-1.1.0");
        addLib(project, "libs/27.1.1/android.arch.lifecycle-common-1.1.0.jar", "android.arch.lifecycle-common-1.1.0.jar");
        addLib(project, "libs/27.1.1/android.arch.lifecycle-livedata-core-1.1.0.aar", "android.arch.lifecycle-livedata-core-1.1.0");
        addLib(project, "libs/27.1.1/android.arch.lifecycle-runtime-1.1.0.aar", "android.arch.lifecycle-runtime-1.1.0");
        addLib(project, "libs/27.1.1/android.arch.lifecycle-viewmodel-1.1.0.aar", "android.arch.lifecycle-viewmodel-1.1.0");
        addLib(project, "libs/27.1.1/appcompat-v7-27.1.1.aar", "appcompat-v7-27.1.1");
        addLib(project, "libs/27.1.1/animated-vector-drawable-27.1.1.aar", "animated-vector-drawable-27.1.1");
        addLib(project, "libs/27.1.1/support-compat-27.1.1.aar", "support-compat-27.1.1");
        addLib(project, "libs/27.1.1/support-core-ui-27.1.1.aar", "support-core-ui-27.1.1");
        addLib(project, "libs/27.1.1/support-core-utils-27.1.1.aar", "support-core-utils-27.1.1");
        addLib(project, "libs/27.1.1/support-fragment-27.1.1.aar", "support-fragment-27.1.1");
        addLib(project, "libs/27.1.1/support-vector-drawable-27.1.1.aar", "support-vector-drawable-27.1.1");
        addLib(project, "libs/27.1.1/support-annotations-27.1.1.jar", "support-annotations-27.1.1.jar");
        addLib(project, "libs/27.1.1/support-media-compat-27.1.1.aar", "support-media-compat-27.1.1");
        addLib(project, "libs/27.1.1/support-v4-27.1.1.aar", "support-v4-27.1.1");
    }
}
 
Example #2
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath)
        throws StreamException, XPathExpressionException {
    XPath xpath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = file.getContents();
        return xpath.evaluate(xPath, new InputSource(is));
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }
}
 
Example #3
Source File: AndroidManifestParser.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses the Android Manifest from an {@link InputStream}, and returns a {@link ManifestData}
 * object containing the result of the parsing.
 *
 * @param manifestFileStream the {@link InputStream} representing the manifest file.
 * @return A class containing the manifest info obtained during the parsing or null on error.
 *
 * @throws StreamException
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public static ManifestData parse(InputStream manifestFileStream)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    if (manifestFileStream != null) {
        SAXParser parser = sParserFactory.newSAXParser();

        ManifestData data = new ManifestData();

        ManifestHandler manifestHandler = new ManifestHandler(null, data, null);
        parser.parse(new InputSource(manifestFileStream), manifestHandler);

        return data;
    }

    return null;
}
 
Example #4
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of the minSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the attribute value.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getMinSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_MIN_SDK_VERSION);

    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #5
Source File: AndroidManifestParser.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the Android Manifest from an {@link InputStream}, and returns a {@link ManifestData}
 * object containing the result of the parsing.
 *
 * @param manifestFileStream the {@link InputStream} representing the manifest file.
 * @return A class containing the manifest info obtained during the parsing or null on error.
 *
 * @throws StreamException
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public static ManifestData parse(InputStream manifestFileStream)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    if (manifestFileStream != null) {
        SAXParser parser = sParserFactory.newSAXParser();

        ManifestData data = new ManifestData();

        ManifestHandler manifestHandler = new ManifestHandler(null, data, null);
        parser.parse(new InputSource(manifestFileStream), manifestHandler);

        return data;
    }

    return null;
}
 
Example #6
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the value of the minSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the attribute value.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getMinSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_MIN_SDK_VERSION);

    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #7
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath)
        throws StreamException, XPathExpressionException {
    XPath xpath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = file.getContents();
        return xpath.evaluate(xPath, new InputSource(is));
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }
}
 
Example #8
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the package for a given project.
 * @param projectFolder the folder of the project.
 * @return the package info or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getPackage(IAbstractFolder projectFolder)
        throws XPathExpressionException, StreamException {
    IAbstractFile file = getManifest(projectFolder);
    if (file != null) {
        return getPackage(file);
    }

    return null;
}
 
Example #9
Source File: AndroidManifestParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static ManifestData parse(IAbstractFolder projectFolder)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    IAbstractFile manifestFile = AndroidManifest.getManifest(projectFolder);
    if (manifestFile == null) {
        throw new FileNotFoundException();
    }

    return parse(manifestFile, true, null);
}
 
Example #10
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the package for a given project.
 * @param projectFolder the folder of the project.
 * @return the package info or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getPackage(IAbstractFolder projectFolder)
        throws XPathExpressionException, StreamException {
    IAbstractFile file = getManifest(projectFolder);
    if (file != null) {
        return getPackage(file);
    }

    return null;
}
 
Example #11
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the manifest is set to make the application debuggable.
 *
 * If the give manifest does not contain the debuggable attribute then the application
 * is considered to not be debuggable.
 *
 * @param manifestFile the manifest to parse.
 * @return true if the application is debuggable.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean getDebuggable(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String value = getStringValue(manifestFile,
            "/"  + NODE_MANIFEST +
            "/"  + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":"  + ATTRIBUTE_DEBUGGABLE);

    // default is not debuggable, which is the same behavior as parseBoolean
    return Boolean.parseBoolean(value);
}
 
Example #12
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value of the versionCode attribute or -1 if the value is not set.
 * @param manifestFile the manifest file to read the attribute from.
 * @return the integer value or -1 if not set.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static int getVersionCode(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_VERSIONCODE);

    try {
        return Integer.parseInt(result);
    } catch (NumberFormatException e) {
        return -1;
    }
}
 
Example #13
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the version Code attribute is set in a given manifest.
 * @param manifestFile the manifest to check
 * @return true if the versionCode attribute is present and its value is not empty.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean hasVersionCode(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    XPath xPath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = manifestFile.getContents();
        Object result = xPath.evaluate(
                "/"  + NODE_MANIFEST +
                "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
                ":"  + ATTRIBUTE_VERSIONCODE,
                new InputSource(is),
                XPathConstants.NODE);

        if (result != null) {
            Node node  = (Node)result;
            if (!node.getNodeValue().isEmpty()) {
                return true;
            }
        }
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }

    return false;
}
 
Example #14
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value of the targetSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the integer value or -1 if not set.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getTargetSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_TARGET_SDK_VERSION);
    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #15
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the application icon  for a given manifest.
 * @param manifestFile the manifest to parse.
 * @return the icon or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getApplicationIcon(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    return getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_ICON);
}
 
Example #16
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the application label  for a given manifest.
 * @param manifestFile the manifest to parse.
 * @return the label or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getApplicationLabel(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    return getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_LABEL);
}
 
Example #17
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the manifest is set to make the application RTL aware.
 *
 * If the give manifest does not contain the supportsRtl attribute then the application
 * is considered to not be not supporting RTL (there will be no layout mirroring).
 *
 * @param manifestFile the manifest to parse.
 * @return true if the application is supporting RTL.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean getSupportsRtl(IAbstractFile manifestFile)
    throws XPathExpressionException, StreamException {

    String value = getStringValue(manifestFile,
            "/"  + NODE_MANIFEST +
            "/"  + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":"  + ATTRIBUTE_SUPPORTS_RTL);

    // default is not debuggable, which is the same behavior as parseBoolean
    return Boolean.parseBoolean(value);
}
 
Example #18
Source File: AARLibrary.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the package name from the Android Archive without needing to unzip it to a location
 * in the file system
 *
 * @param zip the input stream reading from the Android Archive.
 * @return the package name declared in the archive's AndroidManifest.xml.
 * @throws IOException if reading the input stream fails.
 */
private String extractPackageName(ZipFile zip) throws IOException {
  ZipEntry entry = zip.getEntry("AndroidManifest.xml");
  if (entry == null) {
    throw new IllegalArgumentException(zip.getName() + " does not contain AndroidManifest.xml");
  }
  try {
    ZipEntryWrapper wrapper = new ZipEntryWrapper(zip.getInputStream(entry));
    // the following call will automatically close the input stream opened above
    return AndroidManifest.getPackage(wrapper);
  } catch(StreamException|XPathExpressionException e) {
    throw new IOException("Exception processing AndroidManifest.xml", e);
  }
}
 
Example #19
Source File: ResourceShrinkerAction.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static Set<String> getManifestPackages(Path primaryManifest, List<Path> otherManifests)
    throws SAXException, IOException, StreamException, ParserConfigurationException {
  Set<String> manifestPackages = new LinkedHashSet<>();
  manifestPackages.add(getManifestPackage(primaryManifest));
  for (Path manifest : otherManifests) {
    manifestPackages.add(getManifestPackage(manifest));
  }
  return manifestPackages;
}
 
Example #20
Source File: AndroidManifestParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses the Android Manifest, and returns a {@link ManifestData} object containing the
 * result of the parsing.
 *
 * @param manifestFile the {@link IAbstractFile} representing the manifest file.
 * @param gatherData indicates whether the parsing will extract data from the manifest. If false
 * the method will always return null.
 * @param errorHandler an optional errorHandler.
 * @return A class containing the manifest info obtained during the parsing, or null on error.
 *
 * @throws StreamException
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public static ManifestData parse(
        IAbstractFile manifestFile,
        boolean gatherData,
        ManifestErrorHandler errorHandler)
            throws SAXException, IOException, StreamException, ParserConfigurationException {
    if (manifestFile != null) {
        SAXParser parser = sParserFactory.newSAXParser();

        ManifestData data = null;
        if (gatherData) {
            data = new ManifestData();
        }

        ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
                data, errorHandler);
        InputStream is = manifestFile.getContents();
        try {
            parser.parse(new InputSource(is), manifestHandler);
        } finally {
            try {
                Closeables.close(is, true /* swallowIOException */);
            } catch (IOException e) {
                // cannot happen
            }
        }

        return data;
    }

    return null;
}
 
Example #21
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the manifest is set to make the application debuggable.
 *
 * If the give manifest does not contain the debuggable attribute then the application
 * is considered to not be debuggable.
 *
 * @param manifestFile the manifest to parse.
 * @return true if the application is debuggable.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean getDebuggable(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String value = getStringValue(manifestFile,
            "/"  + NODE_MANIFEST +
            "/"  + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":"  + ATTRIBUTE_DEBUGGABLE);

    // default is not debuggable, which is the same behavior as parseBoolean
    return Boolean.parseBoolean(value);
}
 
Example #22
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the versionCode attribute or -1 if the value is not set.
 * @param manifestFile the manifest file to read the attribute from.
 * @return the integer value or -1 if not set.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static int getVersionCode(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_VERSIONCODE);

    try {
        return Integer.parseInt(result);
    } catch (NumberFormatException e) {
        return -1;
    }
}
 
Example #23
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the version Code attribute is set in a given manifest.
 * @param manifestFile the manifest to check
 * @return true if the versionCode attribute is present and its value is not empty.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean hasVersionCode(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    XPath xPath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = manifestFile.getContents();
        Object result = xPath.evaluate(
                "/"  + NODE_MANIFEST +
                "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
                ":"  + ATTRIBUTE_VERSIONCODE,
                new InputSource(is),
                XPathConstants.NODE);

        if (result != null) {
            Node node  = (Node)result;
            if (!node.getNodeValue().isEmpty()) {
                return true;
            }
        }
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }

    return false;
}
 
Example #24
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the targetSdkVersion attribute.
 * <p/>
 * If the attribute is set with an int value, the method returns an Integer object.
 * <p/>
 * If the attribute is set with a codename, it returns the codename as a String object.
 * <p/>
 * If the attribute is not set, it returns null.
 *
 * @param manifestFile the manifest file to read the attribute from.
 * @return the integer value or -1 if not set.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
@Nullable
public static Object getTargetSdkVersion(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    String result = getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_USES_SDK +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_TARGET_SDK_VERSION);
    try {
        return Integer.valueOf(result);
    } catch (NumberFormatException e) {
        return !result.isEmpty() ? result : null;
    }
}
 
Example #25
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the application icon  for a given manifest.
 * @param manifestFile the manifest to parse.
 * @return the icon or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getApplicationIcon(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    return getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_ICON);
}
 
Example #26
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the application label  for a given manifest.
 * @param manifestFile the manifest to parse.
 * @return the label or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getApplicationLabel(IAbstractFile manifestFile)
        throws XPathExpressionException, StreamException {
    return getStringValue(manifestFile,
            "/" + NODE_MANIFEST +
            "/" + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":" + ATTRIBUTE_LABEL);
}
 
Example #27
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the manifest is set to make the application RTL aware.
 *
 * If the give manifest does not contain the supportsRtl attribute then the application
 * is considered to not be not supporting RTL (there will be no layout mirroring).
 *
 * @param manifestFile the manifest to parse.
 * @return true if the application is supporting RTL.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static boolean getSupportsRtl(IAbstractFile manifestFile)
    throws XPathExpressionException, StreamException {

    String value = getStringValue(manifestFile,
            "/"  + NODE_MANIFEST +
            "/"  + NODE_APPLICATION +
            "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX +
            ":"  + ATTRIBUTE_SUPPORTS_RTL);

    // default is not debuggable, which is the same behavior as parseBoolean
    return Boolean.parseBoolean(value);
}
 
Example #28
Source File: AndroidManifestParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the Android Manifest, and returns a {@link ManifestData} object containing the
 * result of the parsing.
 *
 * @param manifestFile the {@link IAbstractFile} representing the manifest file.
 * @param gatherData indicates whether the parsing will extract data from the manifest. If false
 * the method will always return null.
 * @param errorHandler an optional errorHandler.
 * @return A class containing the manifest info obtained during the parsing, or null on error.
 *
 * @throws StreamException
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public static ManifestData parse(
        IAbstractFile manifestFile,
        boolean gatherData,
        ManifestErrorHandler errorHandler)
            throws SAXException, IOException, StreamException, ParserConfigurationException {
    if (manifestFile != null) {
        SAXParser parser = sParserFactory.newSAXParser();

        ManifestData data = null;
        if (gatherData) {
            data = new ManifestData();
        }

        ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
                data, errorHandler);
        InputStream is = manifestFile.getContents();
        try {
            parser.parse(new InputSource(is), manifestHandler);
        } finally {
            try {
                Closeables.close(is, true /* swallowIOException */);
            } catch (IOException e) {
                // cannot happen
            }
        }

        return data;
    }

    return null;
}
 
Example #29
Source File: AndroidManifestParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static ManifestData parse(IAbstractFolder projectFolder)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    IAbstractFile manifestFile = AndroidManifest.getManifest(projectFolder);
    if (manifestFile == null) {
        throw new FileNotFoundException();
    }

    return parse(manifestFile, true, null);
}
 
Example #30
Source File: AndroidLibraryProject.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public AndroidLibraryProject(File libraryDir, String libraryName) throws IOException, SAXException, StreamException, ParserConfigurationException {
    super(libraryDir, null);
    parseAndroidManifest();

    resDir = new File(dirRoot, "res");
    aidlDir = new File(dirRoot, "aidl");
    jniDir = new File(dirRoot, "jni");
    assetsDir = new File(dirRoot, "assets");

    if (new File(dirRoot, "classes.jar").exists()) {
        classesJar = new File(dirRoot, "classes.jar");
    }
    classR = new File(dirRoot, getPackageName().replace(".", "/") + "/R.java");
}