SAXEventProviderXMLReader.java |
1 /** 2 * Distribution License: 3 * JSword is free software; you can redistribute it and/or modify it under 4 * the terms of the GNU Lesser General Public License, version 2.1 or later 5 * as published by the Free Software Foundation. This program is distributed 6 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 7 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 * See the GNU Lesser General Public License for more details. 9 * 10 * The License is available on the internet at: 11 * http://www.gnu.org/copyleft/lgpl.html 12 * or by writing to: 13 * Free Software Foundation, Inc. 14 * 59 Temple Place - Suite 330 15 * Boston, MA 02111-1307, USA 16 * 17 * © CrossWire Bible Society, 2005 - 2016 18 * 19 */ 20 package org.crosswire.common.xml; 21 22 import org.xml.sax.ContentHandler; 23 import org.xml.sax.DTDHandler; 24 import org.xml.sax.EntityResolver; 25 import org.xml.sax.ErrorHandler; 26 import org.xml.sax.InputSource; 27 import org.xml.sax.SAXException; 28 import org.xml.sax.XMLReader; 29 30 /** 31 * A helper to aid people working with a SAXEventProvider. 32 * 33 * @see gnu.lgpl.License The GNU Lesser General Public License for details. 34 * @author Joe Walker 35 */ 36 /** 37 * 38 * 39 * @see gnu.lgpl.License The GNU Lesser General Public License for details. 40 * @author DM Smith 41 */ 42 /** 43 * 44 * 45 * @see gnu.lgpl.License The GNU Lesser General Public License for details. 46 * @author DM Smith 47 */ 48 public class SAXEventProviderXMLReader implements XMLReader { 49 /** 50 * Constructor SAXEventProviderXMLReader. 51 * 52 * @param docIn the document provided as SAX events 53 */ 54 public SAXEventProviderXMLReader(SAXEventProvider docIn) { 55 this.docIn = docIn; 56 } 57 58 /* (non-Javadoc) 59 * @see org.xml.sax.XMLReader#getFeature(java.lang.String) 60 */ 61 public boolean getFeature(String arg0) { 62 return false; 63 } 64 65 /* (non-Javadoc) 66 * @see org.xml.sax.XMLReader#setFeature(java.lang.String, boolean) 67 */ 68 public void setFeature(String arg0, boolean arg1) { 69 } 70 71 /* (non-Javadoc) 72 * @see org.xml.sax.XMLReader#getProperty(java.lang.String) 73 */ 74 public Object getProperty(String arg0) { 75 return null; 76 } 77 78 /* (non-Javadoc) 79 * @see org.xml.sax.XMLReader#setProperty(java.lang.String, java.lang.Object) 80 */ 81 public void setProperty(String arg0, Object arg1) { 82 } 83 84 /* (non-Javadoc) 85 * @see org.xml.sax.XMLReader#setEntityResolver(org.xml.sax.EntityResolver) 86 */ 87 public void setEntityResolver(EntityResolver entities) { 88 this.entities = entities; 89 } 90 91 /* (non-Javadoc) 92 * @see org.xml.sax.XMLReader#getEntityResolver() 93 */ 94 public EntityResolver getEntityResolver() { 95 return entities; 96 } 97 98 /* (non-Javadoc) 99 * @see org.xml.sax.XMLReader#setDTDHandler(org.xml.sax.DTDHandler) 100 */ 101 public void setDTDHandler(DTDHandler dtds) { 102 this.dtds = dtds; 103 } 104 105 /* (non-Javadoc) 106 * @see org.xml.sax.XMLReader#getDTDHandler() 107 */ 108 public DTDHandler getDTDHandler() { 109 return dtds; 110 } 111 112 /* (non-Javadoc) 113 * @see org.xml.sax.XMLReader#setContentHandler(org.xml.sax.ContentHandler) 114 */ 115 public void setContentHandler(ContentHandler content) { 116 this.content = content; 117 } 118 119 /* (non-Javadoc) 120 * @see org.xml.sax.XMLReader#getContentHandler() 121 */ 122 public ContentHandler getContentHandler() { 123 return content; 124 } 125 126 /* (non-Javadoc) 127 * @see org.xml.sax.XMLReader#setErrorHandler(org.xml.sax.ErrorHandler) 128 */ 129 public void setErrorHandler(ErrorHandler errors) { 130 this.errors = errors; 131 } 132 133 /* (non-Javadoc) 134 * @see org.xml.sax.XMLReader#getErrorHandler() 135 */ 136 public ErrorHandler getErrorHandler() { 137 return errors; 138 } 139 140 /* (non-Javadoc) 141 * @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource) 142 */ 143 public void parse(InputSource is) throws SAXException { 144 if (!(is instanceof SAXEventProviderInputSource)) { 145 throw new SAXException("SAXEventProviderInputSource required"); 146 } 147 148 docIn.provideSAXEvents(getContentHandler()); 149 } 150 151 /* (non-Javadoc) 152 * @see org.xml.sax.XMLReader#parse(java.lang.String) 153 */ 154 public void parse(String arg0) throws SAXException { 155 throw new SAXException("SAXEventProviderInputSource required"); 156 } 157 158 private SAXEventProvider docIn; 159 private ErrorHandler errors; 160 private ContentHandler content; 161 private DTDHandler dtds; 162 private EntityResolver entities; 163 } 164