1 21 22 package nu.xom.xslt; 23 24 import java.io.IOException ; 25 26 import nu.xom.converters.SAXConverter; 27 28 import org.xml.sax.ContentHandler ; 29 import org.xml.sax.DTDHandler ; 30 import org.xml.sax.EntityResolver ; 31 import org.xml.sax.ErrorHandler ; 32 import org.xml.sax.InputSource ; 33 import org.xml.sax.SAXException ; 34 import org.xml.sax.SAXNotRecognizedException ; 35 import org.xml.sax.SAXNotSupportedException ; 36 import org.xml.sax.XMLReader ; 37 import org.xml.sax.ext.LexicalHandler ; 38 39 51 class XOMReader implements XMLReader { 52 53 private SAXConverter converter; 54 55 public boolean getFeature(String uri) 56 throws SAXNotRecognizedException , SAXNotSupportedException { 57 58 if ("http://xml.org/sax/features/namespace-prefixes".equals(uri) 59 || "http://xml.org/sax/features/namespaces".equals(uri)) { 60 return true; 61 } 62 throw new SAXNotRecognizedException ("XOMReader doesn't support features"); 63 64 } 65 66 67 public void setFeature(String uri, boolean value) 68 throws SAXNotRecognizedException , SAXNotSupportedException { 69 70 } 71 72 73 public Object getProperty(String uri) throws SAXNotRecognizedException , 74 SAXNotSupportedException { 75 76 if ("http://xml.org/sax/properties/lexical-handler".equals(uri)) { 77 return converter.getLexicalHandler(); 78 } 79 else { 80 throw new SAXNotRecognizedException ("XOMReader doesn't support features"); 81 } 82 83 } 84 85 86 public void setProperty(String uri, Object value) 87 throws SAXNotRecognizedException , SAXNotSupportedException { 88 89 if ("http://xml.org/sax/properties/lexical-handler".equals(uri)) { 90 LexicalHandler handler = (LexicalHandler ) value; 91 converter.setLexicalHandler(handler); 92 } 93 else { 94 throw new SAXNotRecognizedException ( 95 "XOMReader doesn't support " + uri); 96 } 97 98 } 99 100 101 public void setEntityResolver(EntityResolver resolver) { 102 throw new UnsupportedOperationException (); 103 } 104 105 106 public EntityResolver getEntityResolver() { 107 return null; 108 } 109 110 111 public void setDTDHandler(DTDHandler handler) { 112 } 114 115 116 public DTDHandler getDTDHandler() { 117 return null; 118 } 119 120 121 public void setContentHandler(ContentHandler handler) { 122 converter = new SAXConverter(handler); 123 } 124 125 126 public ContentHandler getContentHandler() { 127 return null; 128 } 129 130 131 public void setErrorHandler(ErrorHandler handler) { 132 } 133 134 135 public ErrorHandler getErrorHandler() { 136 return null; 137 } 138 139 140 public void parse(InputSource source) 141 throws IOException , SAXException { 142 143 XOMInputSource xis = (XOMInputSource) source; 144 converter.convert(xis.getNodes()); 145 146 } 147 148 149 public void parse(String url) throws IOException , SAXException { 150 throw new UnsupportedOperationException (); 151 } 152 153 154 } 155 | Popular Tags |