public ParseDoc(Object xmlFile, String rootId, TreeMap prevIdMap) { SAXBuilder saxBuilder = new SAXBuilder(); try { if (xmlFile instanceof String) { document = saxBuilder.build((String) xmlFile); } else if (xmlFile instanceof URL) { document = saxBuilder.build((URL) xmlFile); } root = ParseUtils.parseRoot(document, rootId); objects = new TreeMap(); // Build description string (but not for the snippets.xml file) if (xmlFile instanceof String) { List authorL = root.getChildren("author"); String author = "<unknown>"; if (root.getAttributeValue("name") != null) { author = root.getAttributeValue("name"); } else if (authorL.size() > 0) { author = ((Element) authorL.get(0)).getValue(); } String description = "from file " + xmlFile.toString() + " (author: " + author + ") on " + new Date().toString(); HasIdentifiers.addGlobalIdentifier("_description_", description); } // Get all macro definitions, and remove them from document TreeMap macroMap = ParseUtils.getMacroDefs(root); // Process all macro expansions; replace macro expansion request with result ParseUtils.expandMacros(root, macroMap); // Get all elements in document, and assign identifiers to them; idMap = ParseUtils.parseId(root, prevIdMap); // Rewriting done; output debug XML code if (root.getAttributeValue("debug") != null) { XMLOutputter outputter = new XMLOutputter(); FileOutputStream fos = new FileOutputStream(xmlFile + ".debug"); outputter.output(document, fos); fos.close(); } } catch (JDOMException e) { // indicates a well-formedness or other error throw new Error("JDOMException: " + e.getMessage()); } catch (IOException e) { // indicates an IO problem throw new Error("IOException: " + e.getMessage()); } }
public void parseCodeGeneration() { // parse all <codeGeneration> elements List codeGenList = ParseUtils.parseDescendants(root, "codeGeneration", idMap); Iterator i = codeGenList.iterator(); while (i.hasNext()) { Element cgelt = (Element) i.next(); // It's the side effect that we're after here. new CodeGeneration(cgelt, idMap, objects); } }
public void parseCode() { // Parse all <code> and <parameter> elements List codeList = ParseUtils.parseDescendants(root, "code", idMap); Iterator i = codeList.iterator(); while (i.hasNext()) { Element codeElt = (Element) i.next(); String codeId = codeElt.getAttributeValue("id"); if (objects.containsKey(codeId)) { System.out.println("Note: Shadowing definition of <code id=\"" + codeId + "\">"); } objects.put(codeId, new Code(codeElt, idMap)); } }
public void parseIdRef() { // Change identifiers of referring elements to element referred to ParseUtils.parseIdref(root, idMap); }