1 17 package org.apache.excalibur.xml.sax; 18 19 import org.xml.sax.Attributes ; 20 import org.xml.sax.ContentHandler ; 21 import org.xml.sax.Locator ; 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.ext.LexicalHandler ; 24 25 36 public class ContentHandlerWrapper 37 extends AbstractXMLConsumer 38 { 39 40 private ContentHandler m_contentHandler; 41 42 43 private LexicalHandler m_lexicalHandler; 44 45 48 public ContentHandlerWrapper() 49 { 50 } 51 52 55 public ContentHandlerWrapper( final ContentHandler contentHandler ) 56 { 57 setContentHandler( contentHandler ); 58 } 59 60 63 public ContentHandlerWrapper( final ContentHandler contentHandler, 64 final LexicalHandler lexicalHandler ) 65 { 66 setContentHandler( contentHandler ); 67 setLexicalHandler( lexicalHandler ); 68 } 69 70 76 public void setContentHandler( final ContentHandler contentHandler ) 77 throws IllegalStateException 78 { 79 if( null != m_contentHandler ) 80 { 81 throw new IllegalStateException (); 82 } 83 m_contentHandler = contentHandler; 84 } 85 86 92 public void setLexicalHandler( final LexicalHandler lexicalHandler ) 93 throws IllegalStateException 94 { 95 if( null != m_lexicalHandler ) 96 { 97 throw new IllegalStateException (); 98 } 99 m_lexicalHandler = lexicalHandler; 100 } 101 102 105 public void setDocumentLocator( final Locator locator ) 106 { 107 if( null == m_contentHandler ) 108 { 109 return; 110 } 111 else 112 { 113 m_contentHandler.setDocumentLocator( locator ); 114 } 115 } 116 117 120 public void startDocument() 121 throws SAXException 122 { 123 if( null == m_contentHandler ) 124 { 125 final String message = "ContentHandler not set"; 126 throw new SAXException ( message ); 127 } 128 m_contentHandler.startDocument(); 129 } 130 131 134 public void endDocument() 135 throws SAXException 136 { 137 m_contentHandler.endDocument(); 138 } 139 140 143 public void startPrefixMapping( final String prefix, 144 final String uri ) 145 throws SAXException 146 { 147 if( null == m_contentHandler ) 148 { 149 final String message = "ContentHandler not set"; 150 throw new SAXException ( message ); 151 } 152 m_contentHandler.startPrefixMapping( prefix, uri ); 153 } 154 155 158 public void endPrefixMapping( final String prefix ) 159 throws SAXException 160 { 161 m_contentHandler.endPrefixMapping( prefix ); 162 } 163 164 167 public void startElement( final String uri, 168 final String loc, 169 final String raw, 170 final Attributes a ) 171 throws SAXException 172 { 173 m_contentHandler.startElement( uri, loc, raw, a ); 174 } 175 176 179 public void endElement( final String uri, 180 final String loc, 181 final String raw ) 182 throws SAXException 183 { 184 m_contentHandler.endElement( uri, loc, raw ); 185 } 186 187 190 public void characters( final char[] ch, 191 final int start, 192 final int len ) 193 throws SAXException 194 { 195 m_contentHandler.characters( ch, start, len ); 196 } 197 198 201 public void ignorableWhitespace( final char[] ch, 202 final int start, 203 final int len ) 204 throws SAXException 205 { 206 m_contentHandler.ignorableWhitespace( ch, start, len ); 207 } 208 209 212 public void processingInstruction( final String target, 213 final String data ) 214 throws SAXException 215 { 216 m_contentHandler.processingInstruction( target, data ); 217 } 218 219 225 public void skippedEntity( final String name ) 226 throws SAXException 227 { 228 m_contentHandler.skippedEntity( name ); 229 } 230 231 240 public void startDTD( final String name, 241 final String publicId, 242 final String systemId ) 243 throws SAXException 244 { 245 if( null != m_lexicalHandler ) 246 { 247 m_lexicalHandler.startDTD( name, publicId, systemId ); 248 } 249 } 250 251 254 public void endDTD() 255 throws SAXException 256 { 257 if( null != m_lexicalHandler ) 258 { 259 m_lexicalHandler.endDTD(); 260 } 261 } 262 263 269 public void startEntity( final String name ) 270 throws SAXException 271 { 272 if( null != m_lexicalHandler ) 273 { 274 m_lexicalHandler.startEntity( name ); 275 } 276 } 277 278 283 public void endEntity( final String name ) 284 throws SAXException 285 { 286 if( null != m_lexicalHandler ) 287 { 288 m_lexicalHandler.endEntity( name ); 289 } 290 } 291 292 295 public void startCDATA() 296 throws SAXException 297 { 298 if( null != m_lexicalHandler ) 299 { 300 m_lexicalHandler.startCDATA(); 301 } 302 } 303 304 307 public void endCDATA() 308 throws SAXException 309 { 310 if( null != m_lexicalHandler ) 311 { 312 m_lexicalHandler.endCDATA(); 313 } 314 } 315 316 323 public void comment( final char[] ch, 324 final int start, 325 final int len ) 326 throws SAXException 327 { 328 if( null != m_lexicalHandler ) 329 { 330 m_lexicalHandler.comment( ch, start, len ); 331 } 332 } 333 } 334 | Popular Tags |