001: // SAX default implementation for Locator.
002: // http://www.saxproject.org
003: // No warranty; no copyright -- use this as you will.
004: // $Id: LocatorImpl.java,v 1.7 2002/02/01 20:06:20 db Exp $
005:
006: package org.xml.sax.helpers;
007:
008: import org.xml.sax.Locator;
009:
010: /**
011: * Provide an optional convenience implementation of Locator.
012: *
013: * <blockquote>
014: * <em>This module, both source code and documentation, is in the
015: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
016: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
017: * for further information.
018: * </blockquote>
019: *
020: * <p>This class is available mainly for application writers, who
021: * can use it to make a persistent snapshot of a locator at any
022: * point during a document parse:</p>
023: *
024: * <pre>
025: * Locator locator;
026: * Locator startloc;
027: *
028: * public void setLocator (Locator locator)
029: * {
030: * // note the locator
031: * this.locator = locator;
032: * }
033: *
034: * public void startDocument ()
035: * {
036: * // save the location of the start of the document
037: * // for future use.
038: * Locator startloc = new LocatorImpl(locator);
039: * }
040: *</pre>
041: *
042: * <p>Normally, parser writers will not use this class, since it
043: * is more efficient to provide location information only when
044: * requested, rather than constantly updating a Locator object.</p>
045: *
046: * @since SAX 1.0
047: * @author David Megginson
048: * @version 2.0.1 (sax2r2)
049: * @see org.xml.sax.Locator Locator
050: */
051: public class LocatorImpl implements Locator {
052:
053: /**
054: * Zero-argument constructor.
055: *
056: * <p>This will not normally be useful, since the main purpose
057: * of this class is to make a snapshot of an existing Locator.</p>
058: */
059: public LocatorImpl() {
060: }
061:
062: /**
063: * Copy constructor.
064: *
065: * <p>Create a persistent copy of the current state of a locator.
066: * When the original locator changes, this copy will still keep
067: * the original values (and it can be used outside the scope of
068: * DocumentHandler methods).</p>
069: *
070: * @param locator The locator to copy.
071: */
072: public LocatorImpl(Locator locator) {
073: setPublicId(locator.getPublicId());
074: setSystemId(locator.getSystemId());
075: setLineNumber(locator.getLineNumber());
076: setColumnNumber(locator.getColumnNumber());
077: }
078:
079: ////////////////////////////////////////////////////////////////////
080: // Implementation of org.xml.sax.Locator
081: ////////////////////////////////////////////////////////////////////
082:
083: /**
084: * Return the saved public identifier.
085: *
086: * @return The public identifier as a string, or null if none
087: * is available.
088: * @see org.xml.sax.Locator#getPublicId
089: * @see #setPublicId
090: */
091: public String getPublicId() {
092: return publicId;
093: }
094:
095: /**
096: * Return the saved system identifier.
097: *
098: * @return The system identifier as a string, or null if none
099: * is available.
100: * @see org.xml.sax.Locator#getSystemId
101: * @see #setSystemId
102: */
103: public String getSystemId() {
104: return systemId;
105: }
106:
107: /**
108: * Return the saved line number (1-based).
109: *
110: * @return The line number as an integer, or -1 if none is available.
111: * @see org.xml.sax.Locator#getLineNumber
112: * @see #setLineNumber
113: */
114: public int getLineNumber() {
115: return lineNumber;
116: }
117:
118: /**
119: * Return the saved column number (1-based).
120: *
121: * @return The column number as an integer, or -1 if none is available.
122: * @see org.xml.sax.Locator#getColumnNumber
123: * @see #setColumnNumber
124: */
125: public int getColumnNumber() {
126: return columnNumber;
127: }
128:
129: ////////////////////////////////////////////////////////////////////
130: // Setters for the properties (not in org.xml.sax.Locator)
131: ////////////////////////////////////////////////////////////////////
132:
133: /**
134: * Set the public identifier for this locator.
135: *
136: * @param publicId The new public identifier, or null
137: * if none is available.
138: * @see #getPublicId
139: */
140: public void setPublicId(String publicId) {
141: this .publicId = publicId;
142: }
143:
144: /**
145: * Set the system identifier for this locator.
146: *
147: * @param systemId The new system identifier, or null
148: * if none is available.
149: * @see #getSystemId
150: */
151: public void setSystemId(String systemId) {
152: this .systemId = systemId;
153: }
154:
155: /**
156: * Set the line number for this locator (1-based).
157: *
158: * @param lineNumber The line number, or -1 if none is available.
159: * @see #getLineNumber
160: */
161: public void setLineNumber(int lineNumber) {
162: this .lineNumber = lineNumber;
163: }
164:
165: /**
166: * Set the column number for this locator (1-based).
167: *
168: * @param columnNumber The column number, or -1 if none is available.
169: * @see #getColumnNumber
170: */
171: public void setColumnNumber(int columnNumber) {
172: this .columnNumber = columnNumber;
173: }
174:
175: ////////////////////////////////////////////////////////////////////
176: // Internal state.
177: ////////////////////////////////////////////////////////////////////
178:
179: private String publicId;
180: private String systemId;
181: private int lineNumber;
182: private int columnNumber;
183:
184: }
185:
186: // end of LocatorImpl.java
|