001    /*
002     * Copyright (c) 2006 Henri Sivonen
003     *
004     * Permission is hereby granted, free of charge, to any person obtaining a 
005     * copy of this software and associated documentation files (the "Software"), 
006     * to deal in the Software without restriction, including without limitation 
007     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
008     * and/or sell copies of the Software, and to permit persons to whom the 
009     * Software is furnished to do so, subject to the following conditions:
010     *
011     * The above copyright notice and this permission notice shall be included in 
012     * all copies or substantial portions of the Software.
013     *
014     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
015     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
016     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
017     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
018     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
019     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
020     * DEALINGS IN THE SOFTWARE.
021     */
022    
023    package org.whattf.checker;
024    
025    import org.xml.sax.Attributes;
026    import org.xml.sax.SAXException;
027    
028    /**
029     * Dumps the parse events as warnings.
030     * 
031     * @version $Id: DebugChecker.java 189 2007-10-08 11:27:05Z hsivonen $
032     * @author hsivonen
033     */
034    public final class DebugChecker extends Checker {
035    
036        /**
037         * Contructor.
038         */
039        public DebugChecker() {
040            super();
041        }
042    
043        /**
044         * @see org.whattf.checker.Checker#characters(char[], int, int)
045         */
046        @Override
047        public void characters(char[] ch, int start, int length) throws SAXException {
048            StringBuilder buf = new StringBuilder();
049            buf.append("Characters: \u201C");
050            buf.append(ch, start, length);
051            buf.append("\u201D.");
052            warn(buf.toString());
053        }
054    
055        /**
056         * @see org.whattf.checker.Checker#endDocument()
057         */
058        @Override
059        public void endDocument() throws SAXException {
060        }
061    
062        /**
063         * @see org.whattf.checker.Checker#endElement(java.lang.String, java.lang.String, java.lang.String)
064         */
065        @Override
066        public void endElement(String uri, String localName, String qName) throws SAXException {
067            warn("EndElement: \u201C" + localName + "\u201D from namespace \u201C" + uri + "\u201D.");
068        }
069    
070        /**
071         * @see org.whattf.checker.Checker#endPrefixMapping(java.lang.String)
072         */
073        @Override
074        public void endPrefixMapping(String prefix) throws SAXException {
075            warn("EndPrefixMapping: \u201C" + prefix + "\u201D.");        
076        }
077    
078        /**
079         * @see org.whattf.checker.Checker#processingInstruction(java.lang.String, java.lang.String)
080         */
081        @Override
082        public void processingInstruction(String target, String data) throws SAXException {
083            warn("ProcessingInstruction: \u201C" + target + "\u201D, \u201C" + data + "\u201D.");
084        }
085    
086        /**
087         * @see org.whattf.checker.Checker#skippedEntity(java.lang.String)
088         */
089        @Override
090        public void skippedEntity(String name) throws SAXException {
091            warn("SkippedEntity: \u201C" + name + "\u201D.");
092        }
093    
094        /**
095         * @see org.whattf.checker.Checker#startDocument()
096         */
097        @Override
098        public void startDocument() throws SAXException {
099        }
100    
101        /**
102         * @see org.whattf.checker.Checker#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
103         */
104        @Override
105        public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
106            warn("StartElement: \u201C" + localName + "\u201D from namespace \u201C" + uri + "\u201D.");
107            int len = atts.getLength();
108            for (int i = 0; i < len; i++) {
109                warn("Attribute: \u201C" + atts.getLocalName(i) + "\u201D" + ("".equals(atts.getURI(i)) ? "" : "from namespace \u201C" + atts.getURI(i) + "\u201D") + " has value: \u201C" + atts.getValue(i) + "\u201D.");                       
110            }
111        }
112    
113        /**
114         * @see org.whattf.checker.Checker#startPrefixMapping(java.lang.String, java.lang.String)
115         */
116        @Override
117        public void startPrefixMapping(String prefix, String uri) throws SAXException {
118            warn("StartPrefixMapping: \u201C" + prefix + "\u201D, \u201C" + uri + "\u201D.");
119        }
120    
121    }