001: package com.sun.syndication.io;
002:
003: import java.io.InputStream;
004: import java.io.IOException;
005:
006: /**
007: * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding
008: * can not be determined according to the XML 1.0 specification and RFC 3023.
009: * <p>
010: * The exception returns the unconsumed InputStream to allow the application to do an
011: * alternate processing with the stream. Note that the original InputStream given to the
012: * XmlReader cannot be used as that one has been already read.
013: * <p>
014: *
015: * @author Alejandro Abdelnur
016: *
017: */
018: public class XmlReaderException extends IOException {
019: private String _bomEncoding;
020: private String _xmlGuessEncoding;
021: private String _xmlEncoding;
022: private String _contentTypeMime;
023: private String _contentTypeEncoding;
024: private InputStream _is;
025:
026: /**
027: * Creates an exception instance if the charset encoding could not be determined.
028: * <p>
029: * Instances of this exception are thrown by the XmlReader.
030: * <p>
031: * @param msg message describing the reason for the exception.
032: * @param bomEnc BOM encoding.
033: * @param xmlGuessEnc XML guess encoding.
034: * @param xmlEnc XML prolog encoding.
035: * @param is the unconsumed InputStream.
036: *
037: */
038: public XmlReaderException(String msg, String bomEnc,
039: String xmlGuessEnc, String xmlEnc, InputStream is) {
040: this (msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is);
041: }
042:
043: /**
044: * Creates an exception instance if the charset encoding could not be determined.
045: * <p>
046: * Instances of this exception are thrown by the XmlReader.
047: * <p>
048: * @param msg message describing the reason for the exception.
049: * @param ctMime MIME type in the content-type.
050: * @param ctEnc encoding in the content-type.
051: * @param bomEnc BOM encoding.
052: * @param xmlGuessEnc XML guess encoding.
053: * @param xmlEnc XML prolog encoding.
054: * @param is the unconsumed InputStream.
055: *
056: */
057: public XmlReaderException(String msg, String ctMime, String ctEnc,
058: String bomEnc, String xmlGuessEnc, String xmlEnc,
059: InputStream is) {
060: super (msg);
061: _contentTypeMime = ctMime;
062: _contentTypeEncoding = ctEnc;
063: _bomEncoding = bomEnc;
064: _xmlGuessEncoding = xmlGuessEnc;
065: _xmlEncoding = xmlEnc;
066: _is = is;
067: }
068:
069: /**
070: * Returns the BOM encoding found in the InputStream.
071: * <p>
072: * @return the BOM encoding, null if none.
073: *
074: */
075: public String getBomEncoding() {
076: return _bomEncoding;
077: }
078:
079: /**
080: * Returns the encoding guess based on the first bytes of the InputStream.
081: * <p>
082: * @return the encoding guess, null if it couldn't be guessed.
083: *
084: */
085: public String getXmlGuessEncoding() {
086: return _xmlGuessEncoding;
087: }
088:
089: /**
090: * Returns the encoding found in the XML prolog of the InputStream.
091: * <p>
092: * @return the encoding of the XML prolog, null if none.
093: *
094: */
095: public String getXmlEncoding() {
096: return _xmlEncoding;
097: }
098:
099: /**
100: * Returns the MIME type in the content-type used to attempt determining the encoding.
101: * <p>
102: * @return the MIME type in the content-type, null if there was not content-type or the encoding detection
103: * did not involve HTTP.
104: *
105: */
106: public String getContentTypeMime() {
107: return _contentTypeMime;
108: }
109:
110: /**
111: * Returns the encoding in the content-type used to attempt determining the encoding.
112: * <p>
113: * @return the encoding in the content-type, null if there was not content-type, no encoding in it
114: * or the encoding detection did not involve HTTP.
115: *
116: */
117: public String getContentTypeEncoding() {
118: return _contentTypeEncoding;
119: }
120:
121: /**
122: * Returns the unconsumed InputStream to allow the application to do an alternate
123: * encoding detection on the InputStream.
124: * <p>
125: * @return the unconsumed InputStream.
126: *
127: */
128: public InputStream getInputStream() {
129: return _is;
130: }
131: }
|