private void recordManifestUsages(File manifest) throws IOException, ParserConfigurationException, SAXException { String xml = Files.toString(manifest, UTF_8); Document document = XmlUtils.parseDocument(xml, true); recordManifestUsages(document.getDocumentElement()); }
private void recordManifestUsages(File manifest) throws IOException, ParserConfigurationException, SAXException { String xml = Files.toString(manifest, UTF_8); Document document = XmlUtils.parseDocument(xml, true); mModel.visitXmlDocument(manifest, null, document); }
private void recordXmlResourcesUsages(@NonNull File file, boolean isDefaultFolder, @Nullable Resource from) throws IOException, ParserConfigurationException, SAXException { String xml = Files.toString(file, UTF_8); Document document = XmlUtils.parseDocument(xml, true); recordResourceReferences(file, isDefaultFolder, document.getDocumentElement(), from); }
/** {@link #loadFromXmlFile(File)} but using a String */ public void loadFromXml(@NonNull String persistedState) throws IOException, SAXException, ParserConfigurationException { loadFromDocument(XmlUtils.parseDocument(persistedState, false)); }
/** * Merges the artifacts of a temporary build info into this build's artifacts. If this build * finishes the build-info.xml will contain the artifacts produced by this iteration as well as * the artifacts produced in a previous iteration and saved into the temporary build info. * * @param tmpBuildInfo a past build build-info.xml as a String * @throws IOException cannot be thrown. * @throws SAXException when the xml is not correct. * @throws ParserConfigurationException when the xml parser cannot be initialized. */ public void mergeFrom(@NonNull String tmpBuildInfo) throws IOException, SAXException, ParserConfigurationException { mergeFrom(XmlUtils.parseDocument(tmpBuildInfo, false)); }
private void mergeAnnotationsXml(@NonNull String path, @NonNull String xml) { try { Document document = XmlUtils.parseDocument(xml, false); mergeDocument(document); } catch (Exception e) { String message = "Failed to merge " + path + ": " + e.toString(); if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException)e; message = "Line " + spe.getLineNumber() + ":" + spe.getColumnNumber() + ": " + message; } error(message); if (!(e instanceof IOException)) { e.printStackTrace(); } } }
/** * Parses the given XML string as a DOM document, using the JDK parser. The parser does not * validate, and is optionally namespace aware. Any parsing errors are silently ignored. * * @param xml the XML content to be parsed (must be well formed) * @param namespaceAware whether the parser is namespace aware * @return the DOM document, or null */ @Nullable public static Document parseDocumentSilently(@NonNull String xml, boolean namespaceAware) { try { return parseDocument(xml, namespaceAware); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }
private void mergeAnnotationsXml(@NonNull String path, @NonNull String xml) { try { Document document = XmlUtils.parseDocument(xml, false); mergeDocument(document); } catch (Exception e) { warning("Failed to merge " + path + ": " + e.toString()); if (!(e instanceof IOException)) { e.printStackTrace(); } } }
/** * Parses the given XML string as a DOM document, using the JDK parser. The parser does not * validate, and is optionally namespace aware. * * @param xml the XML content to be parsed (must be well formed) * @param namespaceAware whether the parser is namespace aware * @return the DOM document */ @NonNull public static Document parseDocument(@NonNull String xml, boolean namespaceAware) throws ParserConfigurationException, IOException, SAXException { xml = stripBom(xml); return parseDocument(new StringReader(xml), namespaceAware); }
private void recordResources(@NonNull ResourceFolderType folderType, File folder) throws ParserConfigurationException, SAXException, IOException { File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String path = file.getPath(); mModel.file = file; try { boolean isXml = endsWithIgnoreCase(path, DOT_XML); if (isXml) { String xml = Files.toString(file, UTF_8); Document document = XmlUtils.parseDocument(xml, true); mModel.visitXmlDocument(file, folderType, document); } else { mModel.visitBinaryResource(folderType, file); } } finally { mModel.file = null; } } } }
@Nullable public static Document parseDocumentSilently(@NonNull CharSequence xml, boolean namespaceAware) { try { Reader reader = getReader(xml, true); return XmlUtils.parseDocument(reader, namespaceAware); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }
throws IOException { try { Document document = XmlUtils.parseDocument(xml, false);
private void recordInactiveXmlResources(@NonNull ResourceFolderType folderType, @NonNull File folder) { File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String path = file.getPath(); boolean isXml = endsWithIgnoreCase(path, DOT_XML); try { if (isXml) { String xml = Files.toString(file, UTF_8); Document document = XmlUtils.parseDocument(xml, true); mModel.visitXmlDocument(file, folderType, document); } else { mModel.visitBinaryResource(folderType, file); } } catch (Throwable ignore) { // Tolerate parsing errors etc in these files; they're user // sources, and this is even for inactive source sets. } } } }
@Nullable private static Document checkDocument(@NonNull String pkg, @NonNull String xml, boolean namespaceAware) { try { return XmlUtils.parseDocument(xml, namespaceAware); } catch (SAXException sax) { warning("Failed to parse document for package " + pkg + ": " + sax.toString()); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }
@Nullable private static Document checkDocument(@NonNull String pkg, @NonNull String xml, boolean namespaceAware) { try { return XmlUtils.parseDocument(xml, namespaceAware); } catch (SAXException sax) { warning("Failed to parse document for package " + pkg + ": " + sax.toString()); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }