use of org.w3c.dom.NodeList in project che by eclipse.
the class Launching method restoreLibraryInfo.
/**
* Restores library information for VMs
*/
private static void restoreLibraryInfo() {
fgLibraryInfoMap = new HashMap<String, LibraryInfo>(10);
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append("libraryInfos.xml");
File file = libPath.toFile();
if (file.exists()) {
try {
InputStream stream = new BufferedInputStream(new FileInputStream(file));
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Element root = parser.parse(new InputSource(stream)).getDocumentElement();
if (!root.getNodeName().equals("libraryInfos")) {
//$NON-NLS-1$
return;
}
NodeList list = root.getChildNodes();
int length = list.getLength();
for (int i = 0; i < length; ++i) {
Node node = list.item(i);
short type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
Element element = (Element) node;
String nodeName = element.getNodeName();
if (nodeName.equalsIgnoreCase("libraryInfo")) {
//$NON-NLS-1$
//$NON-NLS-1$
String version = element.getAttribute("version");
//$NON-NLS-1$
String location = element.getAttribute("home");
//$NON-NLS-1$
String[] bootpath = getPathsFromXML(element, "bootpath");
//$NON-NLS-1$
String[] extDirs = getPathsFromXML(element, "extensionDirs");
//$NON-NLS-1$
String[] endDirs = getPathsFromXML(element, "endorsedDirs");
if (location != null) {
LibraryInfo info = new LibraryInfo(version, bootpath, extDirs, endDirs);
fgLibraryInfoMap.put(location, info);
}
}
}
}
} catch (IOException | SAXException | ParserConfigurationException e) {
log(e);
}
}
}
use of org.w3c.dom.NodeList in project che by eclipse.
the class Launching method readInstallInfo.
/**
* Reads the file of saved time stamps and populates the {@link #fgInstallTimeMap}.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information
*
* @since 3.7
*/
private static void readInstallInfo() {
fgInstallTimeMap = new HashMap<String, Long>();
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append(".install.xml");
File file = libPath.toFile();
if (file.exists()) {
try {
InputStream stream = new BufferedInputStream(new FileInputStream(file));
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Element root = parser.parse(new InputSource(stream)).getDocumentElement();
if (root.getNodeName().equalsIgnoreCase("dirs")) {
//$NON-NLS-1$
NodeList nodes = root.getChildNodes();
Node node = null;
Element element = null;
for (int i = 0; i < nodes.getLength(); i++) {
node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
element = (Element) node;
if (element.getNodeName().equalsIgnoreCase("entry")) {
//$NON-NLS-1$
//$NON-NLS-1$
String loc = element.getAttribute("loc");
//$NON-NLS-1$
String stamp = element.getAttribute("stamp");
try {
Long l = new Long(stamp);
fgInstallTimeMap.put(loc, l);
} catch (NumberFormatException nfe) {
//do nothing
}
}
}
}
}
} catch (IOException e) {
log(e);
} catch (ParserConfigurationException e) {
log(e);
} catch (SAXException e) {
log(e);
}
}
}
use of org.w3c.dom.NodeList in project buck by facebook.
the class CompileStringsStep method compileStringFiles.
private StringResources compileStringFiles(ProjectFilesystem filesystem, Collection<Path> filepaths) throws IOException, SAXException {
TreeMap<Integer, EnumMap<Gender, String>> stringsMap = Maps.newTreeMap();
TreeMap<Integer, EnumMap<Gender, ImmutableMap<String, String>>> pluralsMap = Maps.newTreeMap();
TreeMap<Integer, EnumMap<Gender, ImmutableList<String>>> arraysMap = Maps.newTreeMap();
for (Path stringFilePath : filepaths) {
Document dom = XmlDomParser.parse(filesystem.getPathForRelativePath(stringFilePath));
NodeList stringNodes = dom.getElementsByTagName("string");
scrapeStringNodes(stringNodes, stringsMap);
NodeList pluralNodes = dom.getElementsByTagName("plurals");
scrapePluralsNodes(pluralNodes, pluralsMap);
NodeList arrayNodes = dom.getElementsByTagName("string-array");
scrapeStringArrayNodes(arrayNodes, arraysMap);
}
return new StringResources(stringsMap, pluralsMap, arraysMap);
}
use of org.w3c.dom.NodeList in project buck by facebook.
the class MiniAapt method processXmlFile.
@VisibleForTesting
void processXmlFile(ProjectFilesystem filesystem, Path xmlFile, ImmutableSet.Builder<RDotTxtEntry> references) throws IOException, XPathExpressionException, ResourceParseException {
try (InputStream stream = filesystem.newFileInputStream(xmlFile)) {
Document dom = parseXml(xmlFile, stream);
NodeList nodesWithIds = (NodeList) ANDROID_ID_DEFINITION.evaluate(dom, XPathConstants.NODESET);
for (int i = 0; i < nodesWithIds.getLength(); i++) {
String resourceName = nodesWithIds.item(i).getNodeValue();
if (!resourceName.startsWith(ID_DEFINITION_PREFIX)) {
throw new ResourceParseException("Invalid definition of a resource: '%s'", resourceName);
}
Preconditions.checkState(resourceName.startsWith(ID_DEFINITION_PREFIX));
resourceCollector.addIntResourceIfNotPresent(RType.ID, resourceName.substring(ID_DEFINITION_PREFIX.length()));
}
NodeList nodesUsingIds = (NodeList) ANDROID_ID_USAGE.evaluate(dom, XPathConstants.NODESET);
for (int i = 0; i < nodesUsingIds.getLength(); i++) {
String resourceName = nodesUsingIds.item(i).getNodeValue();
int slashPosition = resourceName.indexOf('/');
if (resourceName.charAt(0) != '@' || slashPosition == -1) {
throw new ResourceParseException("Invalid definition of a resource: '%s'", resourceName);
}
String rawRType = resourceName.substring(1, slashPosition);
String name = resourceName.substring(slashPosition + 1);
String nodeName = nodesUsingIds.item(i).getNodeName();
if (name.startsWith("android:") || nodeName.startsWith("tools:")) {
continue;
}
if (!RESOURCE_TYPES.containsKey(rawRType)) {
throw new ResourceParseException("Invalid reference '%s' in '%s'", resourceName, xmlFile);
}
RType rType = Preconditions.checkNotNull(RESOURCE_TYPES.get(rawRType));
references.add(new FakeRDotTxtEntry(IdType.INT, rType, sanitizeName(name)));
}
}
}
use of org.w3c.dom.NodeList in project buck by facebook.
the class XmlTestResultParser method doParse.
private static TestCaseSummary doParse(String xml) throws IOException, SAXException {
Document doc = XmlDomParser.parse(new InputSource(new StringReader(xml)), /* namespaceAware */
true);
Element root = doc.getDocumentElement();
Preconditions.checkState("testcase".equals(root.getTagName()));
String testCaseName = root.getAttribute("name");
NodeList testElements = doc.getElementsByTagName("test");
List<TestResultSummary> testResults = Lists.newArrayListWithCapacity(testElements.getLength());
for (int i = 0; i < testElements.getLength(); i++) {
Element node = (Element) testElements.item(i);
String testName = node.getAttribute("name");
long time = Long.parseLong(node.getAttribute("time"));
String typeString = node.getAttribute("type");
ResultType type = ResultType.valueOf(typeString);
String message;
String stacktrace;
if (type == ResultType.SUCCESS) {
message = null;
stacktrace = null;
} else {
message = node.getAttribute("message");
stacktrace = node.getAttribute("stacktrace");
}
NodeList stdoutElements = node.getElementsByTagName("stdout");
String stdOut;
if (stdoutElements.getLength() == 1) {
stdOut = stdoutElements.item(0).getTextContent();
} else {
stdOut = null;
}
NodeList stderrElements = node.getElementsByTagName("stderr");
String stdErr;
if (stderrElements.getLength() == 1) {
stdErr = stderrElements.item(0).getTextContent();
} else {
stdErr = null;
}
TestResultSummary testResult = new TestResultSummary(testCaseName, testName, type, time, message, stacktrace, stdOut, stdErr);
testResults.add(testResult);
}
return new TestCaseSummary(testCaseName, testResults);
}
Aggregations