Coverage Report - org.apache.maven.plugin.changes.schema.XmlValidationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlValidationHandler
48%
15/31
50%
2/4
1,308
 
 1  
 package org.apache.maven.plugin.changes.schema;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *    http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.xml.sax.Attributes;
 26  
 import org.xml.sax.SAXException;
 27  
 import org.xml.sax.SAXParseException;
 28  
 import org.xml.sax.helpers.DefaultHandler;
 29  
 
 30  
 /**
 31  
  * @author <a href="mailto:olamy@apache.org">olamy</a>
 32  
  * @since 28 juil. 2008
 33  
  * @version $Id: org.apache.maven.plugin.changes.schema.XmlValidationHandler.html 816592 2012-05-08 12:40:21Z hboutemy $
 34  
  */
 35  
 public class XmlValidationHandler
 36  
     extends DefaultHandler
 37  
 {
 38  
    
 39  3
     private boolean parsingError = false;
 40  
 
 41  3
     private List /* SAXParseException */errors = new ArrayList();
 42  
 
 43  3
     private List /* SAXParseException */fatalErrors = new ArrayList();
 44  
 
 45  3
     private List /* SAXParseException */warnings = new ArrayList();
 46  
 
 47  
     private boolean failOnValidationError;
 48  
 
 49  
     /**
 50  
      * see name
 51  
      */
 52  
     public XmlValidationHandler( boolean failOnValidationError )
 53  3
     {
 54  3
         this.failOnValidationError = failOnValidationError;
 55  3
     }
 56  
 
 57  
     /**
 58  
      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
 59  
      */
 60  
     public void error( SAXParseException excp )
 61  
         throws SAXException
 62  
     {
 63  2
         this.setErrorParsing( true );
 64  2
         this.errors.add( excp );
 65  2
         if ( this.failOnValidationError )
 66  
         {
 67  1
             throw new SAXException( excp.getMessage(), excp );
 68  
         }
 69  1
     }
 70  
 
 71  
     /**
 72  
      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
 73  
      */
 74  
     public void fatalError( SAXParseException excp )
 75  
         throws SAXException
 76  
     {
 77  0
         this.fatalErrors.add( excp );
 78  0
         if ( this.failOnValidationError )
 79  
         {
 80  0
             throw new SAXException( excp.getMessage(), excp );
 81  
         }
 82  0
     }
 83  
 
 84  
     /**
 85  
      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
 86  
      */
 87  
     public void warning( SAXParseException excp )
 88  
         throws SAXException
 89  
     {
 90  0
         this.warnings.add( excp );
 91  0
     }
 92  
 
 93  
     /**
 94  
      * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
 95  
      */
 96  
     public void startElement( String uri, String localName, String qName, Attributes attributes )
 97  
         throws SAXException
 98  
     {
 99  
         // nothing
 100  0
     }
 101  
 
 102  
     /**
 103  
      * @return Returns the errorParsing.
 104  
      */
 105  
     public boolean isErrorParsing()
 106  
     {
 107  0
         return this.parsingError;
 108  
     }
 109  
 
 110  
     /**
 111  
      * @param error The errorParsing to set.
 112  
      */
 113  
     public void setErrorParsing( boolean error )
 114  
     {
 115  2
         this.parsingError = error;
 116  2
     }
 117  
 
 118  
     public List /* SAXParseException */getErrors()
 119  
     {
 120  3
         return errors;
 121  
     }
 122  
 
 123  
     public void setErrors( List errors )
 124  
     {
 125  0
         this.errors = errors;
 126  0
     }
 127  
 
 128  
     public List /* SAXParseException */getFatalErrors()
 129  
     {
 130  0
         return fatalErrors;
 131  
     }
 132  
 
 133  
     public void setFatalErrors( List fatalErrors )
 134  
     {
 135  0
         this.fatalErrors = fatalErrors;
 136  0
     }
 137  
 
 138  
     public List /* SAXParseException */ getWarnings()
 139  
     {
 140  0
         return warnings;
 141  
     }
 142  
 
 143  
     public void setWarnings( List warnings )
 144  
     {
 145  0
         this.warnings = warnings;
 146  0
     }
 147  
 }