1 16 package org.apache.cocoon.xml; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.xml.sax.Attributes ; 20 import org.xml.sax.Locator ; 21 import org.xml.sax.SAXException ; 22 import org.xml.sax.ContentHandler ; 23 24 30 public class LoggingContentHandler extends AbstractLogEnabled implements ContentHandler { 31 32 35 String id; 36 37 38 ContentHandler contentHandler; 39 40 44 public LoggingContentHandler(String id, ContentHandler contentHandler) { 45 this.id = id; 46 this.contentHandler = contentHandler; 47 } 48 49 public void setDocumentLocator(Locator locator) { 50 log("setDocumentLocator", ""); 51 contentHandler.setDocumentLocator(locator); 52 } 53 54 public void startDocument() throws SAXException { 55 log("startDocument", ""); 56 this.contentHandler.startDocument(); 57 } 58 59 public void endDocument() throws SAXException { 60 log ("endDocument", ""); 61 this.contentHandler.endDocument(); 62 } 63 64 public void startPrefixMapping(String prefix, String uri) throws SAXException { 65 log ("startPrefixMapping", "prefix="+prefix+",uri="+uri); 66 this.contentHandler.startPrefixMapping(prefix,uri); 67 } 68 69 public void endPrefixMapping(String prefix) throws SAXException { 70 log ("endPrefixMapping", "prefix="+prefix); 71 this.contentHandler.endPrefixMapping(prefix); 72 } 73 74 public void startElement(String uri, String loc, String raw, Attributes a) 75 throws SAXException { 76 log ("startElement", "uri="+uri+",local="+loc+",raw="+raw); 77 for (int i = 0; i < a.getLength(); i++) { 78 log (" ", Integer.toString(i + 1) 79 + ". uri=" + a.getURI(i) 80 + ",local=" + a.getLocalName(i) 81 + ",qname=" + a.getQName(i) 82 + ",type=" + a.getType(i) 83 + ",value=" + a.getValue(i)); 84 } 85 this.contentHandler.startElement(uri,loc,raw,a); 86 } 87 88 89 public void endElement(String uri, String loc, String qname) throws SAXException { 90 log ("endElement", "uri="+uri+",local="+loc+",qname="+qname); 91 this.contentHandler.endElement(uri,loc,qname); 92 } 93 94 public void characters(char ch[], int start, int len) throws SAXException { 95 log ("characters", new String (ch,start,len)); 96 this.contentHandler.characters(ch,start,len); 97 } 98 99 public void ignorableWhitespace(char ch[], int start, int len) throws SAXException { 100 log ("ignorableWhitespace", new String (ch,start,len)); 101 this.contentHandler.ignorableWhitespace(ch,start,len); 102 } 103 104 public void processingInstruction(String target, String data) throws SAXException { 105 log ("processingInstruction", "target="+target+",data="+data); 106 this.contentHandler.processingInstruction(target,data); 107 } 108 109 public void skippedEntity(String name) throws SAXException { 110 log ("skippedEntity", "name="+name); 111 this.contentHandler.skippedEntity(name); 112 } 113 114 private void log(String location, String description) { 115 StringBuffer logEntry = new StringBuffer (); 116 logEntry.append(id); 117 logEntry.append("["); 118 logEntry.append(location); 119 logEntry.append("] "); 120 logEntry.append(description); 121 logEntry.append("\n"); 122 getLogger().debug(logEntry.toString()); 123 } 125 } 126 | Popular Tags |