public void parseDataFormatXMLfile(URL url) throws MaltChainedException { if (url == null) { throw new DataFormatException("The data format specifcation file cannot be found. "); } try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Element root = db.parse(url.openStream()).getDocumentElement(); if (root.getNodeName().equals("dataformat")) { dataFormatName = root.getAttribute("name"); if (root.getAttribute("datastructure").length() > 0) { dataStructure = DataStructure.valueOf(root.getAttribute("datastructure").toUpperCase()); } else { dataStructure = DataStructure.DEPENDENCY; } } else { throw new DataFormatException( "Data format specification file must contain one 'dataformat' element. "); } NodeList cols = root.getElementsByTagName("column"); Element col; for (int i = 0, n = cols.getLength(); i < n; i++) { col = (Element) cols.item(i); DataFormatEntry entry = new DataFormatEntry( col.getAttribute("name"), col.getAttribute("category"), col.getAttribute("type"), col.getAttribute("default")); entries.put(entry.getDataFormatEntryName(), entry); } NodeList deps = root.getElementsByTagName("dependencies"); if (deps.getLength() > 0) { NodeList dep = ((Element) deps.item(0)).getElementsByTagName("dependency"); for (int i = 0, n = dep.getLength(); i < n; i++) { Element e = (Element) dep.item(i); dependencies.add( new Dependency( e.getAttribute("name"), e.getAttribute("url"), e.getAttribute("map"), e.getAttribute("urlmap"))); } } } catch (java.io.IOException e) { throw new DataFormatException("Cannot find the file " + url.toString() + ". ", e); } catch (ParserConfigurationException e) { throw new DataFormatException("Problem parsing the file " + url.toString() + ". ", e); } catch (SAXException e) { throw new DataFormatException("Problem parsing the file " + url.toString() + ". ", e); } }
public void addEntry( String dataFormatEntryName, String category, String type, String defaultOutput) { DataFormatEntry entry = new DataFormatEntry(dataFormatEntryName, category, type, defaultOutput); entries.put(entry.getDataFormatEntryName(), entry); }