List of usage examples for org.dom4j.io SAXReader setEntityResolver
public void setEntityResolver(EntityResolver entityResolver)
From source file:com.cladonia.xml.XMLUtilities.java
License:Open Source License
/** * Validates the document for this URL./*from w ww.j a v a 2s .c o m*/ * * @param url the URL of the document. * * @return the Dom4J document. */ public static synchronized XDocument validate(ErrorHandler handler, BufferedReader isReader, String systemId) throws IOException, SAXParseException { if (DEBUG) System.out.println("DocumentUtilities.validate( " + isReader + ", " + systemId + ")"); XDocument document = null; try { SAXReader reader = createReader(true, false); reader.setEntityResolver(getCatalogResolver()); reader.setErrorHandler(handler); String encoding = null; try { isReader.mark(1024); encoding = getXMLDeclaration(isReader).getEncoding(); // } catch ( NotXMLException e) { // e.printStackTrace(); // throw( e); } finally { isReader.reset(); } XMLReader xmlReader = createReader(isReader, encoding); document = (XDocument) reader.read(xmlReader, systemId); document.setEncoding(xmlReader.getEncoding()); document.setVersion(xmlReader.getVersion()); } catch (DocumentException e) { Exception x = (Exception) e.getNestedException(); if (x instanceof SAXParseException) { SAXParseException spe = (SAXParseException) x; Exception ex = spe.getException(); if (ex instanceof IOException) { throw (IOException) ex; } else { throw (SAXParseException) x; } } else if (x instanceof IOException) { throw (IOException) x; } } return document; }
From source file:com.cladonia.xml.XMLUtilities.java
License:Open Source License
public static synchronized void validate(ErrorHandler handler, BufferedReader isReader, String systemId, String encoding, int type, String grammarLocation) throws IOException, SAXParseException { if (DEBUG)//from w w w.j a v a 2 s. c o m System.out.println("XMLUtilities.validate( " + isReader + ", " + systemId + ", " + encoding + ", " + type + ", " + grammarLocation + ")"); if (type == XMLGrammar.TYPE_RNG || type == XMLGrammar.TYPE_RNC || type == XMLGrammar.TYPE_NRL) { ValidationDriver driver = null; String encode = encoding; if (type == XMLGrammar.TYPE_RNC) { driver = new ValidationDriver(makePropertyMap(null, handler, CHECK_ID_IDREF, false), CompactSchemaReader.getInstance()); } else if (type == XMLGrammar.TYPE_NRL) { driver = new ValidationDriver(makePropertyMap(null, handler, CHECK_ID_IDREF, true), new AutoSchemaReader()); } else { driver = new ValidationDriver(makePropertyMap(null, handler, CHECK_ID_IDREF, false)); } try { isReader.mark(1024); encode = getXMLDeclaration(isReader).getEncoding(); // } catch ( NotXMLException e) { // encode = encoding; // e.printStackTrace(); } finally { isReader.reset(); } InputSource source = new InputSource(isReader); source.setEncoding(encode); try { URL url = null; if (systemId != null) { try { url = new URL(systemId); } catch (MalformedURLException e) { // does not matter really, the base url is only null ... url = null; } } URL schemaURL = null; if (url != null) { schemaURL = new URL(url, grammarLocation); } else { schemaURL = new URL(grammarLocation); } driver.loadSchema(new InputSource(schemaURL.toString())); driver.validate(source); } catch (SAXException x) { x.printStackTrace(); if (x instanceof SAXParseException) { SAXParseException spe = (SAXParseException) x; Exception ex = spe.getException(); if (ex instanceof IOException) { throw (IOException) ex; } else { throw (SAXParseException) x; } } } catch (IOException e) { e.printStackTrace(); throw e; } } else { // type == XMLGrammar.TYPE_DTD || type == XMLGrammar.TYPE_XSD try { SAXReader reader = createReader(true, false); reader.setErrorHandler(handler); String encode = encoding; try { isReader.mark(1024); encode = getXMLDeclaration(isReader).getEncoding(); // } catch ( NotXMLException e) { // encode = encoding; // e.printStackTrace(); } finally { isReader.reset(); } XMLReader xmlReader = createReader(isReader, encode); try { if (type == XMLGrammar.TYPE_DTD) { reader.setFeature("http://apache.org/xml/features/validation/schema", false); reader.setEntityResolver(new DummyEntityResolver(grammarLocation)); } else { // type == XMLGrammar.TYPE_XSD URL url = null; if (systemId != null) { try { url = new URL(systemId); } catch (MalformedURLException e) { // does not matter really, the base url is only null ... url = null; } } URL schemaURL = null; if (url != null) { schemaURL = new URL(url, grammarLocation); } else { schemaURL = new URL(grammarLocation); } reader.setFeature("http://apache.org/xml/features/validation/schema", true); reader.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); reader.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", new InputSource(schemaURL.toString())); } } catch (Exception e) { e.printStackTrace(); } // try { // System.out.println( "http://apache.org/xml/features/validation/schema = "+reader.getXMLReader().getFeature( "http://apache.org/xml/features/validation/schema")); // } catch ( Exception e) { // e.printStackTrace(); // } reader.read(xmlReader, systemId); } catch (DocumentException e) { Exception x = (Exception) e.getNestedException(); // x.printStackTrace(); if (x instanceof SAXParseException) { SAXParseException spe = (SAXParseException) x; Exception ex = spe.getException(); if (ex instanceof IOException) { throw (IOException) ex; } else { throw (SAXParseException) x; } } else if (x instanceof IOException) { throw (IOException) x; } } } }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.SuiteResult.java
License:Open Source License
/** * Parses the JUnit XML file into {@link SuiteResult}s. This method returns a collection, as a single XML may have multiple <testsuite> * elements wrapped into the top-level <testsuites>. *//*from w w w . java2s . c o m*/ static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException { List<SuiteResult> r = new ArrayList<SuiteResult>(); // parse into DOM SAXReader saxReader = new SAXReader(); // install EntityResolver for resolving DTDs, which are in files created by TestNG. // (see https://hudson.dev.java.net/servlets/ReadMsg?listName=users&msgNo=5530) XMLEntityResolver resolver = new XMLEntityResolver(); saxReader.setEntityResolver(resolver); Document result = saxReader.read(xmlReport); Element root = result.getRootElement(); if (root.getName().equals("testsuites")) { // multi-suite file for (Element suite : (List<Element>) root.elements("testsuite")) r.add(new SuiteResult(xmlReport, suite, keepLongStdio)); } else { // single suite file r.add(new SuiteResult(xmlReport, root, keepLongStdio)); } return r; }
From source file:com.devoteam.srit.xmlloader.core.coding.binary.XMLDoc.java
License:Open Source License
/** * Parses the XMLFile against the XMLSchema * @throws java.lang.ParsingException//from w w w. j av a 2 s . co m */ public void parse() throws ParsingException { if (null == this.xmlFile) { throw new ParsingException("XML file not setted"); } final LinkedList<InputStream> streamsList = new LinkedList(); try { // // create a SchemaFactory capable of understanding WXS schemas // SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // // Load a XSD schema, represented by a Schema instance // final XMLDoc _this = this; factory.setResourceResolver(new LSResourceResolver() { public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { if (!systemId.toLowerCase().endsWith(".xsd")) { return null; } return new LSInput() { public InputStream getByteStream() { return null; } public Reader getCharacterStream() { return null; } public void setCharacterStream(Reader characterStream) { } public void setByteStream(InputStream byteStream) { } public String getStringData() { return ""; } public void setStringData(String stringData) { } public String getSystemId() { return ""; } public void setSystemId(String systemId) { } public String getPublicId() { return ""; } public void setPublicId(String publicId) { } public String getBaseURI() { return ""; } public void setBaseURI(String baseURI) { } public String getEncoding() { return "UTF-8"; } public void setEncoding(String encoding) { } public boolean getCertifiedText() { return false; } public void setCertifiedText(boolean certifiedText) { } }; } }); // // Create and configure the DocumentBuilderFactory // DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance(); parserFactory.setValidating(false); parserFactory.setNamespaceAware(true); parserFactory.setCoalescing(true); // // Get the parser // DocumentBuilder parser = parserFactory.newDocumentBuilder(); // // Parse to check document agains XSD // parser.setEntityResolver(new XMLLoaderEntityResolver(this.xmlFile)); parser.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { } public void error(SAXParseException exception) throws SAXException { throw exception; } public void fatalError(SAXParseException exception) throws SAXException { throw exception; } }); parser.parse(openInputStream(streamsList, this.xmlFile), this.getXMLFile().toString()); // // Instanciate the XML parser (no valididy check with dtd) // SAXReader reader = new SAXReader(false); reader.setEntityResolver(new XMLLoaderEntityResolver(this.xmlFile)); document = reader.read(openInputStream(streamsList, this.xmlFile), this.getXMLFile().toString()); } catch (SAXParseException e) { throw new ParsingException("In file : " + xmlFile + "\n" + "Parsing error at line " + e.getLineNumber() + ", column " + e.getColumnNumber() + "\n" + e.getMessage(), e); } catch (Exception e) { throw new ParsingException(e); } finally { for (InputStream stream : streamsList) { try { stream.close(); } catch (Exception e) { // ignore } } } }
From source file:com.devoteam.srit.xmlloader.core.Parameter.java
License:Open Source License
public void applyXPath(String xml, String xpath, boolean deleteNS) throws Exception { // remove beginning to '<' character int iPosBegin = xml.indexOf('<'); if (iPosBegin > 0) { xml = xml.substring(iPosBegin);//from w ww . j av a 2s . c o m } // remove from '>' character to the end int iPosEnd = xml.lastIndexOf('>'); if ((iPosEnd > 0) && (iPosEnd < xml.length() - 1)) { xml = xml.substring(0, iPosEnd + 1); } int iPosXMLLine = xml.indexOf("<?xml"); if (iPosXMLLine < 0) { xml = "<?xml version='1.0'?>" + xml; } // remove the namespace because the parser does not support them if there are not declare in the root node if (deleteNS) { xml = xml.replaceAll("<[a-zA-Z\\.0-9_]+:", "<"); xml = xml.replaceAll("</[a-zA-Z\\.0-9_]+:", "</"); } // remove doctype information (dtd files for the XML syntax) xml = xml.replaceAll("<!DOCTYPE\\s+\\w+\\s+\\w+\\s+[^>]+>", ""); InputStream input = new ByteArrayInputStream(xml.getBytes()); SAXReader reader = new SAXReader(false); reader.setEntityResolver(new XMLLoaderEntityResolver()); Document document = reader.read(input); XPath xpathObject = document.createXPath(xpath); Object obj = xpathObject.evaluate(document.getRootElement()); if (obj instanceof List) { List<Node> list = (List<Node>) obj; for (Node node : list) { add(node.asXML()); } } else if (obj instanceof DefaultElement) { Node node = (Node) obj; add(node.asXML()); } else if (obj instanceof DefaultAttribute) { Node node = (Node) obj; add(node.getStringValue()); } else if (obj instanceof DefaultText) { Node node = (Node) obj; add(node.getText()); } else { add(obj.toString()); } }
From source file:com.devoteam.srit.xmlloader.core.utils.Utils.java
License:Open Source License
public static Document stringParseXML(String xml, boolean deleteNS) throws Exception { // remove beginning to '<' character int iPosBegin = xml.indexOf('<'); if (iPosBegin > 0) { xml = xml.substring(iPosBegin);//from w w w . ja v a2s .c o m } // remove from '>' character to the end int iPosEnd = xml.lastIndexOf('>'); if ((iPosEnd > 0) && (iPosEnd < xml.length() - 1)) { xml = xml.substring(0, iPosEnd + 1); } int iPosXMLLine = xml.indexOf("<?xml"); if (iPosXMLLine < 0) { xml = "<?xml version='1.0'?>" + xml; } // remove the namespace because the parser does not support them if there are not declare in the root node if (deleteNS) { xml = xml.replaceAll("<[a-zA-Z\\.0-9_]+:", "<"); xml = xml.replaceAll("</[a-zA-Z\\.0-9_]+:", "</"); } // remove doctype information (dtd files for the XML syntax) xml = xml.replaceAll("<!DOCTYPE\\s+\\w+\\s+\\w+\\s+[^>]+>", ""); InputStream input = new ByteArrayInputStream(xml.getBytes()); SAXReader reader = new SAXReader(false); reader.setEntityResolver(new XMLLoaderEntityResolver()); Document document = reader.read(input); return document; }
From source file:com.devoteam.srit.xmlloader.core.utils.XMLDocument.java
License:Open Source License
/** * Parses the XMLFile against the XMLSchema * @throws java.lang.ParsingException// www .j a v a 2 s .c o m */ public void parse() throws ParsingException { if (null == this.schemaFile) { throw new ParsingException("Schema file not setted"); } if (null == this.xmlFile) { throw new ParsingException("XML file not setted"); } final LinkedList<InputStream> streamsList = new LinkedList(); try { // // create a SchemaFactory capable of understanding WXS schemas // SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // // Load a XSD schema, represented by a Schema instance // Source schemaSource = new StreamSource(openInputStream(streamsList, this.schemaFile)); final XMLDocument _this = this; factory.setResourceResolver(new LSResourceResolver() { public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { if (!systemId.toLowerCase().endsWith(".xsd")) { return null; } final URI finalPath = URIFactory.resolve(_this.schemaFile, systemId);//"./" + schemaFile).substring(0, ("./" + schemaFile).lastIndexOf("/") + 1) + systemId; return new LSInput() { public InputStream getByteStream() { try { InputStream in = openInputStream(streamsList, finalPath); if (null == in) { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.CORE, "Exception : Include the XML file : ", finalPath); } return in; } catch (Exception e) { e.printStackTrace(); return null; } } public Reader getCharacterStream() { return null; } public void setCharacterStream(Reader characterStream) { } public void setByteStream(InputStream byteStream) { } public String getStringData() { return ""; } public void setStringData(String stringData) { } public String getSystemId() { return ""; } public void setSystemId(String systemId) { } public String getPublicId() { return ""; } public void setPublicId(String publicId) { } public String getBaseURI() { return ""; } public void setBaseURI(String baseURI) { } public String getEncoding() { return "UTF-8"; } public void setEncoding(String encoding) { } public boolean getCertifiedText() { return false; } public void setCertifiedText(boolean certifiedText) { } }; } }); Schema schema = factory.newSchema(schemaSource); // // Create and configure the DocumentBuilderFactory // DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance(); parserFactory.setSchema(schema); parserFactory.setValidating(false); parserFactory.setNamespaceAware(true); parserFactory.setCoalescing(true); // // Get the parser // DocumentBuilder parser = parserFactory.newDocumentBuilder(); // // Parse to check document agains XSD // parser.setEntityResolver(new XMLLoaderEntityResolver(this.xmlFile)); parser.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { } public void error(SAXParseException exception) throws SAXException { throw exception; } public void fatalError(SAXParseException exception) throws SAXException { throw exception; } }); parser.parse(openInputStream(streamsList, this.xmlFile), this.getXMLFile().toString()); // // Instanciate the XML parser (no valididy check with dtd) // SAXReader reader = new SAXReader(false); reader.setEntityResolver(new XMLLoaderEntityResolver(this.xmlFile)); document = reader.read(openInputStream(streamsList, this.xmlFile), this.getXMLFile().toString()); } catch (SAXParseException e) { throw new ParsingException("In file : " + xmlFile + "\n" + "Parsing error at line " + e.getLineNumber() + ", column " + e.getColumnNumber() + "\n" + e.getMessage(), e); } catch (Exception e) { throw new ParsingException(e); } finally { for (InputStream stream : streamsList) { try { stream.close(); } catch (Exception e) { // ignore } } } }
From source file:com.digiaplus.lms.core.xml.XMLParser.java
License:Apache License
/** * @param in/*from ww w .j a v a 2 s .c om*/ * @param validateXML * @return parsed document */ public Document parse(InputStream in, boolean validateXML) { Document document; try { SAXReader reader = new SAXReader(); reader.setEntityResolver(er); reader.setValidation(validateXML); document = reader.read(in, ""); document.normalize(); } catch (Exception e) { throw new DAPRuntimeException(XMLParser.class, "Exception reading XML", e); } return document; }
From source file:com.dtolabs.shared.resources.ResourceXMLParser.java
License:Apache License
/** * Parse the document, applying the configured Receiver to the parsed entities * * @throws ResourceXMLParserException parse error * @throws java.io.IOException io error/*from ww w. j a va 2 s .c o m*/ */ public void parse() throws ResourceXMLParserException, IOException { final EntityResolver resolver = createEntityResolver(); final SAXReader reader = new SAXReader(false); reader.setEntityResolver(resolver); try { final Document doc; if (null == this.doc) { final InputStream in; if (null != file) { in = new FileInputStream(file); } else { in = input; } try { doc = reader.read(in); } finally { if (null != file) { in.close(); } } } else { doc = this.doc; } final EntitySet set = new EntitySet(); final Element root = doc.getRootElement(); final List list = root.selectNodes(entityXpath); for (final Object n : list) { final Node node = (Node) n; final Entity ent = parseEnt(node, set); if (null != receiver) { if (!receiver.resourceParsed(ent)) { break; } } } if (null != receiver) { receiver.resourcesParsed(set); } } catch (DocumentException e) { throw new ResourceXMLParserException(e); } }
From source file:com.erpak.jtrackplanner3d.xml.LibraryReader.java
License:Open Source License
/** * create a new LibraryReader object with the library file name * @param fileName Name of the library file */// w w w. j av a 2s .co m public LibraryReader(File libraryFile) { TrackSystem trackSystem = null; TracksTreeCellRenderer renderer = new TracksTreeCellRenderer(); try { renderer.setStraigthTrackIcon(new ImageIcon(ResourcesManager.getResource("StraigthTrackIcon"))); renderer.setCurvedTrackIcon(new ImageIcon(ResourcesManager.getResource("CurvedTrackIcon"))); renderer.setStraightTurnoutTrackIcon( new ImageIcon(ResourcesManager.getResource("StraigthTurnoutTrackIcon"))); renderer.setCrossingTrackIcon(new ImageIcon(ResourcesManager.getResource("CrossingTrackIcon"))); } catch (Exception ex) { logger.error("Unable to load tree node icons"); logger.error(ex.toString()); } try { Element trackSystemInfoNode; Element element; Element subElement; Attribute attribute; Iterator iter; DefaultMutableTreeNode treeTop; DefaultMutableTreeNode treeCategory; DefaultMutableTreeNode treeElement; // Load the xml library file InputStream in = new FileInputStream(libraryFile); EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { logger.debug("Public id : " + publicId); logger.debug("System Id : " + systemId); if (publicId.equals("-//TrackPlanner//DTD track_system V 1.0//EN")) { InputStream in = getClass().getResourceAsStream("ressources/track_system.dtd"); return new InputSource(in); } return null; } }; SAXReader reader = new SAXReader(); reader.setEntityResolver(resolver); // Read the xml library file Document document = reader.read(in); Element root = document.getRootElement(); logger.debug("Root name : " + root.getName()); // Get "track_system_info" node trackSystemInfoNode = root.element("track_system_infos"); // Get track_system_info_node attributes trackSystem = new TrackSystem(trackSystemInfoNode.attribute("name").getValue(), trackSystemInfoNode.attribute("version").getValue()); trackSystem.setScale(trackSystemInfoNode.attribute("scale").getValue()); trackSystem.setManufacturer(trackSystemInfoNode.attribute("manufacturer").getValue()); // Get the "track_system_caracteristics" node element = trackSystemInfoNode.element("track_system_caracteristics"); trackSystem.setBallastWidth(Float.parseFloat(element.attribute("ballast_width").getValue())); trackSystem.setTrackWidth(Float.parseFloat(element.attribute("railway_width").getValue())); // Get the "track_system_colors" node element = trackSystemInfoNode.element("track_system_colors"); for (iter = element.elementIterator(); iter.hasNext();) { subElement = (Element) iter.next(); trackSystem.addColor(subElement.attribute("name").getValue(), subElement.attribute("r").getValue(), subElement.attribute("g").getValue(), subElement.attribute("b").getValue()); } // Set the top node of tree with tracksystem treeTop = new DefaultMutableTreeNode(trackSystem.getName()); // iterate "straight_tracks" node element = root.element("straight_tracks"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (iter = element.elementIterator("straight_track"); iter.hasNext();) { subElement = (Element) iter.next(); logger.debug("Adding reference : " + subElement.attribute("reference").getValue()); treeElement = new DefaultMutableTreeNode(new StraightTrackSymbol(trackSystem, subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), Float.parseFloat(subElement.attribute("length").getValue()), subElement.attribute("color").getValue())); treeCategory.add(treeElement); } // iterate "curved_tracks" node element = root.element("curved_tracks"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (iter = element.elementIterator("curved_track"); iter.hasNext();) { subElement = (Element) iter.next(); logger.debug("Adding reference : " + subElement.attribute("reference").getValue()); treeElement = new DefaultMutableTreeNode(new CurvedTrackSymbol(trackSystem, subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), Float.parseFloat(subElement.attribute("radius").getValue()), Float.parseFloat(subElement.attribute("angle").getValue()), subElement.attribute("color").getValue())); treeCategory.add(treeElement); } // iterate "straight_turnouts" node element = root.element("straight_turnouts"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (iter = element.elementIterator("straight_turnout"); iter.hasNext();) { subElement = (Element) iter.next(); logger.debug("Adding reference : " + subElement.attribute("reference").getValue()); treeElement = new DefaultMutableTreeNode(new StraightTurnoutSymbol(trackSystem, subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), Float.parseFloat(subElement.attribute("length").getValue()), Float.parseFloat(subElement.attribute("radius").getValue()), Float.parseFloat(subElement.attribute("angle").getValue()), subElement.attribute("direction").getValue(), subElement.attribute("color").getValue())); treeCategory.add(treeElement); } // iterate through "curved_turnouts" node element = root.element("curved_turnouts"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (Iterator i = root.elementIterator("curved_turnouts"); i.hasNext();) { element = (Element) i.next(); logger.debug("Node : " + element.getName()); } // iterate through "three_way_turnouts" node element = root.element("three_way_turnouts"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (iter = element.elementIterator("symetric_three_way_turnout"); iter.hasNext();) { subElement = (Element) iter.next(); logger.debug("Adding reference : " + subElement.attribute("reference").getValue()); treeElement = new DefaultMutableTreeNode(new SymetricThreeWayTurnoutSymbol(trackSystem, subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(), Float.parseFloat(subElement.attribute("length").getValue()), Float.parseFloat(subElement.attribute("radius").getValue()), Float.parseFloat(subElement.attribute("angle").getValue()), subElement.attribute("color").getValue())); treeCategory.add(treeElement); } // iterate through "crossings" node element = root.element("crossings"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (Iterator i = root.elementIterator("crossings"); i.hasNext();) { element = (Element) i.next(); logger.debug("Node : " + element.getName()); } // iterate through "double_slip_switchs" node element = root.element("double_slip_switchs"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (Iterator i = root.elementIterator("double_slip_switchs"); i.hasNext();) { element = (Element) i.next(); logger.debug("Node : " + element.getName()); } // iterate through "special_tracks" node element = root.element("special_tracks"); treeCategory = new DefaultMutableTreeNode(element.getName()); treeTop.add(treeCategory); logger.debug("Node : " + element.getName()); for (Iterator i = root.elementIterator("special_tracks"); i.hasNext();) { element = (Element) i.next(); logger.debug("Node : " + element.getName()); } // fill the tree tree = new JTree(treeTop); } catch (Exception ex) { logger.error("Unable to load track trackSystem library", ex); // Todo : Throws an exception and display an error box instaed of displaying atree with scrap data tree = new JTree(); } logger.debug("Parsing done for trackSystem : " + trackSystem); tree.setName("Track systems"); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer(renderer); }