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