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