Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
XmlReaderException |
|
| 1.0;1 |
1 | package org.codehaus.plexus.util.xml; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.InputStream; | |
23 | import java.io.IOException; | |
24 | ||
25 | /** | |
26 | * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be determined | |
27 | * 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 alternate processing with the | |
30 | * stream. Note that the original InputStream given to the XmlReader cannot be used as that one has been already read. | |
31 | * <p> | |
32 | * | |
33 | * @author Alejandro Abdelnur | |
34 | * @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) | |
35 | * @deprecated TO BE REMOVED from here when plexus-utils is upgraded to 1.4.5+ (and prerequisite upgraded to Maven 2.0.6) | |
36 | */ | |
37 | public class XmlReaderException extends IOException | |
38 | { | |
39 | private String _bomEncoding; | |
40 | ||
41 | private String _xmlGuessEncoding; | |
42 | ||
43 | private String _xmlEncoding; | |
44 | ||
45 | private String _contentTypeMime; | |
46 | ||
47 | private String _contentTypeEncoding; | |
48 | ||
49 | private InputStream _is; | |
50 | ||
51 | /** | |
52 | * Creates an exception instance if the charset encoding could not be determined. | |
53 | * <p> | |
54 | * Instances of this exception are thrown by the XmlReader. | |
55 | * <p> | |
56 | * | |
57 | * @param msg | |
58 | * message describing the reason for the exception. | |
59 | * @param bomEnc | |
60 | * BOM encoding. | |
61 | * @param xmlGuessEnc | |
62 | * XML guess encoding. | |
63 | * @param xmlEnc | |
64 | * XML prolog encoding. | |
65 | * @param is | |
66 | * the unconsumed InputStream. | |
67 | * | |
68 | */ | |
69 | public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) | |
70 | { | |
71 | 0 | this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is ); |
72 | 0 | } |
73 | ||
74 | /** | |
75 | * Creates an exception instance if the charset encoding could not be determined. | |
76 | * <p> | |
77 | * Instances of this exception are thrown by the XmlReader. | |
78 | * <p> | |
79 | * | |
80 | * @param msg | |
81 | * message describing the reason for the exception. | |
82 | * @param ctMime | |
83 | * MIME type in the content-type. | |
84 | * @param ctEnc | |
85 | * encoding in the content-type. | |
86 | * @param bomEnc | |
87 | * BOM encoding. | |
88 | * @param xmlGuessEnc | |
89 | * XML guess encoding. | |
90 | * @param xmlEnc | |
91 | * XML prolog encoding. | |
92 | * @param is | |
93 | * the unconsumed InputStream. | |
94 | * | |
95 | */ | |
96 | public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, | |
97 | String xmlEnc, InputStream is ) | |
98 | { | |
99 | 0 | super( msg ); |
100 | 0 | _contentTypeMime = ctMime; |
101 | 0 | _contentTypeEncoding = ctEnc; |
102 | 0 | _bomEncoding = bomEnc; |
103 | 0 | _xmlGuessEncoding = xmlGuessEnc; |
104 | 0 | _xmlEncoding = xmlEnc; |
105 | 0 | _is = is; |
106 | 0 | } |
107 | ||
108 | /** | |
109 | * Returns the BOM encoding found in the InputStream. | |
110 | * <p> | |
111 | * | |
112 | * @return the BOM encoding, null if none. | |
113 | * | |
114 | */ | |
115 | public String getBomEncoding() | |
116 | { | |
117 | 0 | return _bomEncoding; |
118 | } | |
119 | ||
120 | /** | |
121 | * Returns the encoding guess based on the first bytes of the InputStream. | |
122 | * <p> | |
123 | * | |
124 | * @return the encoding guess, null if it couldn't be guessed. | |
125 | * | |
126 | */ | |
127 | public String getXmlGuessEncoding() | |
128 | { | |
129 | 0 | return _xmlGuessEncoding; |
130 | } | |
131 | ||
132 | /** | |
133 | * Returns the encoding found in the XML prolog of the InputStream. | |
134 | * <p> | |
135 | * | |
136 | * @return the encoding of the XML prolog, null if none. | |
137 | * | |
138 | */ | |
139 | public String getXmlEncoding() | |
140 | { | |
141 | 0 | return _xmlEncoding; |
142 | } | |
143 | ||
144 | /** | |
145 | * Returns the MIME type in the content-type used to attempt determining the encoding. | |
146 | * <p> | |
147 | * | |
148 | * @return the MIME type in the content-type, null if there was not content-type or the encoding detection did not | |
149 | * involve HTTP. | |
150 | * | |
151 | */ | |
152 | public String getContentTypeMime() | |
153 | { | |
154 | 0 | return _contentTypeMime; |
155 | } | |
156 | ||
157 | /** | |
158 | * Returns the encoding in the content-type used to attempt determining the encoding. | |
159 | * <p> | |
160 | * | |
161 | * @return the encoding in the content-type, null if there was not content-type, no encoding in it or the encoding | |
162 | * detection did not involve HTTP. | |
163 | * | |
164 | */ | |
165 | public String getContentTypeEncoding() | |
166 | { | |
167 | 0 | return _contentTypeEncoding; |
168 | } | |
169 | ||
170 | /** | |
171 | * Returns the unconsumed InputStream to allow the application to do an alternate encoding detection on the | |
172 | * InputStream. | |
173 | * <p> | |
174 | * | |
175 | * @return the unconsumed InputStream. | |
176 | * | |
177 | */ | |
178 | public InputStream getInputStream() | |
179 | { | |
180 | 0 | return _is; |
181 | } | |
182 | } |