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.IOException; 20 import java.io.InputStream; 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 extends IOException { 35 private String _bomEncoding; 36 37 private String _xmlGuessEncoding; 38 39 private String _xmlEncoding; 40 41 private String _contentTypeMime; 42 43 private String _contentTypeEncoding; 44 45 private InputStream _is; 46 47 /** 48 * Creates an exception instance if the charset encoding could not be determined. 49 * <p> 50 * Instances of this exception are thrown by the XmlReader. 51 * <p> 52 * 53 * @param msg message describing the reason for the exception. 54 * @param bomEnc BOM encoding. 55 * @param xmlGuessEnc XML guess encoding. 56 * @param xmlEnc XML prolog encoding. 57 * @param is the unconsumed InputStream. 58 */ 59 public XmlReaderException(String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) { 60 this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is); 61 } 62 63 /** 64 * Creates an exception instance if the charset encoding could not be determined. 65 * <p> 66 * Instances of this exception are thrown by the XmlReader. 67 * <p> 68 * 69 * @param msg message describing the reason for the exception. 70 * @param ctMime MIME type in the content-type. 71 * @param ctEnc encoding in the content-type. 72 * @param bomEnc BOM encoding. 73 * @param xmlGuessEnc XML guess encoding. 74 * @param xmlEnc XML prolog encoding. 75 * @param is the unconsumed InputStream. 76 */ 77 public XmlReaderException( 78 String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) { 79 super(msg); 80 _contentTypeMime = ctMime; 81 _contentTypeEncoding = ctEnc; 82 _bomEncoding = bomEnc; 83 _xmlGuessEncoding = xmlGuessEnc; 84 _xmlEncoding = xmlEnc; 85 _is = is; 86 } 87 88 /** 89 * Returns the BOM encoding found in the InputStream. 90 * <p> 91 * 92 * @return the BOM encoding, null if none. 93 */ 94 public String getBomEncoding() { 95 return _bomEncoding; 96 } 97 98 /** 99 * Returns the encoding guess based on the first bytes of the InputStream. 100 * <p> 101 * 102 * @return the encoding guess, null if it couldn't be guessed. 103 */ 104 public String getXmlGuessEncoding() { 105 return _xmlGuessEncoding; 106 } 107 108 /** 109 * Returns the encoding found in the XML prolog of the InputStream. 110 * <p> 111 * 112 * @return the encoding of the XML prolog, null if none. 113 */ 114 public String getXmlEncoding() { 115 return _xmlEncoding; 116 } 117 118 /** 119 * Returns the MIME type in the content-type used to attempt determining the encoding. 120 * <p> 121 * 122 * @return the MIME type in the content-type, null if there was not content-type or the encoding detection did not 123 * involve HTTP. 124 */ 125 public String getContentTypeMime() { 126 return _contentTypeMime; 127 } 128 129 /** 130 * Returns the encoding in the content-type used to attempt determining the encoding. 131 * <p> 132 * 133 * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding 134 * detection did not involve HTTP. 135 */ 136 public String getContentTypeEncoding() { 137 return _contentTypeEncoding; 138 } 139 140 /** 141 * Returns the unconsumed InputStream to allow the application to do an alternate encoding detection on the 142 * InputStream. 143 * <p> 144 * 145 * @return the unconsumed InputStream. 146 */ 147 public InputStream getInputStream() { 148 return _is; 149 } 150 }