1 /* 2 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package org.xml.sax.helpers; 27 28 import org.xml.sax.Locator; 29 30 31 /** 32 * Provide an optional convenience implementation of Locator. 33 * 34 * <p>This class is available mainly for application writers, who 35 * can use it to make a persistent snapshot of a locator at any 36 * point during a document parse:</p> 37 * 38 * <pre> 39 * Locator locator; 40 * Locator startloc; 41 * 42 * public void setLocator (Locator locator) 43 * { 44 * // note the locator 45 * this.locator = locator; 46 * } 47 * 48 * public void startDocument () 49 * { 50 * // save the location of the start of the document 51 * // for future use. 52 * Locator startloc = new LocatorImpl(locator); 53 * } 54 *</pre> 55 * 56 * <p>Normally, parser writers will not use this class, since it 57 * is more efficient to provide location information only when 58 * requested, rather than constantly updating a Locator object.</p> 59 * 60 * @since 1.4, SAX 1.0 61 * @author David Megginson 62 * @see org.xml.sax.Locator Locator 63 */ 64 public class LocatorImpl implements Locator 65 { 66 67 68 /** 69 * Zero-argument constructor. 70 * 71 * <p>This will not normally be useful, since the main purpose 72 * of this class is to make a snapshot of an existing Locator.</p> 73 */ 74 public LocatorImpl () 75 { 76 } 77 78 79 /** 80 * Copy constructor. 81 * 82 * <p>Create a persistent copy of the current state of a locator. 83 * When the original locator changes, this copy will still keep 84 * the original values (and it can be used outside the scope of 85 * DocumentHandler methods).</p> 86 * 87 * @param locator The locator to copy. 88 */ 89 public LocatorImpl (Locator locator) 90 { 91 setPublicId(locator.getPublicId()); 92 setSystemId(locator.getSystemId()); 93 setLineNumber(locator.getLineNumber()); 94 setColumnNumber(locator.getColumnNumber()); 95 } 96 97 98 99 //////////////////////////////////////////////////////////////////// 100 // Implementation of org.xml.sax.Locator 101 //////////////////////////////////////////////////////////////////// 102 103 104 /** 105 * Return the saved public identifier. 106 * 107 * @return The public identifier as a string, or null if none 108 * is available. 109 * @see org.xml.sax.Locator#getPublicId 110 * @see #setPublicId 111 */ 112 public String getPublicId () 113 { 114 return publicId; 115 } 116 117 118 /** 119 * Return the saved system identifier. 120 * 121 * @return The system identifier as a string, or null if none 122 * is available. 123 * @see org.xml.sax.Locator#getSystemId 124 * @see #setSystemId 125 */ 126 public String getSystemId () 127 { 128 return systemId; 129 } 130 131 132 /** 133 * Return the saved line number (1-based). 134 * 135 * @return The line number as an integer, or -1 if none is available. 136 * @see org.xml.sax.Locator#getLineNumber 137 * @see #setLineNumber 138 */ 139 public int getLineNumber () 140 { 141 return lineNumber; 142 } 143 144 145 /** 146 * Return the saved column number (1-based). 147 * 148 * @return The column number as an integer, or -1 if none is available. 149 * @see org.xml.sax.Locator#getColumnNumber 150 * @see #setColumnNumber 151 */ 152 public int getColumnNumber () 153 { 154 return columnNumber; 155 } 156 157 158 159 //////////////////////////////////////////////////////////////////// 160 // Setters for the properties (not in org.xml.sax.Locator) 161 //////////////////////////////////////////////////////////////////// 162 163 164 /** 165 * Set the public identifier for this locator. 166 * 167 * @param publicId The new public identifier, or null 168 * if none is available. 169 * @see #getPublicId 170 */ 171 public void setPublicId (String publicId) 172 { 173 this.publicId = publicId; 174 } 175 176 177 /** 178 * Set the system identifier for this locator. 179 * 180 * @param systemId The new system identifier, or null 181 * if none is available. 182 * @see #getSystemId 183 */ 184 public void setSystemId (String systemId) 185 { 186 this.systemId = systemId; 187 } 188 189 190 /** 191 * Set the line number for this locator (1-based). 192 * 193 * @param lineNumber The line number, or -1 if none is available. 194 * @see #getLineNumber 195 */ 196 public void setLineNumber (int lineNumber) 197 { 198 this.lineNumber = lineNumber; 199 } 200 201 202 /** 203 * Set the column number for this locator (1-based). 204 * 205 * @param columnNumber The column number, or -1 if none is available. 206 * @see #getColumnNumber 207 */ 208 public void setColumnNumber (int columnNumber) 209 { 210 this.columnNumber = columnNumber; 211 } 212 213 214 215 //////////////////////////////////////////////////////////////////// 216 // Internal state. 217 //////////////////////////////////////////////////////////////////// 218 219 private String publicId; 220 private String systemId; 221 private int lineNumber; 222 private int columnNumber; 223 224 } 225 226 // end of LocatorImpl.java