private static IPeakSet<? extends IPeak> parsePeakSet(Node parent) throws XmlParserException { // retrieve all the properties Vector<IPeak> peaks = new Vector<IPeak>(); 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("peaks")) { NodeList nodes2 = node.getChildNodes(); for (int nodeid2 = 0; nodeid2 < nodes2.getLength(); ++nodeid2) { Node node2 = nodes2.item(nodeid2); if (node2.getNodeType() != Node.ELEMENT_NODE) continue; IPeak peak = parseIPeak(node2); if (peak != null) peaks.add(peak); } } } // create the bugger IPeakSet<IPeak> peakset = new IPeakSet<IPeak>(peaks); parseIPeak(parent, peakset); return peakset; }
// Lee la configuracion que se encuentra en conf/RegistryConf private void readConfXml() { try { File inputFile = new File("src/java/Conf/RegistryConf.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("RegistryConf"); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; RegistryConf reg = new RegistryConf(); String aux; int idSensor; int value; aux = eElement.getElementsByTagName("idSensor").item(0).getTextContent(); idSensor = Integer.parseInt(aux); reg.setIdSensor(idSensor); aux = eElement.getElementsByTagName("saveType").item(0).getTextContent(); reg.setSaveTypeString(aux); aux = eElement.getElementsByTagName("value").item(0).getTextContent(); value = Integer.parseInt(aux); reg.setValue(value); registryConf.add(reg); lastRead.put(idSensor, 0); } } } catch (Exception e) { e.printStackTrace(); } }
private static MeasurementInfo parseMeasurement(Node parent) throws XmlParserException { String id = ""; String label = ""; String sampleid = ""; Vector<FileInfo> files = null; Vector<ScanInfo> scans = null; 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("id")) id = element.getTextContent(); else if (element.getTagName().equals("label")) label = element.getTextContent(); else if (element.getTagName().equals("sampleid")) sampleid = element.getTextContent(); else if (element.getTagName().equals("scans")) scans = parseScans(node); else if (element.getTagName().equals("files")) files = parseFiles(node); } MeasurementInfo measurement = new MeasurementInfo(Integer.parseInt(id), sampleid); measurement.setLabel(label); measurement.addFileInfos(files); if (scans != null) measurement.addScanInfos(scans); return measurement; }
private static SetInfo parseSet(Node parent) throws XmlParserException { String id = ""; String type = ""; String measurementids = null; NodeList nodes = parent.getChildNodes(); Vector<SetInfo> sets = new Vector<SetInfo>(); 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("id")) id = element.getTextContent(); else if (element.getTagName().equals("set")) sets.add(parseSet(element)); else if (element.getTagName().equals("type")) type = element.getTextContent(); else if (element.getTagName().equals("measurementids")) measurementids = element.getTextContent(); } // create the set SetInfo set = new SetInfo(id, Integer.parseInt(type)); if (measurementids != null) { int mids[] = ByteArray.toIntArray(Base64.decode(measurementids), ByteArray.ENDIAN_LITTLE, 32); for (int mid : mids) set.addMeasurementID(mid); } // add the children for (SetInfo s : sets) set.addChild(s); return set; }
private static Header parseHeader(Node parent) throws XmlParserException { Header header = new Header(); 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; try { if (element.getTagName().equals("nrpeaks")) header.setNrPeaks(Integer.parseInt(element.getTextContent())); else if (element.getTagName().equals("date")) header.setDate(element.getTextContent()); else if (element.getTagName().equals("owner")) header.setOwner(element.getTextContent()); else if (element.getTagName().equals("description")) header.setDescription(element.getTextContent()); else if (element.getTagName().equals("sets")) header.addSetInfos(parseSets(element)); else if (element.getTagName().equals("measurements")) header.addMeasurementInfos(parseMeasurements(element)); else if (element.getTagName().equals("annotations")) { Vector<Annotation> annotations = parseAnnotations(element); if (annotations != null) for (Annotation annotation : annotations) header.addAnnotation(annotation); } } catch (Exception e) { throw new XmlParserException( "Invalid value in header (" + element.getTagName() + "): '" + e.getMessage() + "'."); } } return header; }
/* * Output this item. Then, if the element has child elements, output each. */ private void outputItem(Element e, PrintWriter out) { int chk = 0; HashMap collection = new HashMap(); String key = null; Element collectionElement = null; log.fine("outputing item for " + e.getAttribute("name") + ": " + e.getAttribute("query")); out.println("<item>"); out.println("<name>" + e.getAttribute("name") + "</name>"); if (e.getTagName().equalsIgnoreCase("collection")) { // change made by NETTY (change collectionlist to collection) out.println( "<query>collection=" + e.getAttribute("col_id") + "&xsl=metadata_to_html_full</query>"); } else { out.println( "<query>owner=" + e.getAttribute("query") + "&xsl=metadata_to_html_full</query>"); } // now output children NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { chk++; outputItem((Element) child, out); } } out.println("</item>"); }
// Gets the specified XML Schema doc if one is mentioned in the file public static File getSchemaFile(Document xmlDoc) { /** @todo Must be an easier way of doing this... */ logger.logComment("Getting schema file for: " + xmlDoc.getDocumentURI()); NodeList nl = xmlDoc.getChildNodes(); for (int j = 0; j < nl.getLength(); j++) { Node node = nl.item(j); logger.logComment("Type: " + node.getNodeType() + "Name: " + node.getNodeName()); if (node.getNodeName().equals(XML_STYLESHEET_NODE)) { String nodeVal = node.getNodeValue(); logger.logComment("Looking at: " + nodeVal); String xslFileName = nodeVal.substring(nodeVal.indexOf("href=\"") + 6, nodeVal.length() - 1); File xslFile = new File(xslFileName); return xslFile; } if (node.getAttributes().getLength() > 0) { logger.logComment("Attributes: " + node.getAttributes()); if (node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR) != null) { String locString = node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR).getNodeValue(); logger.logComment("Loc string: " + locString); String file = locString.split("\\s")[1]; return new File(file); } } } logger.logError("No node found with name: " + XML_STYLESHEET_NODE); return null; }
private void buildHierarchyDOM() { TransformerFactory factory = TransformerFactory.newInstance(); StreamSource src = new StreamSource( this.getServletContext() .getResourceAsStream("/WEB-INF/classes/gpt/search/browse/ownerHierarchy.xml")); log.info("initializing src from stream " + src); try { Transformer t = factory.newTransformer(); dom = new DOMResult(); t.transform(src, dom); // now go thru tree, setting up the query attribute for each node Node tree = dom.getNode(); NodeList children = tree.getChildNodes(); log.info("dom tree contains " + children.getLength() + " nodes"); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) child; String query = computeQuery(e); e.setAttribute("query", query); } } } catch (Exception e) { log.severe("Could not init ownerHierarchy because exception thrown:"); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); log.severe(sw.toString()); } }
/* * If the element contains an attribute 'makeOnly' with a value of 'true', * create a child element before any existing children which will display a node * which will display only the elements records. * Compute the query attribute, which is the appended result of all of the children * appended to this element name. If noQuery=true. then do not generate a query term * for this element. */ String computeQuery(Element e) { String query = ""; if (!(e.getAttribute("noQuery").equalsIgnoreCase("true"))) { query = e.getAttribute("name"); } String makeOnly = e.getAttribute("makeOnly"); boolean madeOnly = false; NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { if (makeOnly.equalsIgnoreCase("true") && !madeOnly) { // need to make an ...-Only node and populate it String onlyTagName = e.getTagName() + "-Only"; Element only = ((Document) dom.getNode()).createElement(onlyTagName); only.setAttribute("name", e.getAttribute("name") + "-Only"); only.setAttribute("query", e.getAttribute("name")); e.insertBefore(only, child); i++; madeOnly = true; } if (query.length() > 0) { query += ","; } query += computeQuery((Element) child); } } log.info("setting query for " + e.getNodeName() + " " + query); e.setAttribute("query", query); return query; }
/* return the value of the XML text node (never null) */ protected static String GetNodeText(Node root) { StringBuffer sb = new StringBuffer(); if (root != null) { NodeList list = root.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeType() == Node.CDATA_SECTION_NODE) { // CDATA Section sb.append(n.getNodeValue()); } else if (n.getNodeType() == Node.TEXT_NODE) { sb.append(n.getNodeValue()); } else { // Print.logWarn("Unrecognized node type: " + n.getNodeType()); } } } return sb.toString(); }
public Vector getNodes(Element padre) { Vector vectorNode = new Vector(); NodeList nodeList = padre.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) vectorNode.add(node); } return vectorNode; }
private List<Node> getChildNodes(Node parentNode, String tagName) { List<Node> nodeList = new ArrayList<Node>(); for (Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE && tagName.equals(child.getNodeName())) { nodeList.add(child); } } return nodeList; }
/** * Carries out preprocessing that makes JEuclid handle the document better. * * @param doc Document */ static void preprocessForJEuclid(Document doc) { // underbrace and overbrace NodeList list = doc.getElementsByTagName("mo"); for (int i = 0; i < list.getLength(); i++) { Element mo = (Element) list.item(i); String parentName = ((Element) mo.getParentNode()).getTagName(); if (parentName == null) { continue; } if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23df")); } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23de")); } } // menclose for long division doesn't allow enough top padding. Oh, and // <mpadded> isn't implemented. And there isn't enough padding to left of // the bar either. Solve by adding an <mover> with just an <mspace> over# // the longdiv, contained within an mrow that adds a <mspace> before it. list = doc.getElementsByTagName("menclose"); for (int i = 0; i < list.getLength(); i++) { Element menclose = (Element) list.item(i); // Only for longdiv if (!"longdiv".equals(menclose.getAttribute("notation"))) { continue; } Element mrow = doc.createElementNS(WebMathsService.NS, "mrow"); Element mover = doc.createElementNS(WebMathsService.NS, "mover"); Element mspace = doc.createElementNS(WebMathsService.NS, "mspace"); Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace"); boolean previousElement = false; for (Node previous = menclose.getPreviousSibling(); previous != null; previous = previous.getPreviousSibling()) { if (previous.getNodeType() == Node.ELEMENT_NODE) { previousElement = true; break; } } if (previousElement) { mspaceW.setAttribute("width", "4px"); } menclose.getParentNode().insertBefore(mrow, menclose); menclose.getParentNode().removeChild(menclose); mrow.appendChild(mspaceW); mrow.appendChild(mover); mover.appendChild(menclose); mover.appendChild(mspace); } }
private static boolean isTextChild(Node parent, String text) { NodeList list = parent.getChildNodes(); if (list.getLength() != 1) { return false; } Node child = list.item(0); if (child.getNodeType() != Node.TEXT_NODE) { return false; } return child.getNodeValue().equals(text); }
private static Vector<Annotation> parseAnnotations(Node parent) throws XmlParserException { Vector<Annotation> annotations = new Vector<Annotation>(); 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("annotation")) { String label = null, value = null, valuetype = null, unit = null; NodeList annotation_nodes = element.getChildNodes(); for (int annotationid = 0; annotationid < annotation_nodes.getLength(); ++annotationid) { Node annotation_node = annotation_nodes.item(annotationid); if (annotation_node.getNodeType() != Node.ELEMENT_NODE) continue; Element annotation_element = (Element) annotation_node; if (annotation_element.getTagName().equals("label")) label = annotation_element.getTextContent(); else if (annotation_element.getTagName().equals("value")) value = annotation_element.getTextContent(); else if (annotation_element.getTagName().equals("valuetype")) valuetype = annotation_element.getTextContent(); } if (label == null || value == null || valuetype == null) throw new XmlParserException("Annotation is missing either: label, value or valuetype"); Annotation annotation = new Annotation(label, value, Annotation.ValueType.valueOf(valuetype)); annotation.setUnit(unit); if (annotation.getValueType() == Annotation.ValueType.ONTOLOGY) annotation.setOntologyRef(element.getAttribute("ontologyref")); if (element.getAttribute("unit") != null) annotation.setUnit(element.getAttribute("unit")); annotations.add(annotation); } } return annotations; }
private static void parseIPeak(Node parent, IPeak peak) throws XmlParserException { // retrieve all the properties int scan = -1; double retentiontime = -1; double mass = -1; double intensity = -1; int patternid = -1; int measurementid = -1; // String sha1 = null; Vector<Annotation> annotations = null; 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("patternid")) patternid = Integer.parseInt(element.getTextContent()); else if (element.getTagName().equals("measurementid")) measurementid = Integer.parseInt(element.getTextContent()); else if (element.getTagName().equals("annotations")) annotations = parseAnnotations(element); else if (element.getTagName().equals("scan")) scan = Integer.parseInt(element.getTextContent()); else if (element.getTagName().equals("retentiontime")) retentiontime = Double.parseDouble(element.getTextContent()); else if (element.getTagName().equals("mass")) mass = Double.parseDouble(element.getTextContent()); else if (element.getTagName().equals("intensity")) intensity = Double.parseDouble(element.getTextContent()); // else if (element.getTagName().equals("sha1sum")) // sha1 = element.getTextContent(); } // check whether obligatory values are missing if (mass == -1 || intensity == -1) throw new XmlParserException("Mass and/or intensity information is missing for IPeak."); peak.setScanID(scan); peak.setRetentionTime(retentiontime); peak.setMass(mass); peak.setIntensity(intensity); peak.setPatternID(patternid); peak.setMeasurementID(measurementid); if (annotations != null) for (Annotation annotation : annotations) peak.addAnnotation(annotation); // check whether // if (sha1!=null && !sha1.equals(peak.sha1())) // throw new XmlParserException("SHA1-sum for individual ipeak element does not match."); }
private static String getTextContent(Node n) { NodeList nodeList = n.getChildNodes(); String textContent = ""; for (int j = 0; j < nodeList.getLength(); j++) { Node k = nodeList.item(j); if (k.getNodeType() == Node.TEXT_NODE) { textContent = k.getNodeValue(); break; } } return textContent; }
private static Vector<FileInfo> parseFiles(Node parent) throws XmlParserException { Vector<FileInfo> files = new Vector<FileInfo>(); 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("file")) files.add(parseFile(node)); } return files; }
/** * Get all the properties of this resource. This implementation stores properties in an XML * document containing a properties root element. The properties file name is derived from the URI * by adding the extension PropertiesManager.propertiesSuffix. This applies to collections as well * as other resources. * * <p>Since the properties are stored in a file, and all methods that query and update the * properties must read the XML file into memory and parse it, many of the other property methods * are implemented by calling this method. Subclasses of ResourceImpl may want to use other * techniques depending on how the properties are stored. * * @return a MultiStatus containing response elements with prop elements containing the properties * and their statuses. * @exception com.ibm.webdav.WebDAVException */ public MultiStatus getProperties() throws WebDAVException { Document propertiesDocument = resource.loadProperties(); // create a MultiStatus to hold the results MultiStatus results = new MultiStatus(); // create a response element to hold the properties for this resource PropertyResponse response = null; String urlstring; if (false) { // I consider this to be the more correct way and the // way used in the examples in the spec... but it is // redundant and creates the possibility of the two // redundant parts being out of synch. urlstring = resource.getURL().toString(); } else { // this is the way that mod_dav and a few others do it. This // way also makes it easier to debug clients even if // redirecting through a dedicated proxy. Without this // it's inconvenient to debug IE5. It gets confused if // the host:port (if provided) don't match who it thinks // it's connecting to. urlstring = resource.getURL().getFile(); } response = new PropertyResponse(urlstring); // add the properties to the response NodeList properties = propertiesDocument.getDocumentElement().getChildNodes(); Node temp = null; for (int i = 0; i < properties.getLength(); i++) { temp = properties.item(i); // Skip ignorable TXText elements if (!(temp.getNodeType() == Node.ELEMENT_NODE)) { continue; } Element property = (Element) temp; PropertyName pn = new PropertyName(property); response.addProperty(pn, property, WebDAVStatus.SC_OK); } results.addResponse(response); return results; }
public void read(Document doc) { try { Element root = doc.getDocumentElement(); NodeList nList = doc.getElementsByTagName("user"); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; } } // Element e1 = (Element) nList.item(0); } catch (Exception e) { } }
/** * Method that reads a XML-file, and returns a Model that contains the information * * @param file * @return * @return */ public static Model readXML(String file) { // initialize table to be filled with content of XML file Model t = new Model(); try { // Create file to be parsed by document parser File xmlfile = new File(file); // create parser DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); // parse the file Document parsedfile = parser.parse(xmlfile); // normalize the parsed file (make it more user-friendly) parsedfile.getDocumentElement().normalize(); NodeList cells = parsedfile.getElementsByTagName("CELL"); for (int i = 0; i < cells.getLength(); i++) { // Get cell at list index i Node currentcell = cells.item(i); // read the elements "location" attributes row/column if (Node.ELEMENT_NODE == currentcell.getNodeType()) { Element cellinfo = (Element) currentcell; // get the row number from node attribute int row = Integer.parseInt(cellinfo.getAttribute("row")) - 1; // get the column number from the node attribute int col = Integer.parseInt(cellinfo.getAttribute("column")) - 1; // get content from node String content = cellinfo.getTextContent(); if (content != null) { content = content.replace("\n", ""); } // Make the content an Integer (if it is a number), easier // for // using it later on // put content in table, with row/column inserted as x/y t.setContent(row, col, (String) content); } } } catch (ParserConfigurationException e) { System.out.println("Fileparser could not be made"); } catch (IOException f) { System.out.println("File could not be parsed, did you enter the correct file name?"); } catch (SAXException g) { System.out.println("Something went wrong in parsing the file"); } return t; }
private static ScanInfo parseScan(Node parent) throws XmlParserException { double retentiontime = 0; Polarity polarity = Polarity.NEUTRAL; Vector<Annotation> annotations = null; 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("polarity")) polarity = Polarity.valueOf(element.getTextContent()); else if (element.getTagName().equals("retentiontime")) retentiontime = Double.parseDouble(element.getTextContent()); else if (element.getTagName().equals("annotations")) annotations = parseAnnotations(element); } ScanInfo scan = new ScanInfo(retentiontime, polarity); if (annotations != null) scan.addAnnotations(annotations); return scan; }
private void call(String script) throws ParserConfigurationException, TransformerConfigurationException { File callerScript = this.currentScript; Document doc = null; try { this.currentScript = new File(script); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = db.parse(this.currentScript); } catch (Exception ex) { this.currentScript = callerScript; Utils.onError(new Error.FileParse(script)); return; } NodeList operations = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < operations.getLength(); i++) { Node operation = operations.item(i); if (operation.getNodeType() != Node.ELEMENT_NODE) continue; call(operation); } this.currentScript = callerScript; }
private static FileInfo parseFile(Node parent) throws XmlParserException { String label = ""; String name = ""; String location = ""; Vector<Annotation> annotations = null; 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("label")) label = element.getTextContent(); else if (element.getTagName().equals("name")) name = element.getTextContent(); else if (element.getTagName().equals("location")) location = element.getTextContent(); else if (element.getTagName().equals("annotations")) annotations = parseAnnotations(node); } FileInfo file = new FileInfo(label, name, location); if (annotations != null) file.addAnnotations(annotations); return file; }
// http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html private double my_ListParser(int itIs) { double[] my_list = new double[3]; try { File fXmlFile = new File("/Users/alexiaKourfali/NetBeansProjects/mav_project3_part2/web/my_list.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(fXmlFile); doc.getDocumentElement().normalize(); // System.out.println("Root element " + doc.getDocumentElement().getNodeName()); NodeList nodeLst = doc.getElementsByTagName("Entry"); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("Price"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); Node nV = (Node) fstNm.item(0); /*not sureeeee*/ my_list[s] = Double.parseDouble(nV.getNodeValue()); } } } catch (Exception e) { } if (itIs == 0) return my_list[0]; if (itIs == 1) return my_list[1]; else return my_list[2]; }
public List<ClassNode> getClasses() { ArrayList<ClassNode> classes = new ArrayList<ClassNode>(); /** * Получаем список дочерних узлов для данного узла XML, который соответствует приложению * application. Здесь будут располагаться все узлы Node, каждый из которых является объектным * представлением тега class для текущего тега application. */ NodeList classNodes = node.getChildNodes(); for (int i = 0; i < classNodes.getLength(); i++) { Node node = classNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { /** Создаем на основе Node узла своё объектное представление класса. */ ClassNode classNode = new ClassNode(node); classes.add(classNode); } } return classes; }
/** Возвращает список методов класса. */ public List<MethodNode> getMethods() { ArrayList<MethodNode> methods = new ArrayList<MethodNode>(); /** * Получаем список дочерних узлов для данного узла XML, который соответствует классу class. * Здесь будут располагаться все узлы Node, каждый из которых является объектным * представлением тега method для текущего тега class. */ NodeList methodNodes = node.getChildNodes(); for (int i = 0; i < methodNodes.getLength(); i++) { node = methodNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { /** Создаем на основе Node узла своё объектное представление метода. */ MethodNode methodNode = new MethodNode(node); methods.add(methodNode); } } return methods; }
public void outputOwners(PrintWriter out) { // traverse doc, outputing nodes log.info("inserting owners "); try { Node tree = dom.getNode(); NodeList children = tree.getChildNodes(); log.info("dom tree contains " + children.getLength() + " nodes"); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { // check to see if there are collections under owner Element e = (Element) child; outputItem(e, out); } } } catch (Exception e) { log.severe("Could not init ownerHierarchy because exception thrown:"); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); log.severe(sw.toString()); } }
@SuppressWarnings("unchecked") private static BackgroundIon<? extends Peak> parseBackgroundIon(Node parent) throws XmlParserException { // retrieve the separate peaks PeakData<? extends Peak> peakdata = null; 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("peakdata")) { peakdata = parsePeakData(element); } } // create the bugger BackgroundIon<? extends Peak> backgroundion = null; if (peakdata.getFactory().getPeakClass().equals(Centroid.class)) backgroundion = new BackgroundIon<Centroid>((PeakData<Centroid>) peakdata); parseIPeak(parent, backgroundion); return backgroundion; }
// ----------------------------------------------------- // Description: Using the specified template, create // csv records corresponding to the output xml criteria. // ----------------------------------------------------- void transformWithTemplate(String templateName, String fileName, String destinationDirectory) { System.out.println("fileName = " + fileName); String fileName_woext = fileName.substring(0, fileName.lastIndexOf('.')); try { File fXmlFile = new File(templateLocation, templateName); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("output"); // loop through all the output nodes for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String outputLine = getTagValue("line", eElement); FileWriter output = new FileWriter( destinationDirectory + File.separator + fileName_woext.substring(0, fileName.lastIndexOf('_')) + ".csv", true); BufferedWriter bufWrite = new BufferedWriter(output); System.out.println( destinationDirectory + File.separator + fileName_woext.substring(0, fileName.lastIndexOf("_")) + ".csv"); if (Settings.optionalIdentifier != null) { bufWrite.write("\"" + Settings.optionalIdentifier + "\""); } String[] outputItems = outputLine.split("#"); for (String outputItem : outputItems) { if ((temp == 0) && (Settings.optionalIdentifier == null)) { bufWrite.write( "\"" + interpretText(destinationDirectory, fileName_woext, outputItem) + "\""); } else { bufWrite.write( ",\"" + interpretText(destinationDirectory, fileName_woext, outputItem) + "\""); } } bufWrite.write("\r\n"); bufWrite.close(); output.close(); } } } catch (Exception e) { e.printStackTrace(); } }