1 38 39 40 package com.sun.xml.fastinfoset.stax; 41 42 import com.sun.xml.fastinfoset.tools.XML_SAX_FI; 43 44 import java.io.InputStream ; 45 import java.io.Reader ; 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.BufferedInputStream ; 49 import java.io.BufferedOutputStream ; 50 51 import javax.xml.stream.*; 52 import javax.xml.stream.XMLStreamException; 53 import javax.xml.stream.util.XMLEventAllocator ; 54 import javax.xml.transform.Source ; 55 import javax.xml.transform.stream.StreamSource ; 56 import com.sun.xml.fastinfoset.CommonResourceBundle; 57 58 public class StAXInputFactory extends XMLInputFactory { 59 private StAXManager _manager = new StAXManager(StAXManager.CONTEXT_READER) ; 61 62 public StAXInputFactory() { 63 } 64 65 public static XMLInputFactory newInstance() { 66 return XMLInputFactory.newInstance(); 67 } 68 69 74 public XMLStreamReader createXMLStreamReader(Reader xmlfile) throws XMLStreamException { 75 return getXMLStreamReader(xmlfile); 76 } 77 78 public XMLStreamReader createXMLStreamReader(InputStream s) throws XMLStreamException { 79 return new StAXDocumentParser(s, _manager); 80 } 81 82 public XMLStreamReader createXMLStreamReader(String systemId, Reader xmlfile) throws XMLStreamException { 83 return getXMLStreamReader(xmlfile); 84 } 85 86 public XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException { 87 return null; 88 } 89 90 public XMLStreamReader createXMLStreamReader(String systemId, InputStream inputstream) throws XMLStreamException { 91 return createXMLStreamReader(inputstream); 92 } 93 94 95 public XMLStreamReader createXMLStreamReader(InputStream inputstream, String encoding) throws XMLStreamException { 96 return createXMLStreamReader(inputstream); 97 } 98 99 100 XMLStreamReader getXMLStreamReader(String systemId, InputStream inputstream, String encoding) 101 throws XMLStreamException{ 102 return createXMLStreamReader(inputstream); 103 104 } 105 106 111 XMLStreamReader getXMLStreamReader(Reader xmlfile) 112 throws XMLStreamException{ 113 114 ByteArrayOutputStream byteStream = new ByteArrayOutputStream (); 115 BufferedOutputStream bufferedStream = new BufferedOutputStream (byteStream); 116 StAXDocumentParser sr = null; 117 try { 118 XML_SAX_FI convertor = new XML_SAX_FI(); 119 convertor.convert(xmlfile, bufferedStream); 120 121 ByteArrayInputStream byteInputStream = new ByteArrayInputStream (byteStream.toByteArray()); 122 InputStream document = new BufferedInputStream (byteInputStream); 123 sr = new StAXDocumentParser(); 124 sr.setInputStream(document); 125 sr.setManager(_manager); 126 return sr; 127 } catch (Exception e) { 129 return null; 130 } 131 132 } 133 134 135 140 public XMLEventReader createXMLEventReader(InputStream inputstream) throws XMLStreamException { 141 return new StAXEventReader(createXMLStreamReader(inputstream)); 142 } 143 144 public XMLEventReader createXMLEventReader(Reader reader) throws XMLStreamException { 145 return new StAXEventReader(createXMLStreamReader(reader)); 146 } 147 148 public XMLEventReader createXMLEventReader(Source source) throws XMLStreamException { 149 return new StAXEventReader(createXMLStreamReader(source)); 150 } 151 152 public XMLEventReader createXMLEventReader(String systemId, InputStream inputstream) throws XMLStreamException { 153 return new StAXEventReader(createXMLStreamReader(systemId, inputstream)); 154 } 155 156 public XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding) throws XMLStreamException { 157 return new StAXEventReader(createXMLStreamReader(stream, encoding)); 158 } 159 160 public XMLEventReader createXMLEventReader(String systemId, Reader reader) throws XMLStreamException { 161 return new StAXEventReader(createXMLStreamReader(systemId, reader)); 162 } 163 164 171 public XMLEventReader createXMLEventReader(XMLStreamReader streamReader) throws XMLStreamException { 172 return new StAXEventReader(streamReader); 173 } 174 175 public XMLEventAllocator getEventAllocator() { 176 return (XMLEventAllocator)getProperty(XMLInputFactory.ALLOCATOR); 177 } 178 179 public XMLReporter getXMLReporter() { 180 return (XMLReporter)_manager.getProperty(XMLInputFactory.REPORTER); 181 } 182 183 public XMLResolver getXMLResolver() { 184 Object object = _manager.getProperty(XMLInputFactory.RESOLVER); 185 return (XMLResolver)object; 186 } 188 189 public void setXMLReporter(XMLReporter xmlreporter) { 190 _manager.setProperty(XMLInputFactory.REPORTER, xmlreporter); 191 } 192 193 public void setXMLResolver(XMLResolver xmlresolver) { 194 _manager.setProperty(XMLInputFactory.RESOLVER, xmlresolver); 195 } 196 197 202 public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException { 203 return new StAXFilteredEvent(reader, filter); 204 } 205 206 211 public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException { 212 213 if( reader != null && filter != null ) 214 return new StAXFilteredParser(reader,filter); 215 216 return null; 217 } 218 219 220 221 226 public Object getProperty(String name) throws IllegalArgumentException { 227 if(name == null){ 228 throw new IllegalArgumentException (CommonResourceBundle.getInstance().getString("message.nullPropertyName")); 229 } 230 if(_manager.containsProperty(name)) 231 return _manager.getProperty(name); 232 throw new IllegalArgumentException (CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object []{name})); 233 } 234 235 240 public boolean isPropertySupported(String name) { 241 if(name == null) 242 return false ; 243 else 244 return _manager.containsProperty(name); 245 } 246 247 250 public void setEventAllocator(XMLEventAllocator allocator) { 251 _manager.setProperty(XMLInputFactory.ALLOCATOR, allocator); 252 } 253 254 261 public void setProperty(String name, Object value) throws IllegalArgumentException { 262 _manager.setProperty(name,value); 263 } 264 265 } 266 | Popular Tags |