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