001: /*
002: * Copyright (c) 1999 World Wide Web Consortium
003: * (Massachusetts Institute of Technology, Institut National de Recherche
004: * en Informatique et en Automatique, Keio University).
005: * All Rights Reserved. http://www.w3.org/Consortium/Legal/
006: *
007: * The original version of this interface comes from SAX :
008: * http://www.megginson.com/SAX/
009: *
010: * $Id$
011: */
012: package org.w3c.css.sac;
013:
014: /**
015: * Encapsulate a CSS parse error or warning.
016: *
017: * <p>This exception will include information for locating the error
018: * in the original CSS document. Note that although the application
019: * will receive a CSSParseException as the argument to the handlers
020: * in the ErrorHandler interface, the application is not actually
021: * required to throw the exception; instead, it can simply read the
022: * information in it and take a different action.</p>
023: *
024: * <p>Since this exception is a subclass of CSSException, it
025: * inherits the ability to wrap another exception.</p>
026: *
027: * @version $Revision$
028: * @author Philippe Le Hegaret
029: */
030: public class CSSParseException extends CSSException {
031:
032: private String uri;
033: private int lineNumber;
034: private int columnNumber;
035:
036: /**
037: * Create a new CSSParseException from a message and a Locator.
038: *
039: * <p>This constructor is especially useful when an application is
040: * creating its own exception from within a DocumentHandler
041: * callback.</p>
042: *
043: * @param message The error or warning message.
044: * @param locator The locator object for the error or warning.
045: * @see Locator
046: * @see Parser#setLocale
047: */
048: public CSSParseException(String message, Locator locator) {
049: super (message);
050: this .code = SAC_SYNTAX_ERR;
051: this .uri = locator.getURI();
052: this .lineNumber = locator.getLineNumber();
053: this .columnNumber = locator.getColumnNumber();
054: }
055:
056: /**
057:
058: * Wrap an existing exception in a CSSParseException.
059: *
060: * <p>This constructor is especially useful when an application is
061: * creating its own exception from within a DocumentHandler
062: * callback, and needs to wrap an existing exception that is not a
063: * subclass of CSSException.</p>
064: *
065: * @param message The error or warning message, or null to
066: * use the message from the embedded exception.
067: * @param locator The locator object for the error or warning.
068: * @param e Any exception
069: * @see Locator
070: * @see Parser#setLocale
071: */
072: public CSSParseException(String message, Locator locator,
073: Exception e) {
074: super (SAC_SYNTAX_ERR, message, e);
075: this .uri = locator.getURI();
076: this .lineNumber = locator.getLineNumber();
077: this .columnNumber = locator.getColumnNumber();
078: }
079:
080: /**
081: * Create a new CSSParseException.
082: *
083: * <p>This constructor is most useful for parser writers.</p>
084: *
085: * <p>the parser must resolve the URI fully before creating the exception.</p>
086: *
087: * @param message The error or warning message.
088: * @param uri The URI of the document that generated the error or warning.
089: * @param lineNumber The line number of the end of the text that
090: * caused the error or warning.
091: * @param columnNumber The column number of the end of the text that
092: * cause the error or warning.
093: * @see Parser#setLocale
094: */
095: public CSSParseException(String message, String uri,
096: int lineNumber, int columnNumber) {
097: super (message);
098: this .code = SAC_SYNTAX_ERR;
099: this .uri = uri;
100: this .lineNumber = lineNumber;
101: this .columnNumber = columnNumber;
102: }
103:
104: /**
105: * Create a new CSSParseException with an embedded exception.
106: *
107: * <p>This constructor is most useful for parser writers who
108: * need to wrap an exception that is not a subclass of
109: * CSSException.</p>
110: *
111: * <p>The parser must resolve the URI fully before creating the
112: * exception.</p>
113: *
114: * @param message The error or warning message, or null to use
115: * the message from the embedded exception.
116: * @param uri The URI of the document that generated
117: * the error or warning.
118: * @param lineNumber The line number of the end of the text that
119: * caused the error or warning.
120: * @param columnNumber The column number of the end of the text that
121: * cause the error or warning.
122: * @param e Another exception to embed in this one.
123: * @see Parser#setLocale
124: */
125: public CSSParseException(String message, String uri,
126: int lineNumber, int columnNumber, Exception e) {
127: super (SAC_SYNTAX_ERR, message, e);
128: this .uri = uri;
129: this .lineNumber = lineNumber;
130: this .columnNumber = columnNumber;
131: }
132:
133: /**
134: * Get the URI of the document where the exception occurred.
135: *
136: * <p>The URI will be resolved fully.</p>
137: *
138: * @return A string containing the URI, or null
139: * if none is available.
140: * @see Locator#getURI
141: */
142: public String getURI() {
143: return this .uri;
144: }
145:
146: /**
147: * The line number of the end of the text where the exception occurred.
148: *
149: * @return An integer representing the line number, or -1
150: * if none is available.
151: * @see Locator#getLineNumber
152: */
153: public int getLineNumber() {
154: return this .lineNumber;
155: }
156:
157: /**
158: * The column number of the end of the text where the exception occurred.
159: *
160: * <p>The first column in a line is position 1.</p>
161: *
162: * @return An integer representing the column number, or -1
163: * if none is available.
164: * @see Locator#getColumnNumber
165: */
166: public int getColumnNumber() {
167: return this.columnNumber;
168: }
169: }
|