001: /* Copyright 2000 - 2001 Quadcap Software. All rights reserved.
002: *
003: * This software is distributed under the Quadcap Free Software License.
004: * This software may be used or modified for any purpose, personal or
005: * commercial. Open Source redistributions are permitted. Commercial
006: * redistribution of larger works derived from, or works which bundle
007: * this software requires a "Commercial Redistribution License"; see
008: * http://www.quadcap.com/purchase.
009: *
010: * Redistributions qualify as "Open Source" under one of the following terms:
011: *
012: * Redistributions are made at no charge beyond the reasonable cost of
013: * materials and delivery.
014: *
015: * Redistributions are accompanied by a copy of the Source Code or by an
016: * irrevocable offer to provide a copy of the Source Code for up to three
017: * years at the cost of materials and delivery. Such redistributions
018: * must allow further use, modification, and redistribution of the Source
019: * Code under substantially the same terms as this license.
020: *
021: * Redistributions of source code must retain the copyright notices as they
022: * appear in each source code file, these license terms, and the
023: * disclaimer/limitation of liability set forth as paragraph 6 below.
024: *
025: * Redistributions in binary form must reproduce this Copyright Notice,
026: * these license terms, and the disclaimer/limitation of liability set
027: * forth as paragraph 6 below, in the documentation and/or other materials
028: * provided with the distribution.
029: *
030: * The Software is provided on an "AS IS" basis. No warranty is
031: * provided that the Software is free of defects, or fit for a
032: * particular purpose.
033: *
034: * Limitation of Liability. Quadcap Software shall not be liable
035: * for any damages suffered by the Licensee or any third party resulting
036: * from use of the Software.
037: */
038:
039: // SAX default implementation for Locator.
040: // No warranty; no copyright -- use this as you will.
041: // $Id: LocatorImpl.java,v 1.3 2001/01/06 06:11:03 stan Exp $
042: package org.xml.sax.helpers;
043:
044: import org.xml.sax.Locator;
045:
046: /**
047: * Provide an optional convenience implementation of Locator.
048: *
049: * <p>This class is available mainly for application writers, who
050: * can use it to make a persistent snapshot of a locator at any
051: * point during a document parse:</p>
052: *
053: * <pre>
054: * Locator locator;
055: * Locator startloc;
056: *
057: * public void setLocator (Locator locator)
058: * {
059: * // note the locator
060: * this.locator = locator;
061: * }
062: *
063: * public void startDocument ()
064: * {
065: * // save the location of the start of the document
066: * // for future use.
067: * Locator startloc = new LocatorImpl(locator);
068: * }
069: *</pre>
070: *
071: * <p>Normally, parser writers will not use this class, since it
072: * is more efficient to provide location information only when
073: * requested, rather than constantly updating a Locator object.</p>
074: *
075: * @see org.xml.sax.Locator
076: */
077: public class LocatorImpl implements Locator {
078:
079: /**
080: * Zero-argument constructor.
081: *
082: * <p>This will not normally be useful, since the main purpose
083: * of this class is to make a snapshot of an existing Locator.</p>
084: */
085: public LocatorImpl() {
086: }
087:
088: /**
089: * Copy constructor.
090: *
091: * <p>Create a persistent copy of the current state of a locator.
092: * When the original locator changes, this copy will still keep
093: * the original values (and it can be used outside the scope of
094: * DocumentHandler methods).</p>
095: *
096: * @param locator The locator to copy.
097: */
098: public LocatorImpl(Locator locator) {
099: setPublicId(locator.getPublicId());
100: setSystemId(locator.getSystemId());
101: setLineNumber(locator.getLineNumber());
102: setColumnNumber(locator.getColumnNumber());
103: }
104:
105: //////////////////////////////////////////////////////////////////////
106: // Implementation of org.xml.sax.Locator
107: //////////////////////////////////////////////////////////////////////
108:
109: /**
110: * Return the saved public identifier.
111: *
112: * @return The public identifier as a string, or null if none
113: * is available.
114: * @see org.xml.sax.Locator#getPublicId
115: * @see #setPublicId
116: */
117: public String getPublicId() {
118: return publicId;
119: }
120:
121: /**
122: * Return the saved system identifier.
123: *
124: * @return The system identifier as a string, or null if none
125: * is available.
126: * @see org.xml.sax.Locator#getSystemId
127: * @see #setSystemId
128: */
129: public String getSystemId() {
130: return systemId;
131: }
132:
133: /**
134: * Return the saved line number (1-based).
135: *
136: * @return The line number as an integer, or -1 if none is available.
137: * @see org.xml.sax.Locator#getLineNumber
138: * @see #setLineNumber
139: */
140: public int getLineNumber() {
141: return lineNumber;
142: }
143:
144: /**
145: * Return the saved column number (1-based).
146: *
147: * @return The column number as an integer, or -1 if none is available.
148: * @see org.xml.sax.Locator#getColumnNumber
149: * @see #setColumnNumber
150: */
151: public int getColumnNumber() {
152: return columnNumber;
153: }
154:
155: //////////////////////////////////////////////////////////////////////
156: // Setters for the properties (not in org.xml.sax.Locator)
157: //////////////////////////////////////////////////////////////////////
158:
159: /**
160: * Set the public identifier for this locator.
161: *
162: * @param publicId The new public identifier, or null
163: * if none is available.
164: * @see #getPublicId
165: */
166: public void setPublicId(String publicId) {
167: this .publicId = publicId;
168: }
169:
170: /**
171: * Set the system identifier for this locator.
172: *
173: * @param systemId The new system identifier, or null
174: * if none is available.
175: * @see #getSystemId
176: */
177: public void setSystemId(String systemId) {
178: this .systemId = systemId;
179: }
180:
181: /**
182: * Set the line number for this locator (1-based).
183: *
184: * @param lineNumber The line number, or -1 if none is available.
185: * @see #getLineNumber
186: */
187: public void setLineNumber(int lineNumber) {
188: this .lineNumber = lineNumber;
189: }
190:
191: /**
192: * Set the column number for this locator (1-based).
193: *
194: * @param columnNumber The column number, or -1 if none is available.
195: * @see #getColumnNumber
196: */
197: public void setColumnNumber(int columnNumber) {
198: this .columnNumber = columnNumber;
199: }
200:
201: //////////////////////////////////////////////////////////////////////
202: // Internal state.
203: //////////////////////////////////////////////////////////////////////
204:
205: private String publicId;
206: private String systemId;
207: private int lineNumber;
208: private int columnNumber;
209:
210: }
|