/* * processAttributes: * This method gets all of the attributes for a given soda element. * * Intput: * map: This is the soda element's map. * node: This is the xml node for the given element. * * Output: * returns a SodaHash object filled with the node's attributes if it has any. If there are * no attributes then an empty SodaHash is returned. * */ private SodaHash processAttributes(SodaHash map, Node node) { int len = node.getAttributes().getLength(); if (node.hasAttributes()) { for (int i = 0; i <= len - 1; i++) { Node tmp = node.getAttributes().item(i); String name = tmp.getNodeName(); String value = tmp.getNodeValue(); String accessor = findElementAccessor((SodaElements) map.get("type"), name); map.put(name, value); if (accessor != null) { map.put("how", accessor); } } } return map; }
/* * parse: * This method parses all the xml nodes into a SodaEvents object. * * Input: * node: This is a node list from the soda xml test. * * Output: * returns a SodaEvents object. */ private SodaEvents parse(NodeList node) throws Exception { SodaHash data = null; SodaEvents dataList = null; boolean err = false; int len = 0; dataList = new SodaEvents(); len = node.getLength(); for (int i = 0; i <= len - 1; i++) { Node child = node.item(i); String name = child.getNodeName(); if (name.startsWith("#")) { continue; } if (!sodaTypes.isValid(name)) { if (this.reporter == null) { System.err.printf("Error: Invalid Soda Element: '%s'!\n", name); } else { this.reporter.ReportError(String.format("Error: Invalid Soda Element: '%s'!", name)); } err = true; break; } data = new SodaHash(); data.put("do", name); data.put("type", SodaElements.valueOf(name.toUpperCase())); if (child.hasAttributes()) { data = processAttributes(data, child); } if (name.contains("javascript")) { String tmp = child.getTextContent(); if (!tmp.isEmpty()) { data.put("content", tmp); } } if (child.hasChildNodes()) { if (name.contains("execute")) { String[] list = processArgs(child.getChildNodes()); data.put("args", list); } else { SodaEvents tmp = parse(child.getChildNodes()); if (tmp != null) { data.put("children", tmp); } else { err = true; break; } } } if (!data.isEmpty()) { dataList.add(data); } else { System.out.printf("Note: No data found.\n"); } } if (err) { dataList = null; } return dataList; }