public void onDocument(Document document, String xpath) throws XmlParserException { if (xpath.equals(XPATH_IPEAK)) { Node node = document.getChildNodes().item(0); // check whether we're getting the correct ipeak Node typeattribute = node.getAttributes().getNamedItem(PeakMLWriter.TYPE); if (typeattribute == null) throw new XmlParserException("Failed to locate the type attribute."); if (!typeattribute.getNodeValue().equals(PeakMLWriter.TYPE_MASSCHROMATOGRAM)) throw new XmlParserException( "IPeak (" + typeattribute.getNodeValue() + ") is not of type: '" + PeakMLWriter.TYPE_MASSCHROMATOGRAM + "'"); // parse this node as a mass chromatogram MassChromatogram<? extends Peak> masschromatogram = parseMassChromatogram(node); if (masschromatogram != null) peaks.add(masschromatogram); // if (_listener != null && result.header != null && result.header.getNrPeaks() != 0) _listener.update((100. * index++) / result.header.getNrPeaks()); } else if (xpath.equals(XPATH_HEADER)) { result.header = parseHeader(document.getFirstChild()); } }
static { try { URL url = SpellCheckActivator.bundleContext.getBundle().getResource(RESOURCE_LOC); InputStream stream = url.openStream(); if (stream == null) throw new IOException(); // strict parsing options DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); // parses configuration xml /*- * Warning: Felix is unable to import the com.sun.rowset.internal * package, meaning this can't use the XmlErrorHandler. This causes * a warning and a default handler to be attached. Otherwise this * should have: builder.setErrorHandler(new XmlErrorHandler()); */ DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(stream); // iterates over nodes, parsing contents Node root = doc.getChildNodes().item(1); NodeList categories = root.getChildNodes(); for (int i = 0; i < categories.getLength(); ++i) { Node node = categories.item(i); if (node.getNodeName().equals(NODE_DEFAULTS)) { parseDefaults(node.getChildNodes()); } else if (node.getNodeName().equals(NODE_LOCALES)) { parseLocales(node.getChildNodes()); } else { logger.warn("Unrecognized category: " + node.getNodeName()); } } } catch (IOException exc) { logger.error("Unable to load spell checker parameters", exc); } catch (SAXException exc) { logger.error("Unable to parse spell checker parameters", exc); } catch (ParserConfigurationException exc) { logger.error("Unable to parse spell checker parameters", exc); } }
public void onDocument(Document document, String xpath) throws XmlParserException { if (xpath.equals(XPATH_IPEAK)) { Node node = document.getChildNodes().item(0); // check whether we're getting the correct ipeak Node typeattribute = node.getAttributes().getNamedItem(PeakMLWriter.TYPE); if (typeattribute == null) throw new XmlParserException("Failed to locate a type attribute."); // ... // IPeak peak = (_loadall ? parseIPeak(node) : parseCentroid(node)); IPeak peak = parseIPeak(node); if (peak != null) _listener.onIPeak(peak); } else if (xpath.equals(XPATH_HEADER)) { Header header = parseHeader(document.getFirstChild()); _listener.onHeader(header); } }
public void onDocument(Document document, String xpath) throws XmlParserException { if (xpath.equals(XPATH_IPEAK)) { Node node = document.getChildNodes().item(0); // check whether we're getting the correct ipeak Node typeattribute = node.getAttributes().getNamedItem(PeakMLWriter.TYPE); if (typeattribute == null || !typeattribute.getNodeValue().equals(PeakMLWriter.TYPE_PEAKSET)) throw new XmlParserException("Failed to locate a type attribute."); // parse this node as a mass chromatogram IPeakSet<? extends IPeak> peakset = parsePeakSet(node); if (peakset != null) peaks.add(peakset); // if (_listener != null && result.header != null && result.header.getNrPeaks() != 0) _listener.update((100. * index++) / result.header.getNrPeaks()); } else if (xpath.equals(XPATH_HEADER)) { result.header = parseHeader(document.getFirstChild()); } }
private static void showDocument(Document doc) { StringBuffer content = new StringBuffer(); Node node = doc.getChildNodes().item(0); ApplicationNode appNode = new ApplicationNode(node); content.append("Application \n"); List<ClassNode> classes = appNode.getClasses(); for (int i = 0; i < classes.size(); i++) { ClassNode classNode = classes.get(i); content.append(SPACE + "Class: " + classNode.getName() + " \n"); List<MethodNode> methods = classNode.getMethods(); for (int j = 0; j < methods.size(); j++) { MethodNode methodNode = methods.get(j); content.append(SPACE + SPACE + "Method: " + methodNode.getName() + " \n"); } } System.out.println(content.toString()); }