1 package org.mr.core.util.xml.sax; 2 3 import org.xml.sax.*; 4 import org.xml.sax.ext.DeclHandler ; 5 import org.xml.sax.ext.LexicalHandler ; 6 7 import java.io.IOException ; 8 import java.io.Serializable ; 9 10 55 56 63 public class FilterContentHandler 64 implements ContentHandler, EntityResolver, DTDHandler, ErrorHandler, LexicalHandler , DeclHandler , Serializable { 65 66 private static final SinkContentHandler SINK_HANDLER = new SinkContentHandler(); 67 68 private final ContentHandler m_handler; 69 private final DTDHandler m_dtdHandler; 70 private final ErrorHandler m_errorHandler; 71 private final EntityResolver m_entityResolver; 72 private final LexicalHandler m_lexicalHandler; 73 private final DeclHandler m_declHandler; 74 75 81 public static ContentHandler ensureFullHandler(ContentHandler i_handler) { 82 if (i_handler instanceof DTDHandler && i_handler instanceof ErrorHandler && 83 i_handler instanceof EntityResolver && i_handler instanceof LexicalHandler && 84 i_handler instanceof DeclHandler ) { 85 return i_handler; 86 } 87 return new FilterContentHandler(i_handler); 88 } 89 90 public ContentHandler getContentHandler() { 91 return m_handler; 92 } 93 94 public FilterContentHandler(ContentHandler i_handler) { 95 m_handler = i_handler; 96 m_dtdHandler = (i_handler instanceof DTDHandler)? (DTDHandler)i_handler : SINK_HANDLER; 97 m_errorHandler = (i_handler instanceof ErrorHandler)? (ErrorHandler)i_handler : SINK_HANDLER; 98 m_entityResolver = (i_handler instanceof EntityResolver)? (EntityResolver)i_handler : SINK_HANDLER; 99 m_lexicalHandler = (i_handler instanceof LexicalHandler )? (LexicalHandler )i_handler : SINK_HANDLER; 100 m_declHandler = (i_handler instanceof DeclHandler )? (DeclHandler )i_handler : SINK_HANDLER; 101 } 102 103 public void setDocumentLocator(Locator i_locator) { 104 m_handler.setDocumentLocator(i_locator); 105 } 106 107 public void startDocument() throws SAXException { 108 m_handler.startDocument(); 109 } 110 111 public void endDocument() throws SAXException { 112 m_handler.endDocument(); 113 } 114 115 public void startPrefixMapping(String i_prefix, String i_uri) throws SAXException { 116 m_handler.startPrefixMapping(i_prefix, i_uri); 117 } 118 119 public void endPrefixMapping(String i_prefix) throws SAXException { 120 m_handler.endPrefixMapping(i_prefix); 121 } 122 123 public void startElement(String i_namespaceURI, String i_localName, String i_qName, Attributes i_atts) throws SAXException { 124 m_handler.startElement(i_namespaceURI, i_localName, i_qName, i_atts); 125 } 126 127 public void endElement(String i_namespaceURI, String i_localName, String i_qName) throws SAXException { 128 m_handler.endElement(i_namespaceURI, i_localName, i_qName); 129 } 130 131 public void ignorableWhitespace(char[] i_chars, int i_start, int i_length) throws SAXException { 132 m_handler.ignorableWhitespace(i_chars, i_start, i_length); 133 } 134 135 public void processingInstruction(String i_target, String i_data) throws SAXException { 136 m_handler.processingInstruction(i_target, i_data); 137 } 138 139 public void skippedEntity(String i_name) throws SAXException { 140 m_handler.skippedEntity(i_name); 141 } 142 143 public void characters(char[] i_chars, int i_start, int i_length) throws SAXException { 144 m_handler.characters(i_chars, i_start, i_length); 145 } 146 147 public void notationDecl(String s, String s1, String s2) throws SAXException { 148 m_dtdHandler.notationDecl(s, s1, s2); 149 } 150 151 public void unparsedEntityDecl(String s, String s1, String s2, String s3) throws SAXException { 152 m_dtdHandler.unparsedEntityDecl(s, s1, s2, s3); 153 } 154 155 public void warning(SAXParseException e) throws SAXException { 156 m_errorHandler.warning(e); 157 } 158 159 public void error(SAXParseException e) throws SAXException { 160 m_errorHandler.error(e); 161 } 162 163 public void fatalError(SAXParseException e) throws SAXException { 164 m_errorHandler.fatalError(e); 165 } 166 167 public InputSource resolveEntity(String s, String s1) throws SAXException, IOException { 168 return m_entityResolver.resolveEntity(s, s1); 169 } 170 171 public void startDTD(String s, String s1, String s2) throws SAXException { 172 m_lexicalHandler.startDTD(s, s1, s2); 173 } 174 175 public void endDTD() throws SAXException { 176 m_lexicalHandler.endDTD(); 177 } 178 179 public void startEntity(String s) throws SAXException { 180 m_lexicalHandler.startEntity(s); 181 } 182 183 public void endEntity(String s) throws SAXException { 184 m_lexicalHandler.endEntity(s); 185 } 186 187 public void startCDATA() throws SAXException { 188 m_lexicalHandler.startCDATA(); 189 } 190 191 public void endCDATA() throws SAXException { 192 m_lexicalHandler.endCDATA(); 193 } 194 195 public void comment(char[] i_chars, int i, int i1) throws SAXException { 196 m_lexicalHandler.comment(i_chars, i, i1); 197 } 198 199 public void elementDecl(String s, String s1) throws SAXException { 200 m_declHandler.elementDecl(s, s1); 201 } 202 203 public void attributeDecl(String s, String s1, String s2, String s3, String s4) throws SAXException { 204 m_declHandler.attributeDecl(s, s1, s2, s3, s4); 205 } 206 207 public void internalEntityDecl(String s, String s1) throws SAXException { 208 m_declHandler.internalEntityDecl(s, s1); 209 } 210 211 public void externalEntityDecl(String s, String s1, String s2) throws SAXException { 212 m_declHandler.externalEntityDecl(s, s1, s2); 213 } 214 } 215 | Popular Tags |