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