Coverage Report - org.apache.maven.shared.utils.xml.XmlReaderException
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlReaderException
0%
0/16
N/A
1
 
 1  
 package org.apache.maven.shared.utils.xml;
 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.io.IOException;
 23  
 import java.io.InputStream;
 24  
 
 25  
 /**
 26  
  * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be determined
 27  
  * according to the XML 1.0 specification and RFC 3023.
 28  
  * <p/>
 29  
  * The exception returns the unconsumed InputStream to allow the application to do an alternate processing with the
 30  
  * stream. Note that the original InputStream given to the XmlReader cannot be used as that one has been already read.
 31  
  * <p/>
 32  
  *
 33  
  * @author Alejandro Abdelnur
 34  
  * @version revision 1.1 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java)
 35  
  */
 36  
 class XmlReaderException
 37  
     extends IOException
 38  
 {
 39  
     private final String _bomEncoding;
 40  
 
 41  
     private final String _xmlGuessEncoding;
 42  
 
 43  
     private final String _xmlEncoding;
 44  
 
 45  
     private final String _contentTypeMime;
 46  
 
 47  
     private final String _contentTypeEncoding;
 48  
 
 49  
     private final InputStream _is;
 50  
 
 51  
     /**
 52  
      * Creates an exception instance if the charset encoding could not be determined.
 53  
      * <p/>
 54  
      * Instances of this exception are thrown by the XmlReader.
 55  
      * <p/>
 56  
      *
 57  
      * @param msg         message describing the reason for the exception.
 58  
      * @param bomEnc      BOM encoding.
 59  
      * @param xmlGuessEnc XML guess encoding.
 60  
      * @param xmlEnc      XML prolog encoding.
 61  
      * @param is          the unconsumed InputStream.
 62  
      */
 63  
     XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is )
 64  
     {
 65  0
         this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is );
 66  0
     }
 67  
 
 68  
     /**
 69  
      * Creates an exception instance if the charset encoding could not be determined.
 70  
      * <p/>
 71  
      * Instances of this exception are thrown by the XmlReader.
 72  
      * <p/>
 73  
      *
 74  
      * @param msg         message describing the reason for the exception.
 75  
      * @param ctMime      MIME type in the content-type.
 76  
      * @param ctEnc       encoding in the content-type.
 77  
      * @param bomEnc      BOM encoding.
 78  
      * @param xmlGuessEnc XML guess encoding.
 79  
      * @param xmlEnc      XML prolog encoding.
 80  
      * @param is          the unconsumed InputStream.
 81  
      */
 82  
     XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc,
 83  
                                String xmlEnc, InputStream is )
 84  
     {
 85  0
         super( msg );
 86  0
         _contentTypeMime = ctMime;
 87  0
         _contentTypeEncoding = ctEnc;
 88  0
         _bomEncoding = bomEnc;
 89  0
         _xmlGuessEncoding = xmlGuessEnc;
 90  0
         _xmlEncoding = xmlEnc;
 91  0
         _is = is;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * Returns the BOM encoding found in the InputStream.
 96  
      * <p/>
 97  
      *
 98  
      * @return the BOM encoding, null if none.
 99  
      */
 100  
     public String getBomEncoding()
 101  
     {
 102  0
         return _bomEncoding;
 103  
     }
 104  
 
 105  
     /**
 106  
      * Returns the encoding guess based on the first bytes of the InputStream.
 107  
      * <p/>
 108  
      *
 109  
      * @return the encoding guess, null if it couldn't be guessed.
 110  
      */
 111  
     public String getXmlGuessEncoding()
 112  
     {
 113  0
         return _xmlGuessEncoding;
 114  
     }
 115  
 
 116  
     /**
 117  
      * Returns the encoding found in the XML prolog of the InputStream.
 118  
      * <p/>
 119  
      *
 120  
      * @return the encoding of the XML prolog, null if none.
 121  
      */
 122  
     public String getXmlEncoding()
 123  
     {
 124  0
         return _xmlEncoding;
 125  
     }
 126  
 
 127  
     /**
 128  
      * Returns the MIME type in the content-type used to attempt determining the encoding.
 129  
      * <p/>
 130  
      *
 131  
      * @return the MIME type in the content-type, null if there was not content-type or the encoding detection did not
 132  
      *         involve HTTP.
 133  
      */
 134  
     public String getContentTypeMime()
 135  
     {
 136  0
         return _contentTypeMime;
 137  
     }
 138  
 
 139  
     /**
 140  
      * Returns the encoding in the content-type used to attempt determining the encoding.
 141  
      * <p/>
 142  
      *
 143  
      * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding
 144  
      *         detection did not involve HTTP.
 145  
      */
 146  
     public String getContentTypeEncoding()
 147  
     {
 148  0
         return _contentTypeEncoding;
 149  
     }
 150  
 
 151  
     /**
 152  
      * Returns the unconsumed InputStream to allow the application to do an alternate encoding detection on the
 153  
      * InputStream.
 154  
      * <p/>
 155  
      *
 156  
      * @return the unconsumed InputStream.
 157  
      */
 158  
     public InputStream getInputStream()
 159  
     {
 160  0
         return _is;
 161  
     }
 162  
 }