1 package org.codehaus.plexus.util.xml; 2 3 import java.io.InputStream; 4 import java.io.IOException; 5 6 /** 7 * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be determined 8 * according to the XML 1.0 specification and RFC 3023. 9 * <p> 10 * The exception returns the unconsumed InputStream to allow the application to do an alternate processing with the 11 * stream. Note that the original InputStream given to the XmlReader cannot be used as that one has been already read. 12 * <p> 13 * 14 * @author Alejandro Abdelnur 15 * @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) 16 * @deprecated TO BE REMOVED from here when plexus-utils is upgraded to 1.4.5+ (and prerequisite upgraded to Maven 2.0.6) 17 */ 18 public class XmlReaderException extends IOException 19 { 20 private String _bomEncoding; 21 22 private String _xmlGuessEncoding; 23 24 private String _xmlEncoding; 25 26 private String _contentTypeMime; 27 28 private String _contentTypeEncoding; 29 30 private InputStream _is; 31 32 /** 33 * Creates an exception instance if the charset encoding could not be determined. 34 * <p> 35 * Instances of this exception are thrown by the XmlReader. 36 * <p> 37 * 38 * @param msg 39 * message describing the reason for the exception. 40 * @param bomEnc 41 * BOM encoding. 42 * @param xmlGuessEnc 43 * XML guess encoding. 44 * @param xmlEnc 45 * XML prolog encoding. 46 * @param is 47 * the unconsumed InputStream. 48 * 49 */ 50 public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) 51 { 52 this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is ); 53 } 54 55 /** 56 * Creates an exception instance if the charset encoding could not be determined. 57 * <p> 58 * Instances of this exception are thrown by the XmlReader. 59 * <p> 60 * 61 * @param msg 62 * message describing the reason for the exception. 63 * @param ctMime 64 * MIME type in the content-type. 65 * @param ctEnc 66 * encoding in the content-type. 67 * @param bomEnc 68 * BOM encoding. 69 * @param xmlGuessEnc 70 * XML guess encoding. 71 * @param xmlEnc 72 * XML prolog encoding. 73 * @param is 74 * the unconsumed InputStream. 75 * 76 */ 77 public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, 78 String xmlEnc, InputStream is ) 79 { 80 super( msg ); 81 _contentTypeMime = ctMime; 82 _contentTypeEncoding = ctEnc; 83 _bomEncoding = bomEnc; 84 _xmlGuessEncoding = xmlGuessEnc; 85 _xmlEncoding = xmlEnc; 86 _is = is; 87 } 88 89 /** 90 * Returns the BOM encoding found in the InputStream. 91 * <p> 92 * 93 * @return the BOM encoding, null if none. 94 * 95 */ 96 public String getBomEncoding() 97 { 98 return _bomEncoding; 99 } 100 101 /** 102 * Returns the encoding guess based on the first bytes of the InputStream. 103 * <p> 104 * 105 * @return the encoding guess, null if it couldn't be guessed. 106 * 107 */ 108 public String getXmlGuessEncoding() 109 { 110 return _xmlGuessEncoding; 111 } 112 113 /** 114 * Returns the encoding found in the XML prolog of the InputStream. 115 * <p> 116 * 117 * @return the encoding of the XML prolog, null if none. 118 * 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 */ 133 public String getContentTypeMime() 134 { 135 return _contentTypeMime; 136 } 137 138 /** 139 * Returns the encoding in the content-type used to attempt determining the encoding. 140 * <p> 141 * 142 * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding 143 * detection did not involve HTTP. 144 * 145 */ 146 public String getContentTypeEncoding() 147 { 148 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 */ 159 public InputStream getInputStream() 160 { 161 return _is; 162 } 163 }