You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/02/02 04:18:04 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/xml LoggingContentHandler.java
vgritsenko 02/02/01 19:18:04
Added: src/java/org/apache/cocoon/xml LoggingContentHandler.java
Log:
logging cohtent handler to debug SAX streams
Revision Changes Path
1.1 xml-cocoon2/src/java/org/apache/cocoon/xml/LoggingContentHandler.java
Index: LoggingContentHandler.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.xml;
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLFilter;
import org.xml.sax.ContentHandler;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
/**
* Logging content handler logs all events going through to the logger.
*
* @author <a href="mailto:vgritsenko@apache.org>Vadim Gritsenko</a>
* @version $Revision: 1.1 $ $Date: 2002/02/02 03:18:04 $
*/
public class LoggingContentHandler extends AbstractLoggable implements ContentHandler {
/**
* All debug messages from this handler are prefixed with this id.
*/
String id;
/** The current <code>ContentHandler</code>. */
ContentHandler contentHandler;
/**
* Creates new <code>LoggingContentHandler</code> with specified
* <code>id</code> and destination <code>contentHandler</code>.
*/
public LoggingContentHandler(String id, ContentHandler contentHandler) {
this.id = id;
this.contentHandler = contentHandler;
}
public void setDocumentLocator(Locator locator) {
log("setDocumentLocator", "");
contentHandler.setDocumentLocator(locator);
}
public void startDocument() throws SAXException {
log("startDocument", "");
this.contentHandler.startDocument();
}
public void endDocument() throws SAXException {
log ("endDocument", "");
this.contentHandler.endDocument();
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
log ("startPrefixMapping", "prefix="+prefix+",uri="+uri);
this.contentHandler.startPrefixMapping(prefix,uri);
}
public void endPrefixMapping(String prefix) throws SAXException {
log ("endPrefixMapping", "prefix="+prefix);
this.contentHandler.endPrefixMapping(prefix);
}
public void startElement(String uri, String loc, String raw, Attributes a)
throws SAXException {
log ("startElement", "uri="+uri+",local="+loc+",raw="+raw);
for (int i = 0; i < a.getLength(); i++) {
log (" ", Integer.toString(i + 1)
+ ". uri=" + a.getURI(i)
+ ",local=" + a.getLocalName(i)
+ ",qname=" + a.getQName(i)
+ ",type=" + a.getType(i)
+ ",value=" + a.getValue(i));
}
this.contentHandler.startElement(uri,loc,raw,a);
}
public void endElement(String uri, String loc, String qname) throws SAXException {
log ("endElement", "uri="+uri+",local="+loc+",qname="+qname);
this.contentHandler.endElement(uri,loc,qname);
}
public void characters(char ch[], int start, int len) throws SAXException {
log ("characters", new String(ch,start,len));
this.contentHandler.characters(ch,start,len);
}
public void ignorableWhitespace(char ch[], int start, int len) throws SAXException {
log ("ignorableWhitespace", new String(ch,start,len));
this.contentHandler.ignorableWhitespace(ch,start,len);
}
public void processingInstruction(String target, String data) throws SAXException {
log ("processingInstruction", "target="+target+",data="+data);
this.contentHandler.processingInstruction(target,data);
}
public void skippedEntity(String name) throws SAXException {
log ("skippedEntity", "name="+name);
this.contentHandler.skippedEntity(name);
}
private void log(String location, String description) {
StringBuffer logEntry = new StringBuffer();
logEntry.append(id);
logEntry.append("[");
logEntry.append(location);
logEntry.append("] ");
logEntry.append(description);
logEntry.append("\n");
getLogger().debug(logEntry.toString());
// System.out.print(logEntry.toString());
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org