KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > common > LogContentHandler


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.common;
10
11 import org.apache.commons.logging.Log;
12
13 import org.xml.sax.*;
14
15 /**
16  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
17  * @version CVS $Id: LogContentHandler.java,v 1.2 2004/01/08 11:30:52 benedikta Exp $
18  */

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   /**
36    * Receive an object for locating the origin of SAX document events.
37    */

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   /**
47    * Receive notification of the beginning of a document.
48    */

49   public void startDocument() throws SAXException
50   {
51     if (log!=null)
52       log.debug("[SAX] StartDocument");
53
54     handler.startDocument();
55   }
56
57   /**
58    * Receive notification of the end of a document.
59    */

60   public void endDocument() throws SAXException
61   {
62     if (log!=null)
63       log.debug("[SAX] EndDocument");
64
65     handler.endDocument();
66   }
67
68   /**
69    * Receive notification of character data.
70    */

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 JavaDoc(c, start, len)+"\"");
76
77     handler.characters(c, start, len);
78   }
79
80   /**
81    * Receive notification of ignorable whitespace in element content.
82    */

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 JavaDoc(c, start, len)+"\"");
88
89     handler.ignorableWhitespace(c, start, len);
90   }
91
92   /**
93    * Receive notification of the beginning of an element.
94    */

95   public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc 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   /**
105    * Receive notification of the end of an element.
106    */

107   public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc 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   /**
117    * Receive notification of a processing instruction.
118    */

119   public void processingInstruction(String JavaDoc target, String JavaDoc 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   /**
129    * Begin the scope of a prefix-URI Namespace mapping.
130    */

131   public void startPrefixMapping(String JavaDoc prefix, String JavaDoc 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   /**
141    * End the scope of a prefix-URI mapping.
142    */

143   public void endPrefixMapping(String JavaDoc 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 JavaDoc 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