1 31 package org.objectweb.proactive.core.xml.io; 32 33 import org.apache.log4j.Logger; 34 35 import org.apache.xerces.parsers.SAXParser; 36 37 import org.objectweb.proactive.core.config.ProActiveConfiguration; 38 39 40 import org.xml.sax.SAXNotRecognizedException ; 41 import org.xml.sax.SAXNotSupportedException ; 42 43 44 52 public class StreamReader implements XMLReader { 53 static Logger logger = Logger.getLogger(StreamReader.class.getName()); 54 private org.xml.sax.XMLReader parser; 55 private org.xml.sax.InputSource inputSource; 56 57 public StreamReader(java.io.InputStream in, XMLHandler xmlHandler) 58 throws java.io.IOException { 59 this(new org.xml.sax.InputSource (in), xmlHandler); 60 } 61 62 public StreamReader(java.io.Reader reader, XMLHandler xmlHandler) 63 throws java.io.IOException { 64 this(new org.xml.sax.InputSource (reader), xmlHandler); 65 } 66 67 public StreamReader(org.xml.sax.InputSource inputSource, 68 XMLHandler xmlHandler) throws java.io.IOException { 69 this.inputSource = inputSource; 70 DefaultHandlerAdapter adaptor = new DefaultHandlerAdapter(xmlHandler); 71 72 parser = new SAXParser(); 75 parser.setContentHandler(adaptor); 77 if ("enable".equals(ProActiveConfiguration.getSchemaValidationState())) { 78 try { 79 parser.setErrorHandler(new SAXParserErrorHandler()); 80 parser.setFeature("http://xml.org/sax/features/validation", true); 81 parser.setFeature("http://apache.org/xml/features/validation/schema", 82 true); 83 84 } catch (SAXNotRecognizedException e) { 86 logger.error("unrecognised feature: "); 87 logger.error("http://xml.org/sax/features/validation"); 88 } catch (SAXNotSupportedException e) { 89 logger.error("unrecognised feature: "); 90 logger.error("http://apache.org/xml/features/validation/schema"); 91 } 92 } 93 } 94 95 public void read() throws java.io.IOException { 97 try { 98 parser.parse(inputSource); 101 } catch (org.xml.sax.SAXException e) { 102 e.printStackTrace(); 103 throw new java.io.IOException (e.toString()); 104 } 105 } 106 } 107 | Popular Tags |