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