private void loadData(File path) { if (path.isDirectory()) { File[] dataFiles = path.listFiles(new XMLFilter()); SAXBuilder builder = new SAXBuilder(); GeneratorDtdResolver resolver = new GeneratorDtdResolver(path); builder.setEntityResolver(resolver); for (int i = 0; i < dataFiles.length; i++) { try { URL url = dataFiles[i].toURI().toURL(); Document nameSet = builder.build(url); DocType dt = nameSet.getDocType(); if (dt.getElementName().equals("GENERATOR")) { loadFromDocument(nameSet); } nameSet = null; dt = null; } catch (Exception e) { Logging.errorPrint(e.getMessage(), e); JOptionPane.showMessageDialog(this, "XML Error with file " + dataFiles[i].getName()); } } loadDropdowns(); } else { JOptionPane.showMessageDialog(this, "No data files in directory " + path.getPath()); } }
void getAttributes(Object node, String localName, String namespaceUri, List result) { if (node instanceof Element) { Element e = (Element) node; if (localName == null) { result.addAll(e.getAttributes()); } else { Attribute attr = e.getAttribute(localName, Namespace.getNamespace("", namespaceUri)); if (attr != null) { result.add(attr); } } } else if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; if ("target".equals(localName)) { result.add(new Attribute("target", pi.getTarget())); } else if ("data".equals(localName)) { result.add(new Attribute("data", pi.getData())); } else { result.add(new Attribute(localName, pi.getValue(localName))); } } else if (node instanceof DocType) { DocType doctype = (DocType) node; if ("publicId".equals(localName)) { result.add(new Attribute("publicId", doctype.getPublicID())); } else if ("systemId".equals(localName)) { result.add(new Attribute("systemId", doctype.getSystemID())); } else if ("elementName".equals(localName)) { result.add(new Attribute("elementName", doctype.getElementName())); } } }