1 // SAX default implementation for Locator.
2 // http://www.saxproject.org
3 // No warranty; no copyright -- use this as you will.
4 // $Id: LocatorImpl.java,v 1.6 2002/01/30 20:52:27 dbrownell Exp $
5 
6 package org.xml.sax.helpers;
7 
8 import org.xml.sax.Locator;
9 
10 import android.compat.annotation.UnsupportedAppUsage;
11 
12 
13 /**
14  * Provide an optional convenience implementation of Locator.
15  *
16  * <blockquote>
17  * <em>This module, both source code and documentation, is in the
18  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
19  * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
20  * for further information.
21  * </blockquote>
22  *
23  * <p>This class is available mainly for application writers, who
24  * can use it to make a persistent snapshot of a locator at any
25  * point during a document parse:</p>
26  *
27  * <pre>
28  * Locator locator;
29  * Locator startloc;
30  *
31  * public void setLocator (Locator locator)
32  * {
33  *         // note the locator
34  *   this.locator = locator;
35  * }
36  *
37  * public void startDocument ()
38  * {
39  *         // save the location of the start of the document
40  *         // for future use.
41  *   Locator startloc = new LocatorImpl(locator);
42  * }
43  *</pre>
44  *
45  * <p>Normally, parser writers will not use this class, since it
46  * is more efficient to provide location information only when
47  * requested, rather than constantly updating a Locator object.</p>
48  *
49  * @since SAX 1.0
50  * @author David Megginson
51  * @version 2.0.1 (sax2r2)
52  * @see org.xml.sax.Locator Locator
53  */
54 public class LocatorImpl implements Locator
55 {
56 
57 
58     /**
59      * Zero-argument constructor.
60      *
61      * <p>This will not normally be useful, since the main purpose
62      * of this class is to make a snapshot of an existing Locator.</p>
63      */
LocatorImpl()64     public LocatorImpl ()
65     {
66     }
67 
68 
69     /**
70      * Copy constructor.
71      *
72      * <p>Create a persistent copy of the current state of a locator.
73      * When the original locator changes, this copy will still keep
74      * the original values (and it can be used outside the scope of
75      * DocumentHandler methods).</p>
76      *
77      * @param locator The locator to copy.
78      */
LocatorImpl(Locator locator)79     public LocatorImpl (Locator locator)
80     {
81     setPublicId(locator.getPublicId());
82     setSystemId(locator.getSystemId());
83     setLineNumber(locator.getLineNumber());
84     setColumnNumber(locator.getColumnNumber());
85     }
86 
87 
88 
89     ////////////////////////////////////////////////////////////////////
90     // Implementation of org.xml.sax.Locator
91     ////////////////////////////////////////////////////////////////////
92 
93 
94     /**
95      * Return the saved public identifier.
96      *
97      * @return The public identifier as a string, or null if none
98      *         is available.
99      * @see org.xml.sax.Locator#getPublicId
100      * @see #setPublicId
101      */
getPublicId()102     public String getPublicId ()
103     {
104     return publicId;
105     }
106 
107 
108     /**
109      * Return the saved system identifier.
110      *
111      * @return The system identifier as a string, or null if none
112      *         is available.
113      * @see org.xml.sax.Locator#getSystemId
114      * @see #setSystemId
115      */
getSystemId()116     public String getSystemId ()
117     {
118     return systemId;
119     }
120 
121 
122     /**
123      * Return the saved line number (1-based).
124      *
125      * @return The line number as an integer, or -1 if none is available.
126      * @see org.xml.sax.Locator#getLineNumber
127      * @see #setLineNumber
128      */
getLineNumber()129     public int getLineNumber ()
130     {
131     return lineNumber;
132     }
133 
134 
135     /**
136      * Return the saved column number (1-based).
137      *
138      * @return The column number as an integer, or -1 if none is available.
139      * @see org.xml.sax.Locator#getColumnNumber
140      * @see #setColumnNumber
141      */
getColumnNumber()142     public int getColumnNumber ()
143     {
144     return columnNumber;
145     }
146 
147 
148 
149     ////////////////////////////////////////////////////////////////////
150     // Setters for the properties (not in org.xml.sax.Locator)
151     ////////////////////////////////////////////////////////////////////
152 
153 
154     /**
155      * Set the public identifier for this locator.
156      *
157      * @param publicId The new public identifier, or null
158      *        if none is available.
159      * @see #getPublicId
160      */
setPublicId(String publicId)161     public void setPublicId (String publicId)
162     {
163     this.publicId = publicId;
164     }
165 
166 
167     /**
168      * Set the system identifier for this locator.
169      *
170      * @param systemId The new system identifier, or null
171      *        if none is available.
172      * @see #getSystemId
173      */
setSystemId(String systemId)174     public void setSystemId (String systemId)
175     {
176     this.systemId = systemId;
177     }
178 
179 
180     /**
181      * Set the line number for this locator (1-based).
182      *
183      * @param lineNumber The line number, or -1 if none is available.
184      * @see #getLineNumber
185      */
setLineNumber(int lineNumber)186     public void setLineNumber (int lineNumber)
187     {
188     this.lineNumber = lineNumber;
189     }
190 
191 
192     /**
193      * Set the column number for this locator (1-based).
194      *
195      * @param columnNumber The column number, or -1 if none is available.
196      * @see #getColumnNumber
197      */
setColumnNumber(int columnNumber)198     public void setColumnNumber (int columnNumber)
199     {
200     this.columnNumber = columnNumber;
201     }
202 
203 
204 
205     ////////////////////////////////////////////////////////////////////
206     // Internal state.
207     ////////////////////////////////////////////////////////////////////
208 
209     @UnsupportedAppUsage
210     private String publicId;
211     @UnsupportedAppUsage
212     private String systemId;
213     @UnsupportedAppUsage
214     private int lineNumber;
215     @UnsupportedAppUsage
216     private int columnNumber;
217 
218 }
219 
220 // end of LocatorImpl.java
221