1 /*
2  * reserved comment block
3  * DO NOT REMOVE OR ALTER!
4  */
5 /*
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 package com.sun.org.apache.xerces.internal.xni.parser;
23 
24 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
25 import com.sun.org.apache.xerces.internal.xni.XNIException;
26 
27 /**
28  * A parsing exception. This exception is different from the standard
29  * XNI exception in that it stores the location in the document (or
30  * its entities) where the exception occurred.
31  *
32  * @author Andy Clark, IBM
33  *
34  */
35 public class XMLParseException
36     extends XNIException {
37 
38     /** Serialization version. */
39     static final long serialVersionUID = 1732959359448549967L;
40 
41     //
42     // Data
43     //
44 
45     /** Public identifier. */
46     protected String fPublicId;
47 
48     /** literal System identifier. */
49     protected String fLiteralSystemId;
50 
51     /** expanded System identifier. */
52     protected String fExpandedSystemId;
53 
54     /** Base system identifier. */
55     protected String fBaseSystemId;
56 
57     /** Line number. */
58     protected int fLineNumber = -1;
59 
60     /** Column number. */
61     protected int fColumnNumber = -1;
62 
63     /** Character offset. */
64     protected int fCharacterOffset = -1;
65 
66     //
67     // Constructors
68     //
69 
70     /** Constructs a parse exception. */
XMLParseException(XMLLocator locator, String message)71     public XMLParseException(XMLLocator locator, String message) {
72         super(message);
73         if (locator != null) {
74             fPublicId = locator.getPublicId();
75             fLiteralSystemId = locator.getLiteralSystemId();
76             fExpandedSystemId = locator.getExpandedSystemId();
77             fBaseSystemId = locator.getBaseSystemId();
78             fLineNumber = locator.getLineNumber();
79             fColumnNumber = locator.getColumnNumber();
80             fCharacterOffset = locator.getCharacterOffset();
81         }
82     } // <init>(XMLLocator,String)
83 
84     /** Constructs a parse exception. */
XMLParseException(XMLLocator locator, String message, Exception exception)85     public XMLParseException(XMLLocator locator,
86                              String message, Exception exception) {
87         super(message, exception);
88         if (locator != null) {
89             fPublicId = locator.getPublicId();
90             fLiteralSystemId = locator.getLiteralSystemId();
91             fExpandedSystemId = locator.getExpandedSystemId();
92             fBaseSystemId = locator.getBaseSystemId();
93             fLineNumber = locator.getLineNumber();
94             fColumnNumber = locator.getColumnNumber();
95             fCharacterOffset = locator.getCharacterOffset();
96         }
97     } // <init>(XMLLocator,String,Exception)
98 
99     //
100     // Public methods
101     //
102 
103     /** Returns the public identifier. */
getPublicId()104     public String getPublicId() {
105         return fPublicId;
106     } // getPublicId():String
107 
108     /** Returns the expanded system identifier. */
getExpandedSystemId()109     public String getExpandedSystemId() {
110         return fExpandedSystemId;
111     } // getExpandedSystemId():String
112 
113     /** Returns the literal system identifier. */
getLiteralSystemId()114     public String getLiteralSystemId() {
115         return fLiteralSystemId;
116     } // getLiteralSystemId():String
117 
118     /** Returns the base system identifier. */
getBaseSystemId()119     public String getBaseSystemId() {
120         return fBaseSystemId;
121     } // getBaseSystemId():String
122 
123     /** Returns the line number. */
getLineNumber()124     public int getLineNumber() {
125         return fLineNumber;
126     } // getLineNumber():int
127 
128     /** Returns the row number. */
getColumnNumber()129     public int getColumnNumber() {
130         return fColumnNumber;
131     } // getRowNumber():int
132 
133     /** Returns the character offset. */
getCharacterOffset()134     public int getCharacterOffset() {
135         return fCharacterOffset;
136     } // getCharacterOffset():int
137 
138     //
139     // Object methods
140     //
141 
142     /** Returns a string representation of this object. */
toString()143     public String toString() {
144 
145         StringBuffer str = new StringBuffer();
146         if (fPublicId != null) {
147             str.append(fPublicId);
148         }
149         str.append(':');
150         if (fLiteralSystemId != null) {
151             str.append(fLiteralSystemId);
152         }
153         str.append(':');
154         if (fExpandedSystemId != null) {
155             str.append(fExpandedSystemId);
156         }
157         str.append(':');
158         if (fBaseSystemId != null) {
159             str.append(fBaseSystemId);
160         }
161         str.append(':');
162         str.append(fLineNumber);
163         str.append(':');
164         str.append(fColumnNumber);
165         str.append(':');
166         str.append(fCharacterOffset);
167         str.append(':');
168         String message = getMessage();
169         if (message == null) {
170             Exception exception = getException();
171             if (exception != null) {
172                 message = exception.getMessage();
173             }
174         }
175         if (message != null) {
176             str.append(message);
177         }
178         return str.toString();
179 
180     } // toString():String
181 
182 } // XMLParseException
183