Changeset 9
- Timestamp:
- 06/30/05 13:16:03 (3 years ago)
- Files:
-
- trunk/src/net/schst/XJConf/Extension.java (modified) (1 diff)
- trunk/src/net/schst/XJConf/XmlReader.java (modified) (6 diffs)
- trunk/src/net/schst/XJConf/ext/XInclude.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/net/schst/XJConf/Extension.java
r8 r9 8 8 public interface Extension { 9 9 10 public String getNamespace(); 11 10 12 public void startElement(XmlReader reader, Tag tag) 11 13 throws SAXException; trunk/src/net/schst/XJConf/XmlReader.java
r8 r9 5 5 import java.util.Stack; 6 6 7 import javax.xml.parsers.ParserConfigurationException; 7 8 import javax.xml.parsers.SAXParser; 8 9 import javax.xml.parsers.SAXParserFactory; … … 62 63 private Stack openFiles = new Stack(); 63 64 65 private SAXParserFactory parserFactory = null; 66 64 67 /** 65 68 * Set the tag definitions … … 88 91 } 89 92 93 public void addExtension(String name) { 94 try { 95 Class c = Class.forName(name); 96 Extension ext = (Extension)c.newInstance(); 97 String ns = ext.getNamespace(); 98 99 this.addExtension(ns, ext); 100 101 } catch (Exception e) { 102 e.printStackTrace(); 103 } 104 } 105 90 106 /** 91 107 * Parse a configuration file, that you already … … 95 111 */ 96 112 public void parse(File file) { 97 SAXParserFactory factory = SAXParserFactory.newInstance(); 98 factory.setNamespaceAware(true); 113 if (this.parserFactory == null) { 114 this.parserFactory = SAXParserFactory.newInstance(); 115 this.parserFactory.setNamespaceAware(true); 116 } 99 117 100 118 this.openFiles.push(file); 101 119 120 SAXParser saxParser; 102 121 try { 103 SAXParser saxParser = factory.newSAXParser();122 saxParser = this.parserFactory.newSAXParser(); 104 123 saxParser.parse(file, this); 105 124 } catch (Throwable t) { … … 136 155 public void startElement(String namespaceURI, String sName, String qName, Attributes atts) 137 156 throws SAXException { 157 138 158 if (this.myNamespace.equals(namespaceURI) && this.depth > 0) { 139 159 return; 140 160 } 141 161 142 162 this.depth++; 143 163 … … 161 181 } else { 162 182 if (!this.tagDefs.isNamespaceDefined(namespaceURI)) { 163 throw new UnknownNamespaceException("Unknown namespace " + namespaceURI); 183 File current = this.getCurrentFile(); 184 throw new UnknownNamespaceException("Unknown namespace " + namespaceURI + " in file " + current.getAbsolutePath()); 164 185 } 165 186 if (!this.tagDefs.isTagDefined(namespaceURI, sName)) { trunk/src/net/schst/XJConf/ext/XInclude.java
r8 r9 16 16 public class XInclude implements Extension { 17 17 18 private String namespace = "http://www.w3.org/2001/XInclude"; 19 20 public String getNamespace() { 21 return this.namespace; 22 } 23 18 24 /* (non-Javadoc) 19 25 * @see net.schst.XJConf.Extension#endElement(java.lang.String, java.lang.String) … … 29 35 href = current.getParent() + "/" + href; 30 36 } 31 32 37 reader.parse(href); 33 38 }
