001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.xni.parser;
019:
020: import org.apache.xerces.xni.XMLLocator;
021: import org.apache.xerces.xni.XNIException;
022:
023: /**
024: * A parsing exception. This exception is different from the standard
025: * XNI exception in that it stores the location in the document (or
026: * its entities) where the exception occurred.
027: *
028: * @author Andy Clark, IBM
029: *
030: * @version $Id: XMLParseException.java 447244 2006-09-18 05:20:40Z mrglavas $
031: */
032: public class XMLParseException extends XNIException {
033:
034: /** Serialization version. */
035: static final long serialVersionUID = 1732959359448549967L;
036:
037: //
038: // Data
039: //
040:
041: /** Public identifier. */
042: protected String fPublicId;
043:
044: /** literal System identifier. */
045: protected String fLiteralSystemId;
046:
047: /** expanded System identifier. */
048: protected String fExpandedSystemId;
049:
050: /** Base system identifier. */
051: protected String fBaseSystemId;
052:
053: /** Line number. */
054: protected int fLineNumber = -1;
055:
056: /** Column number. */
057: protected int fColumnNumber = -1;
058:
059: /** Character offset. */
060: protected int fCharacterOffset = -1;
061:
062: //
063: // Constructors
064: //
065:
066: /** Constructs a parse exception. */
067: public XMLParseException(XMLLocator locator, String message) {
068: super (message);
069: if (locator != null) {
070: fPublicId = locator.getPublicId();
071: fLiteralSystemId = locator.getLiteralSystemId();
072: fExpandedSystemId = locator.getExpandedSystemId();
073: fBaseSystemId = locator.getBaseSystemId();
074: fLineNumber = locator.getLineNumber();
075: fColumnNumber = locator.getColumnNumber();
076: fCharacterOffset = locator.getCharacterOffset();
077: }
078: } // <init>(XMLLocator,String)
079:
080: /** Constructs a parse exception. */
081: public XMLParseException(XMLLocator locator, String message,
082: Exception exception) {
083: super (message, exception);
084: if (locator != null) {
085: fPublicId = locator.getPublicId();
086: fLiteralSystemId = locator.getLiteralSystemId();
087: fExpandedSystemId = locator.getExpandedSystemId();
088: fBaseSystemId = locator.getBaseSystemId();
089: fLineNumber = locator.getLineNumber();
090: fColumnNumber = locator.getColumnNumber();
091: fCharacterOffset = locator.getCharacterOffset();
092: }
093: } // <init>(XMLLocator,String,Exception)
094:
095: //
096: // Public methods
097: //
098:
099: /** Returns the public identifier. */
100: public String getPublicId() {
101: return fPublicId;
102: } // getPublicId():String
103:
104: /** Returns the expanded system identifier. */
105: public String getExpandedSystemId() {
106: return fExpandedSystemId;
107: } // getExpandedSystemId():String
108:
109: /** Returns the literal system identifier. */
110: public String getLiteralSystemId() {
111: return fLiteralSystemId;
112: } // getLiteralSystemId():String
113:
114: /** Returns the base system identifier. */
115: public String getBaseSystemId() {
116: return fBaseSystemId;
117: } // getBaseSystemId():String
118:
119: /** Returns the line number. */
120: public int getLineNumber() {
121: return fLineNumber;
122: } // getLineNumber():int
123:
124: /** Returns the row number. */
125: public int getColumnNumber() {
126: return fColumnNumber;
127: } // getRowNumber():int
128:
129: /** Returns the character offset. */
130: public int getCharacterOffset() {
131: return fCharacterOffset;
132: } // getCharacterOffset():int
133:
134: //
135: // Object methods
136: //
137:
138: /** Returns a string representation of this object. */
139: public String toString() {
140:
141: StringBuffer str = new StringBuffer();
142: if (fPublicId != null) {
143: str.append(fPublicId);
144: }
145: str.append(':');
146: if (fLiteralSystemId != null) {
147: str.append(fLiteralSystemId);
148: }
149: str.append(':');
150: if (fExpandedSystemId != null) {
151: str.append(fExpandedSystemId);
152: }
153: str.append(':');
154: if (fBaseSystemId != null) {
155: str.append(fBaseSystemId);
156: }
157: str.append(':');
158: str.append(fLineNumber);
159: str.append(':');
160: str.append(fColumnNumber);
161: str.append(':');
162: str.append(fCharacterOffset);
163: str.append(':');
164: String message = getMessage();
165: if (message == null) {
166: Exception exception = getException();
167: if (exception != null) {
168: message = exception.getMessage();
169: }
170: }
171: if (message != null) {
172: str.append(message);
173: }
174: return str.toString();
175:
176: } // toString():String
177:
178: } // XMLParseException
|