001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: SAXEventLogger.java,v 1.3 2006/12/12 09:59:30 drmlipp Exp $
021: *
022: * $Log: SAXEventLogger.java,v $
023: * Revision 1.3 2006/12/12 09:59:30 drmlipp
024: * More detailed attribute reporting.
025: *
026: * Revision 1.2 2006/09/29 12:32:11 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.1.1.1 2004/08/18 15:17:35 drmlipp
030: * Update to 1.2
031: *
032: * Revision 1.3 2004/07/02 08:58:01 lipp
033: * Fixed bug in startPrefixMapping.
034: *
035: * Revision 1.2 2004/03/17 16:25:01 lipp
036: * Fixed generated output.
037: *
038: * Revision 1.1 2004/02/18 13:02:12 lipp
039: * Nice debugging helper.
040: *
041: */
042: package de.danet.an.util.sax;
043:
044: import org.xml.sax.Attributes;
045: import org.xml.sax.ContentHandler;
046: import org.xml.sax.Locator;
047: import org.xml.sax.SAXException;
048:
049: /**
050: * This class provides ...
051: *
052: * @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
053: * @version $Revision: 1.3 $
054: */
055:
056: public class SAXEventLogger implements ContentHandler {
057:
058: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
059: .getLog(SAXEventLogger.class);
060:
061: private ContentHandler baseHandler = null;
062:
063: /**
064: * Creates an instance of <code>SAXEventLogger</code>
065: * with all attributes initialized to default values.
066: * @param handler the handler events are forwarded to
067: */
068: public SAXEventLogger(ContentHandler handler) {
069: baseHandler = handler;
070: }
071:
072: // Implementation of org.xml.sax.ContentHandler
073:
074: /**
075: * Describe <code>startDocument</code> method here.
076: *
077: * @exception SAXException if an error occurs
078: */
079: public void startDocument() throws SAXException {
080: logger.info("startDocument");
081: baseHandler.startDocument();
082: }
083:
084: /**
085: * Describe <code>endDocument</code> method here.
086: *
087: * @exception SAXException if an error occurs
088: */
089: public void endDocument() throws SAXException {
090: logger.info("endDocument");
091: baseHandler.endDocument();
092: }
093:
094: /**
095: * Describe <code>startElement</code> method here.
096: *
097: * @param nsUri a <code>String</code> value
098: * @param lname a <code>String</code> value
099: * @param qname a <code>String</code> value
100: * @param attributes an <code>Attributes</code> value
101: * @exception SAXException if an error occurs
102: */
103: public void startElement(String nsUri, String lname, String qname,
104: Attributes attributes) throws SAXException {
105: StringBuffer s = new StringBuffer("startElement: <{" + nsUri
106: + "}" + lname + "|" + qname);
107: for (int i = 0; i < attributes.getLength(); i++) {
108: s.append(" {" + attributes.getURI(i) + "}"
109: + attributes.getLocalName(i) + "|"
110: + attributes.getQName(i) + "="
111: + attributes.getValue(i));
112: }
113: s.append(">");
114: logger.info(s.toString());
115: baseHandler.startElement(nsUri, lname, qname, attributes);
116: }
117:
118: /**
119: * Describe <code>endElement</code> method here.
120: *
121: * @param nsUri a <code>String</code> value
122: * @param lname a <code>String</code> value
123: * @param qname a <code>String</code> value
124: * @exception SAXException if an error occurs
125: */
126: public void endElement(String nsUri, String lname, String qname)
127: throws SAXException {
128: logger.info("endElement: </{" + nsUri + "}" + lname + "|"
129: + qname + ">");
130: baseHandler.endElement(nsUri, lname, qname);
131: }
132:
133: /**
134: * Describe <code>characters</code> method here.
135: *
136: * @param charArray a <code>char[]</code> value
137: * @param start an <code>int</code> value
138: * @param length an <code>int</code> value
139: * @exception SAXException if an error occurs
140: */
141: public void characters(char[] charArray, int start, int length)
142: throws SAXException {
143: StringBuffer s = new StringBuffer("characters: ");
144: for (int i = 0; i < length; i++) {
145: char c = charArray[start + i];
146: if (Character.isLetterOrDigit(c) || c == ' ') {
147: s.append(c);
148: } else {
149: s.append("%x" + Integer.toHexString((int) c));
150: }
151: }
152: logger.info(s.toString());
153: baseHandler.characters(charArray, start, length);
154: }
155:
156: /**
157: * Describe <code>setDocumentLocator</code> method here.
158: *
159: * @param locator a <code>Locator</code> value
160: */
161: public void setDocumentLocator(Locator locator) {
162: baseHandler.setDocumentLocator(locator);
163: }
164:
165: /**
166: * Describe <code>startPrefixMapping</code> method here.
167: *
168: * @param string a <code>String</code> value
169: * @param string1 a <code>String</code> value
170: * @exception SAXException if an error occurs
171: */
172: public void startPrefixMapping(String string, String string1)
173: throws SAXException {
174: logger.info("startPrefixMapping: " + string + "=" + string1);
175: baseHandler.startPrefixMapping(string, string1);
176: }
177:
178: /**
179: * Describe <code>endPrefixMapping</code> method here.
180: *
181: * @param string a <code>String</code> value
182: * @exception SAXException if an error occurs
183: */
184: public void endPrefixMapping(String string) throws SAXException {
185: logger.info("endPrefixMapping: " + string);
186: baseHandler.endPrefixMapping(string);
187: }
188:
189: /**
190: * Describe <code>ignorableWhitespace</code> method here.
191: *
192: * @param charArray a <code>char[]</code> value
193: * @param n an <code>int</code> value
194: * @param n1 an <code>int</code> value
195: * @exception SAXException if an error occurs
196: */
197: public void ignorableWhitespace(char[] charArray, int n, int n1)
198: throws SAXException {
199: logger.info("ignorableWhitespace");
200: baseHandler.ignorableWhitespace(charArray, n, n1);
201: }
202:
203: /**
204: * Describe <code>processingInstruction</code> method here.
205: *
206: * @param string a <code>String</code> value
207: * @param string1 a <code>String</code> value
208: * @exception SAXException if an error occurs
209: */
210: public void processingInstruction(String string, String string1)
211: throws SAXException {
212: logger.info("processingInstruction: " + string + " " + string1);
213: baseHandler.processingInstruction(string, string1);
214: }
215:
216: /**
217: * Describe <code>skippedEntity</code> method here.
218: *
219: * @param string a <code>String</code> value
220: * @exception SAXException if an error occurs
221: */
222: public void skippedEntity(String string) throws SAXException {
223: logger.info("skippedEntity");
224: baseHandler.skippedEntity(string);
225: }
226:
227: }
|