1 8 9 package net.sourceforge.chaperon.common; 10 11 import org.apache.commons.logging.Log; 12 13 import org.xml.sax.*; 14 15 19 public class LogContentHandler implements ContentHandler 20 { 21 private ContentHandler handler = null; 22 private Log log = null; 23 24 public LogContentHandler(ContentHandler handler, Log log) 25 { 26 this.handler = handler; 27 this.log = log; 28 } 29 30 public void setLog(Log log) 31 { 32 this.log = log; 33 } 34 35 38 public void setDocumentLocator(Locator locator) 39 { 40 if (log!=null) 41 log.debug("[SAX] DocumentLocator "+locator); 42 43 handler.setDocumentLocator(locator); 44 } 45 46 49 public void startDocument() throws SAXException 50 { 51 if (log!=null) 52 log.debug("[SAX] StartDocument"); 53 54 handler.startDocument(); 55 } 56 57 60 public void endDocument() throws SAXException 61 { 62 if (log!=null) 63 log.debug("[SAX] EndDocument"); 64 65 handler.endDocument(); 66 } 67 68 71 public void characters(char[] c, int start, int len) 72 throws SAXException 73 { 74 if (log!=null) 75 log.debug("[SAX] Characters \""+new String (c, start, len)+"\""); 76 77 handler.characters(c, start, len); 78 } 79 80 83 public void ignorableWhitespace(char[] c, int start, int len) 84 throws SAXException 85 { 86 if (log!=null) 87 log.debug("[SAX] Ignorable Whitespace \""+new String (c, start, len)+"\""); 88 89 handler.ignorableWhitespace(c, start, len); 90 } 91 92 95 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) 96 throws SAXException 97 { 98 if (log!=null) 99 log.debug("[SAX] Start Element "+localName+" Namespace "+namespaceURI); 100 101 handler.startElement(namespaceURI, localName, qName, atts); 102 } 103 104 107 public void endElement(String namespaceURI, String localName, String raw) 108 throws SAXException 109 { 110 if (log!=null) 111 log.debug("[SAX] End Element "+localName+" Namespace "+namespaceURI); 112 113 handler.endElement(namespaceURI, localName, raw); 114 } 115 116 119 public void processingInstruction(String target, String data) 120 throws SAXException 121 { 122 if (log!=null) 123 log.debug("[SAX] Processing Instruction Target "+target+" Data "+data); 124 125 handler.processingInstruction(target, data); 126 } 127 128 131 public void startPrefixMapping(String prefix, String uri) 132 throws SAXException 133 { 134 if (log!=null) 135 log.debug("[SAX] Start Prefix Mapping "+prefix+" Namespace "+uri); 136 137 handler.startPrefixMapping(prefix, uri); 138 } 139 140 143 public void endPrefixMapping(String prefix) throws SAXException 144 { 145 if (log!=null) 146 log.debug("[SAX] Start Prefix Mapping "+prefix); 147 148 handler.endPrefixMapping(prefix); 149 } 150 151 public void skippedEntity(String name) throws SAXException 152 { 153 if (log!=null) 154 log.debug("[SAX] Skipped Entity "+name); 155 156 handler.skippedEntity(name); 157 } 158 } 159 | Popular Tags |