public void onDocument(Document document, String xpath) throws XmlParserException { if (xpath.equals(XPATH_IPEAK)) { Node node = document.getFirstChild(); // 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_BACKGROUNDION)) throw new XmlParserException( "IPeak (" + typeattribute.getNodeValue() + ") is not of type: '" + PeakMLWriter.TYPE_BACKGROUNDION + "'"); // parse this node as a mass chromatogram BackgroundIon<? extends Peak> backgroundion = parseBackgroundIon(node); if (backgroundion != null) peaks.add(backgroundion); // 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 IPeak parseIPeak(Node parent) throws XmlParserException { Node type = parent.getAttributes().getNamedItem(PeakMLWriter.TYPE); if (type == null) return null; else if (type.getNodeValue().equals(PeakMLWriter.TYPE_PEAKSET)) return parsePeakSet(parent); else if (type.getNodeValue().equals(PeakMLWriter.TYPE_BACKGROUNDION)) return parseBackgroundIon(parent); else if (type.getNodeValue().equals(PeakMLWriter.TYPE_MASSCHROMATOGRAM)) return parseMassChromatogram(parent); else return null; }
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 PeakData<? extends Peak> parsePeakData(Node parent) throws XmlParserException { // get the attributes Node typeattribute = parent.getAttributes().getNamedItem(PeakMLWriter.TYPE); if (typeattribute == null) throw new XmlParserException("Failed to locate a type attribute."); Node sizeattribute = parent.getAttributes().getNamedItem(PeakMLWriter.SIZE); if (sizeattribute == null) throw new XmlParserException("Failed to locate a size attribute."); int size = Integer.parseInt(sizeattribute.getNodeValue()); String type = typeattribute.getNodeValue(); // create the arrays int scanids[] = null; int patternids[] = null; int measurementids[] = null; double masses[] = null; double intensities[] = null; double retentiontimes[] = null; // retrieve all the data NodeList nodes = parent.getChildNodes(); for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) { Node node = nodes.item(nodeid); if (node.getNodeType() != Node.ELEMENT_NODE) continue; Element element = (Element) node; if (element.getTagName().equals("scanids")) scanids = ByteArray.toIntArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("patternids")) patternids = ByteArray.toIntArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("measurementids")) measurementids = ByteArray.toIntArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("masses")) masses = ByteArray.toDoubleArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("intensities")) intensities = ByteArray.toDoubleArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("retentiontimes")) retentiontimes = ByteArray.toDoubleArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); } // create the PeakData instance if (type.equals("centroid")) return new PeakData<Centroid>( Centroid.factory, size, scanids, patternids, measurementids, masses, intensities, retentiontimes); return null; }