1 // SAX exception class.
2 // http://www.saxproject.org
3 // No warranty; no copyright -- use this as you will.
4 // $Id: SAXParseException.java,v 1.11 2004/04/21 13:05:02 dmegginson Exp $
5 
6 package org.xml.sax;
7 
8 import android.compat.annotation.UnsupportedAppUsage;
9 
10 /**
11  * Encapsulate an XML parse error or warning.
12  *
13  * <blockquote>
14  * <em>This module, both source code and documentation, is in the
15  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
16  * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
17  * for further information.
18  * </blockquote>
19  *
20  * <p>This exception may include information for locating the error
21  * in the original XML document, as if it came from a {@link Locator}
22  * object.  Note that although the application
23  * will receive a SAXParseException as the argument to the handlers
24  * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
25  * the application is not actually required to throw the exception;
26  * instead, it can simply read the information in it and take a
27  * different action.</p>
28  *
29  * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
30  * SAXException}, it inherits the ability to wrap another exception.</p>
31  *
32  * @since SAX 1.0
33  * @author David Megginson
34  * @version 2.0.1 (sax2r2)
35  * @see org.xml.sax.SAXException
36  * @see org.xml.sax.Locator
37  * @see org.xml.sax.ErrorHandler
38  */
39 public class SAXParseException extends SAXException {
40 
41 
42     //////////////////////////////////////////////////////////////////////
43     // Constructors.
44     //////////////////////////////////////////////////////////////////////
45 
46 
47     /**
48      * Create a new SAXParseException from a message and a Locator.
49      *
50      * <p>This constructor is especially useful when an application is
51      * creating its own exception from within a {@link org.xml.sax.ContentHandler
52      * ContentHandler} callback.</p>
53      *
54      * @param message The error or warning message.
55      * @param locator The locator object for the error or warning (may be
56      *        null).
57      * @see org.xml.sax.Locator
58      */
SAXParseException(String message, Locator locator)59     public SAXParseException (String message, Locator locator) {
60     super(message);
61     if (locator != null) {
62         init(locator.getPublicId(), locator.getSystemId(),
63          locator.getLineNumber(), locator.getColumnNumber());
64     } else {
65         init(null, null, -1, -1);
66     }
67     }
68 
69 
70     /**
71      * Wrap an existing exception in a SAXParseException.
72      *
73      * <p>This constructor is especially useful when an application is
74      * creating its own exception from within a {@link org.xml.sax.ContentHandler
75      * ContentHandler} callback, and needs to wrap an existing exception that is not a
76      * subclass of {@link org.xml.sax.SAXException SAXException}.</p>
77      *
78      * @param message The error or warning message, or null to
79      *                use the message from the embedded exception.
80      * @param locator The locator object for the error or warning (may be
81      *        null).
82      * @param e Any exception.
83      * @see org.xml.sax.Locator
84      */
SAXParseException(String message, Locator locator, Exception e)85     public SAXParseException (String message, Locator locator,
86                   Exception e) {
87     super(message, e);
88     if (locator != null) {
89         init(locator.getPublicId(), locator.getSystemId(),
90          locator.getLineNumber(), locator.getColumnNumber());
91     } else {
92         init(null, null, -1, -1);
93     }
94     }
95 
96 
97     /**
98      * Create a new SAXParseException.
99      *
100      * <p>This constructor is most useful for parser writers.</p>
101      *
102      * <p>All parameters except the message are as if
103      * they were provided by a {@link Locator}.  For example, if the
104      * system identifier is a URL (including relative filename), the
105      * caller must resolve it fully before creating the exception.</p>
106      *
107      *
108      * @param message The error or warning message.
109      * @param publicId The public identifier of the entity that generated
110      *                 the error or warning.
111      * @param systemId The system identifier of the entity that generated
112      *                 the error or warning.
113      * @param lineNumber The line number of the end of the text that
114      *                   caused the error or warning.
115      * @param columnNumber The column number of the end of the text that
116      *                     cause the error or warning.
117      */
SAXParseException(String message, String publicId, String systemId, int lineNumber, int columnNumber)118     public SAXParseException (String message, String publicId, String systemId,
119                   int lineNumber, int columnNumber)
120     {
121     super(message);
122     init(publicId, systemId, lineNumber, columnNumber);
123     }
124 
125 
126     /**
127      * Create a new SAXParseException with an embedded exception.
128      *
129      * <p>This constructor is most useful for parser writers who
130      * need to wrap an exception that is not a subclass of
131      * {@link org.xml.sax.SAXException SAXException}.</p>
132      *
133      * <p>All parameters except the message and exception are as if
134      * they were provided by a {@link Locator}.  For example, if the
135      * system identifier is a URL (including relative filename), the
136      * caller must resolve it fully before creating the exception.</p>
137      *
138      * @param message The error or warning message, or null to use
139      *                the message from the embedded exception.
140      * @param publicId The public identifier of the entity that generated
141      *                 the error or warning.
142      * @param systemId The system identifier of the entity that generated
143      *                 the error or warning.
144      * @param lineNumber The line number of the end of the text that
145      *                   caused the error or warning.
146      * @param columnNumber The column number of the end of the text that
147      *                     cause the error or warning.
148      * @param e Another exception to embed in this one.
149      */
SAXParseException(String message, String publicId, String systemId, int lineNumber, int columnNumber, Exception e)150     public SAXParseException (String message, String publicId, String systemId,
151                   int lineNumber, int columnNumber, Exception e)
152     {
153     super(message, e);
154     init(publicId, systemId, lineNumber, columnNumber);
155     }
156 
157 
158     /**
159      * Internal initialization method.
160      *
161      * @param publicId The public identifier of the entity which generated the exception,
162      *        or null.
163      * @param systemId The system identifier of the entity which generated the exception,
164      *        or null.
165      * @param lineNumber The line number of the error, or -1.
166      * @param columnNumber The column number of the error, or -1.
167      */
168     @UnsupportedAppUsage
init(String publicId, String systemId, int lineNumber, int columnNumber)169     private void init (String publicId, String systemId,
170                int lineNumber, int columnNumber)
171     {
172     this.publicId = publicId;
173     this.systemId = systemId;
174     this.lineNumber = lineNumber;
175     this.columnNumber = columnNumber;
176     }
177 
178 
179     /**
180      * Get the public identifier of the entity where the exception occurred.
181      *
182      * @return A string containing the public identifier, or null
183      *         if none is available.
184      * @see org.xml.sax.Locator#getPublicId
185      */
getPublicId()186     public String getPublicId ()
187     {
188     return this.publicId;
189     }
190 
191 
192     /**
193      * Get the system identifier of the entity where the exception occurred.
194      *
195      * <p>If the system identifier is a URL, it will have been resolved
196      * fully.</p>
197      *
198      * @return A string containing the system identifier, or null
199      *         if none is available.
200      * @see org.xml.sax.Locator#getSystemId
201      */
getSystemId()202     public String getSystemId ()
203     {
204     return this.systemId;
205     }
206 
207 
208     /**
209      * The line number of the end of the text where the exception occurred.
210      *
211      * <p>The first line is line 1.</p>
212      *
213      * @return An integer representing the line number, or -1
214      *         if none is available.
215      * @see org.xml.sax.Locator#getLineNumber
216      */
getLineNumber()217     public int getLineNumber ()
218     {
219     return this.lineNumber;
220     }
221 
222 
223     /**
224      * The column number of the end of the text where the exception occurred.
225      *
226      * <p>The first column in a line is position 1.</p>
227      *
228      * @return An integer representing the column number, or -1
229      *         if none is available.
230      * @see org.xml.sax.Locator#getColumnNumber
231      */
getColumnNumber()232     public int getColumnNumber ()
233     {
234     return this.columnNumber;
235     }
236 
237 
238     //////////////////////////////////////////////////////////////////////
239     // Internal state.
240     //////////////////////////////////////////////////////////////////////
241 
242 
243     /**
244      * @serial The public identifier, or null.
245      * @see #getPublicId
246      */
247     @UnsupportedAppUsage
248     private String publicId;
249 
250 
251     /**
252      * @serial The system identifier, or null.
253      * @see #getSystemId
254      */
255     @UnsupportedAppUsage
256     private String systemId;
257 
258 
259     /**
260      * @serial The line number, or -1.
261      * @see #getLineNumber
262      */
263     @UnsupportedAppUsage
264     private int lineNumber;
265 
266 
267     /**
268      * @serial The column number, or -1.
269      * @see #getColumnNumber
270      */
271     @UnsupportedAppUsage
272     private int columnNumber;
273 
274 }
275 
276 // end of SAXParseException.java
277