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 fi.iki.hsivonen.xml.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,v 1.4 2006/12/01 12:34:31 hsivonen Exp $
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 fi.iki.hsivonen.xml.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 fi.iki.hsivonen.xml.checker.Checker#endDocument()
057         */
058        @Override
059        public void endDocument() throws SAXException {
060            warn("EndDocument.");
061        }
062    
063        /**
064         * @see fi.iki.hsivonen.xml.checker.Checker#endElement(java.lang.String, java.lang.String, java.lang.String)
065         */
066        @Override
067        public void endElement(String uri, String localName, String qName) throws SAXException {
068            warn("EndElement: \u201C" + localName + "\u201D from namespace \u201C" + uri + "\u201D.");
069        }
070    
071        /**
072         * @see fi.iki.hsivonen.xml.checker.Checker#endPrefixMapping(java.lang.String)
073         */
074        @Override
075        public void endPrefixMapping(String prefix) throws SAXException {
076            warn("EndPrefixMapping: \u201C" + prefix + "\u201D.");        
077        }
078    
079        /**
080         * @see fi.iki.hsivonen.xml.checker.Checker#processingInstruction(java.lang.String, java.lang.String)
081         */
082        @Override
083        public void processingInstruction(String target, String data) throws SAXException {
084            warn("ProcessingInstruction: \u201C" + target + "\u201D, \u201C" + data + "\u201D.");
085        }
086    
087        /**
088         * @see fi.iki.hsivonen.xml.checker.Checker#skippedEntity(java.lang.String)
089         */
090        @Override
091        public void skippedEntity(String name) throws SAXException {
092            warn("SkippedEntity: \u201C" + name + "\u201D.");
093        }
094    
095        /**
096         * @see fi.iki.hsivonen.xml.checker.Checker#startDocument()
097         */
098        @Override
099        public void startDocument() throws SAXException {
100            warn("StartDocument.");
101        }
102    
103        /**
104         * @see fi.iki.hsivonen.xml.checker.Checker#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
105         */
106        @Override
107        public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
108            warn("StartElement: \u201C" + localName + "\u201D from namespace \u201C" + uri + "\u201D.");
109            int len = atts.getLength();
110            for (int i = 0; i < len; i++) {
111                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.");                       
112            }
113        }
114    
115        /**
116         * @see fi.iki.hsivonen.xml.checker.Checker#startPrefixMapping(java.lang.String, java.lang.String)
117         */
118        @Override
119        public void startPrefixMapping(String prefix, String uri) throws SAXException {
120            warn("StartPrefixMapping: \u201C" + prefix + "\u201D, \u201C" + uri + "\u201D.");
121        }
122    
123    }