001: /*
002: * Copyright (C) Chaperon. All rights reserved.
003: * -------------------------------------------------------------------------
004: * This software is published under the terms of the Apache Software License
005: * version 1.1, a copy of which has been included with this distribution in
006: * the LICENSE file.
007: */
008:
009: package net.sourceforge.chaperon.common;
010:
011: import org.apache.commons.logging.Log;
012:
013: import org.xml.sax.*;
014:
015: /**
016: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
017: * @version CVS $Id: LogContentHandler.java,v 1.2 2004/01/08 11:30:52 benedikta Exp $
018: */
019: public class LogContentHandler implements ContentHandler {
020: private ContentHandler handler = null;
021: private Log log = null;
022:
023: public LogContentHandler(ContentHandler handler, Log log) {
024: this .handler = handler;
025: this .log = log;
026: }
027:
028: public void setLog(Log log) {
029: this .log = log;
030: }
031:
032: /**
033: * Receive an object for locating the origin of SAX document events.
034: */
035: public void setDocumentLocator(Locator locator) {
036: if (log != null)
037: log.debug("[SAX] DocumentLocator " + locator);
038:
039: handler.setDocumentLocator(locator);
040: }
041:
042: /**
043: * Receive notification of the beginning of a document.
044: */
045: public void startDocument() throws SAXException {
046: if (log != null)
047: log.debug("[SAX] StartDocument");
048:
049: handler.startDocument();
050: }
051:
052: /**
053: * Receive notification of the end of a document.
054: */
055: public void endDocument() throws SAXException {
056: if (log != null)
057: log.debug("[SAX] EndDocument");
058:
059: handler.endDocument();
060: }
061:
062: /**
063: * Receive notification of character data.
064: */
065: public void characters(char[] c, int start, int len)
066: throws SAXException {
067: if (log != null)
068: log.debug("[SAX] Characters \"" + new String(c, start, len)
069: + "\"");
070:
071: handler.characters(c, start, len);
072: }
073:
074: /**
075: * Receive notification of ignorable whitespace in element content.
076: */
077: public void ignorableWhitespace(char[] c, int start, int len)
078: throws SAXException {
079: if (log != null)
080: log.debug("[SAX] Ignorable Whitespace \""
081: + new String(c, start, len) + "\"");
082:
083: handler.ignorableWhitespace(c, start, len);
084: }
085:
086: /**
087: * Receive notification of the beginning of an element.
088: */
089: public void startElement(String namespaceURI, String localName,
090: String qName, Attributes atts) throws SAXException {
091: if (log != null)
092: log.debug("[SAX] Start Element " + localName
093: + " Namespace " + namespaceURI);
094:
095: handler.startElement(namespaceURI, localName, qName, atts);
096: }
097:
098: /**
099: * Receive notification of the end of an element.
100: */
101: public void endElement(String namespaceURI, String localName,
102: String raw) throws SAXException {
103: if (log != null)
104: log.debug("[SAX] End Element " + localName + " Namespace "
105: + namespaceURI);
106:
107: handler.endElement(namespaceURI, localName, raw);
108: }
109:
110: /**
111: * Receive notification of a processing instruction.
112: */
113: public void processingInstruction(String target, String data)
114: throws SAXException {
115: if (log != null)
116: log.debug("[SAX] Processing Instruction Target " + target
117: + " Data " + data);
118:
119: handler.processingInstruction(target, data);
120: }
121:
122: /**
123: * Begin the scope of a prefix-URI Namespace mapping.
124: */
125: public void startPrefixMapping(String prefix, String uri)
126: throws SAXException {
127: if (log != null)
128: log.debug("[SAX] Start Prefix Mapping " + prefix
129: + " Namespace " + uri);
130:
131: handler.startPrefixMapping(prefix, uri);
132: }
133:
134: /**
135: * End the scope of a prefix-URI mapping.
136: */
137: public void endPrefixMapping(String prefix) throws SAXException {
138: if (log != null)
139: log.debug("[SAX] Start Prefix Mapping " + prefix);
140:
141: handler.endPrefixMapping(prefix);
142: }
143:
144: public void skippedEntity(String name) throws SAXException {
145: if (log != null)
146: log.debug("[SAX] Skipped Entity " + name);
147:
148: handler.skippedEntity(name);
149: }
150: }
|