KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > xmlutil > XmlReaderException


1 // This file is copied from the Rome project (https://rome.dev.java.net/),
2
// version 0.5, , which is licensed
3
// under the Apache V2 license (and doesn't include a NOTICE file)
4
/*
5  * Copyright 2004 Sun Microsystems, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */

20 package org.outerj.daisy.xmlutil;
21
22 import java.io.InputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 /**
26  * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding
27  * can not be determined 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
30  * alternate processing with the stream. Note that the original InputStream given to the
31  * XmlReader cannot be used as that one has been already read.
32  * <p>
33  *
34  * @author Alejandro Abdelnur
35  *
36  */

37 public class XmlReaderException extends IOException JavaDoc {
38     private String JavaDoc _bomEncoding;
39     private String JavaDoc _xmlGuessEncoding;
40     private String JavaDoc _xmlEncoding;
41     private String JavaDoc _contentTypeMime;
42     private String JavaDoc _contentTypeEncoding;
43     private InputStream JavaDoc _is;
44
45     /**
46      * Creates an exception instance if the charset encoding could not be determined.
47      * <p>
48      * Instances of this exception are thrown by the XmlReader.
49      * <p>
50      * @param msg message describing the reason for the exception.
51      * @param bomEnc BOM encoding.
52      * @param xmlGuessEnc XML guess encoding.
53      * @param xmlEnc XML prolog encoding.
54      * @param is the unconsumed InputStream.
55      *
56      */

57     public XmlReaderException(String JavaDoc msg,String JavaDoc bomEnc,String JavaDoc xmlGuessEnc,String JavaDoc xmlEnc,InputStream JavaDoc is) {
58         this(msg,null,null,bomEnc,xmlGuessEnc,xmlEnc,is);
59     }
60
61     /**
62      * Creates an exception instance if the charset encoding could not be determined.
63      * <p>
64      * Instances of this exception are thrown by the XmlReader.
65      * <p>
66      * @param msg message describing the reason for the exception.
67      * @param ctMime MIME type in the content-type.
68      * @param ctEnc encoding in the content-type.
69      * @param bomEnc BOM encoding.
70      * @param xmlGuessEnc XML guess encoding.
71      * @param xmlEnc XML prolog encoding.
72      * @param is the unconsumed InputStream.
73      *
74      */

75     public XmlReaderException(String JavaDoc msg,String JavaDoc ctMime,String JavaDoc ctEnc,
76                               String JavaDoc bomEnc,String JavaDoc xmlGuessEnc,String JavaDoc xmlEnc,InputStream JavaDoc is) {
77         super(msg);
78         _contentTypeMime = ctMime;
79         _contentTypeEncoding = ctEnc;
80         _bomEncoding = bomEnc;
81         _xmlGuessEncoding = xmlGuessEnc;
82         _xmlEncoding = xmlEnc;
83         _is = is;
84     }
85
86     /**
87      * Returns the BOM encoding found in the InputStream.
88      * <p>
89      * @return the BOM encoding, null if none.
90      *
91      */

92     public String JavaDoc getBomEncoding() {
93         return _bomEncoding;
94     }
95
96     /**
97      * Returns the encoding guess based on the first bytes of the InputStream.
98      * <p>
99      * @return the encoding guess, null if it couldn't be guessed.
100      *
101      */

102     public String JavaDoc getXmlGuessEncoding() {
103         return _xmlGuessEncoding;
104     }
105
106     /**
107      * Returns the encoding found in the XML prolog of the InputStream.
108      * <p>
109      * @return the encoding of the XML prolog, null if none.
110      *
111      */

112     public String JavaDoc getXmlEncoding() {
113         return _xmlEncoding;
114     }
115
116     /**
117      * Returns the MIME type in the content-type used to attempt determining the encoding.
118      * <p>
119      * @return the MIME type in the content-type, null if there was not content-type or the encoding detection
120      * did not involve HTTP.
121      *
122      */

123     public String JavaDoc getContentTypeMime() {
124         return _contentTypeMime;
125     }
126
127     /**
128      * Returns the encoding in the content-type used to attempt determining the encoding.
129      * <p>
130      * @return the encoding in the content-type, null if there was not content-type, no encoding in it
131      * or the encoding detection did not involve HTTP.
132      *
133      */

134     public String JavaDoc getContentTypeEncoding() {
135         return _contentTypeEncoding;
136     }
137
138     /**
139      * Returns the unconsumed InputStream to allow the application to do an alternate
140      * encoding detection on the InputStream.
141      * <p>
142      * @return the unconsumed InputStream.
143      *
144      */

145     public InputStream JavaDoc getInputStream() {
146         return _is;
147     }
148 }
149
150
Popular Tags