1 /* 2 * Copyright 2004 Sun Microsystems, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 package org.codehaus.plexus.util.xml; 18 19 import java.io.InputStream; 20 import java.io.IOException; 21 22 /** 23 * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be determined 24 * according to the XML 1.0 specification and RFC 3023. 25 * <p> 26 * The exception returns the unconsumed InputStream to allow the application to do an alternate processing with the 27 * stream. Note that the original InputStream given to the XmlReader cannot be used as that one has been already read. 28 * <p> 29 * 30 * @author Alejandro Abdelnur 31 * @version revision 1.1 taken on 26/06/2007 from Rome (see 32 * https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) 33 */ 34 public class XmlReaderException 35 extends IOException 36 { 37 private String _bomEncoding; 38 39 private String _xmlGuessEncoding; 40 41 private String _xmlEncoding; 42 43 private String _contentTypeMime; 44 45 private String _contentTypeEncoding; 46 47 private InputStream _is; 48 49 /** 50 * Creates an exception instance if the charset encoding could not be determined. 51 * <p> 52 * Instances of this exception are thrown by the XmlReader. 53 * <p> 54 * 55 * @param msg message describing the reason for the exception. 56 * @param bomEnc BOM encoding. 57 * @param xmlGuessEnc XML guess encoding. 58 * @param xmlEnc XML prolog encoding. 59 * @param is the unconsumed InputStream. 60 */ 61 public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) 62 { 63 this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is ); 64 } 65 66 /** 67 * Creates an exception instance if the charset encoding could not be determined. 68 * <p> 69 * Instances of this exception are thrown by the XmlReader. 70 * <p> 71 * 72 * @param msg message describing the reason for the exception. 73 * @param ctMime MIME type in the content-type. 74 * @param ctEnc encoding in the content-type. 75 * @param bomEnc BOM encoding. 76 * @param xmlGuessEnc XML guess encoding. 77 * @param xmlEnc XML prolog encoding. 78 * @param is the unconsumed InputStream. 79 */ 80 public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, 81 String xmlEnc, InputStream is ) 82 { 83 super( msg ); 84 _contentTypeMime = ctMime; 85 _contentTypeEncoding = ctEnc; 86 _bomEncoding = bomEnc; 87 _xmlGuessEncoding = xmlGuessEnc; 88 _xmlEncoding = xmlEnc; 89 _is = is; 90 } 91 92 /** 93 * Returns the BOM encoding found in the InputStream. 94 * <p> 95 * 96 * @return the BOM encoding, null if none. 97 */ 98 public String getBomEncoding() 99 { 100 return _bomEncoding; 101 } 102 103 /** 104 * Returns the encoding guess based on the first bytes of the InputStream. 105 * <p> 106 * 107 * @return the encoding guess, null if it couldn't be guessed. 108 */ 109 public String getXmlGuessEncoding() 110 { 111 return _xmlGuessEncoding; 112 } 113 114 /** 115 * Returns the encoding found in the XML prolog of the InputStream. 116 * <p> 117 * 118 * @return the encoding of the XML prolog, null if none. 119 */ 120 public String getXmlEncoding() 121 { 122 return _xmlEncoding; 123 } 124 125 /** 126 * Returns the MIME type in the content-type used to attempt determining the encoding. 127 * <p> 128 * 129 * @return the MIME type in the content-type, null if there was not content-type or the encoding detection did not 130 * involve HTTP. 131 */ 132 public String getContentTypeMime() 133 { 134 return _contentTypeMime; 135 } 136 137 /** 138 * Returns the encoding in the content-type used to attempt determining the encoding. 139 * <p> 140 * 141 * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding 142 * detection did not involve HTTP. 143 */ 144 public String getContentTypeEncoding() 145 { 146 return _contentTypeEncoding; 147 } 148 149 /** 150 * Returns the unconsumed InputStream to allow the application to do an alternate encoding detection on the 151 * InputStream. 152 * <p> 153 * 154 * @return the unconsumed InputStream. 155 */ 156 public InputStream getInputStream() 157 { 158 return _is; 159 } 160 }