Coverage Report - org.crosswire.common.xml.XMLHandlerAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
XMLHandlerAdapter
0%
0/51
0%
0/4
1.067
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2005 - 2016
 18  
  *
 19  
  */
 20  
 /*
 21  
  * This is based on XMLProcess.
 22  
  * @author Andy Clark, IBM
 23  
  * @author Arnaud Le Hors, IBM
 24  
  *
 25  
  * Copyright 2000-2002,2004,2005 The Apache Software Foundation.
 26  
  *
 27  
  * Licensed under the Apache License, Version 2.0 (the "License");
 28  
  * you may not use this file except in compliance with the License.
 29  
  * You may obtain a copy of the License at
 30  
  *
 31  
  *      http://www.apache.org/licenses/LICENSE-2.0
 32  
  *
 33  
  * Unless required by applicable law or agreed to in writing, software
 34  
  * distributed under the License is distributed on an "AS IS" BASIS,
 35  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 36  
  * See the License for the specific language governing permissions and
 37  
  * limitations under the License.
 38  
  *
 39  
  */
 40  
 package org.crosswire.common.xml;
 41  
 
 42  
 import java.io.IOException;
 43  
 
 44  
 import org.xml.sax.Attributes;
 45  
 import org.xml.sax.ContentHandler;
 46  
 import org.xml.sax.DTDHandler;
 47  
 import org.xml.sax.EntityResolver;
 48  
 import org.xml.sax.ErrorHandler;
 49  
 import org.xml.sax.InputSource;
 50  
 import org.xml.sax.Locator;
 51  
 import org.xml.sax.SAXException;
 52  
 import org.xml.sax.SAXParseException;
 53  
 import org.xml.sax.ext.DeclHandler;
 54  
 import org.xml.sax.ext.LexicalHandler;
 55  
 
 56  
 /**
 57  
  * Checks a XML document for problems, reporting line and offset.
 58  
  * 
 59  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 60  
  * @author DM Smith
 61  
  */
 62  
 public class XMLHandlerAdapter implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler, DeclHandler, LexicalHandler {
 63  
     /**
 64  
      * Default constructor.
 65  
      */
 66  0
     public XMLHandlerAdapter() {
 67  0
     }
 68  
 
 69  
     /* (non-Javadoc)
 70  
      * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
 71  
      */
 72  
     public void setDocumentLocator(Locator locator) {
 73  0
     }
 74  
 
 75  
     /* (non-Javadoc)
 76  
      * @see org.xml.sax.ContentHandler#startDocument()
 77  
      */
 78  
     public void startDocument() throws SAXException {
 79  0
     }
 80  
 
 81  
     /* (non-Javadoc)
 82  
      * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
 83  
      */
 84  
     public void processingInstruction(String target, String data) throws SAXException {
 85  0
     }
 86  
 
 87  
     /* (non-Javadoc)
 88  
      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
 89  
      */
 90  
     public void characters(char[] ch, int offset, int length) throws SAXException {
 91  0
     }
 92  
 
 93  
     /* (non-Javadoc)
 94  
      * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
 95  
      */
 96  
     public void ignorableWhitespace(char[] ch, int offset, int length) throws SAXException {
 97  0
     }
 98  
 
 99  
     /* (non-Javadoc)
 100  
      * @see org.xml.sax.ContentHandler#endDocument()
 101  
      */
 102  
     public void endDocument() throws SAXException {
 103  0
     }
 104  
 
 105  
     /* (non-Javadoc)
 106  
      * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
 107  
      */
 108  
     public void startPrefixMapping(String prefix, String uri) throws SAXException {
 109  0
     }
 110  
 
 111  
     /* (non-Javadoc)
 112  
      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
 113  
      */
 114  
     public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException {
 115  0
     }
 116  
 
 117  
     /* (non-Javadoc)
 118  
      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
 119  
      */
 120  
     public void endElement(String uri, String localName, String qname) throws SAXException {
 121  0
     }
 122  
 
 123  
     /* (non-Javadoc)
 124  
      * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
 125  
      */
 126  
     public void endPrefixMapping(String prefix) throws SAXException {
 127  0
     }
 128  
 
 129  
     /* (non-Javadoc)
 130  
      * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
 131  
      */
 132  
     public void skippedEntity(String name) throws SAXException {
 133  0
     }
 134  
 
 135  
     /* (non-Javadoc)
 136  
      * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)
 137  
      */
 138  
     public void notationDecl(String name, String publicId, String systemId) throws SAXException {
 139  0
     }
 140  
 
 141  
     /* (non-Javadoc)
 142  
      * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 143  
      */
 144  
     public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException {
 145  0
     }
 146  
 
 147  
     /* (non-Javadoc)
 148  
      * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
 149  
      */
 150  
     public void startDTD(String name, String publicId, String systemId) throws SAXException {
 151  0
     }
 152  
 
 153  
     /* (non-Javadoc)
 154  
      * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
 155  
      */
 156  
     public void startEntity(String name) throws SAXException {
 157  0
     }
 158  
 
 159  
     /* (non-Javadoc)
 160  
      * @see org.xml.sax.ext.LexicalHandler#startCDATA()
 161  
      */
 162  
     public void startCDATA() throws SAXException {
 163  0
     }
 164  
 
 165  
     /* (non-Javadoc)
 166  
      * @see org.xml.sax.ext.LexicalHandler#endCDATA()
 167  
      */
 168  
     public void endCDATA() throws SAXException {
 169  0
     }
 170  
 
 171  
     /* (non-Javadoc)
 172  
      * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
 173  
      */
 174  
     public void comment(char[] ch, int offset, int length) throws SAXException {
 175  0
     }
 176  
 
 177  
     /* (non-Javadoc)
 178  
      * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
 179  
      */
 180  
     public void endEntity(String name) throws SAXException {
 181  0
     }
 182  
 
 183  
     /* (non-Javadoc)
 184  
      * @see org.xml.sax.ext.LexicalHandler#endDTD()
 185  
      */
 186  
     public void endDTD() throws SAXException {
 187  0
     }
 188  
 
 189  
     /* (non-Javadoc)
 190  
      * @see org.xml.sax.ext.DeclHandler#elementDecl(java.lang.String, java.lang.String)
 191  
      */
 192  
     public void elementDecl(String name, String contentModel) throws SAXException {
 193  0
     }
 194  
 
 195  
     /* (non-Javadoc)
 196  
      * @see org.xml.sax.ext.DeclHandler#attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 197  
      */
 198  
     public void attributeDecl(String elementName, String attributeName, String type, String valueDefault, String value) throws SAXException {
 199  0
     }
 200  
 
 201  
     /* (non-Javadoc)
 202  
      * @see org.xml.sax.ext.DeclHandler#internalEntityDecl(java.lang.String, java.lang.String)
 203  
      */
 204  
     public void internalEntityDecl(String name, String text) throws SAXException {
 205  0
     }
 206  
 
 207  
     /* (non-Javadoc)
 208  
      * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
 209  
      */
 210  
     public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException {
 211  0
     }
 212  
 
 213  
     /* (non-Javadoc)
 214  
      * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
 215  
      */
 216  
     public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
 217  0
         return null;
 218  
     }
 219  
 
 220  
     /* (non-Javadoc)
 221  
      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
 222  
      */
 223  
     public void warning(SAXParseException ex) throws SAXException {
 224  0
         printError("Warning", ex);
 225  0
     }
 226  
 
 227  
     /* (non-Javadoc)
 228  
      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
 229  
      */
 230  
     public void error(SAXParseException ex) throws SAXException {
 231  0
         printError("Error", ex);
 232  0
     }
 233  
 
 234  
     /* (non-Javadoc)
 235  
      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
 236  
      */
 237  
     public void fatalError(SAXParseException ex) throws SAXException {
 238  0
         printError("Fatal Error", ex);
 239  0
     }
 240  
 
 241  
     /**
 242  
      * Prints the error message.
 243  
      * 
 244  
      * @param type the type of the message
 245  
      * @param ex the exception of the error
 246  
      */
 247  
     private void printError(String type, SAXParseException ex) {
 248  0
         System.err.print("[");
 249  0
         System.err.print(type);
 250  0
         System.err.print("] ");
 251  0
         String systemId = ex.getSystemId();
 252  0
         if (systemId != null) {
 253  0
             int index = systemId.lastIndexOf('/');
 254  0
             if (index != -1) {
 255  0
                 systemId = systemId.substring(index + 1);
 256  
             }
 257  0
             System.err.print(systemId);
 258  
         }
 259  0
         System.err.print(':');
 260  0
         System.err.print(ex.getLineNumber());
 261  0
         System.err.print(':');
 262  0
         System.err.print(ex.getColumnNumber());
 263  0
         System.err.print(": ");
 264  0
         System.err.print(ex.getMessage());
 265  0
         System.err.println();
 266  0
         System.err.flush();
 267  
 
 268  0
     }
 269  
 }