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 locator interface for document events.
  27 // http://www.saxproject.org
  28 // No warranty; no copyright -- use this as you will.
  29 // $Id: Locator.java,v 1.2 2004/11/03 22:55:32 jsuttor Exp $
  30 
  31 package org.xml.sax;
  32 
  33 
  34 /**
  35  * Interface for associating a SAX event with a document location.
  36  *
  37  * <blockquote>
  38  * <em>This module, both source code and documentation, is in the
  39  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  40  * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  41  * for further information.
  42  * </blockquote>
  43  *
  44  * <p>If a SAX parser provides location information to the SAX
  45  * application, it does so by implementing this interface and then
  46  * passing an instance to the application using the content
  47  * handler's {@link org.xml.sax.ContentHandler#setDocumentLocator
  48  * setDocumentLocator} method.  The application can use the
  49  * object to obtain the location of any other SAX event
  50  * in the XML source document.</p>
  51  *
  52  * <p>Note that the results returned by the object will be valid only
  53  * during the scope of each callback method: the application
  54  * will receive unpredictable results if it attempts to use the
  55  * locator at any other time, or after parsing completes.</p>
  56  *
  57  * <p>SAX parsers are not required to supply a locator, but they are
  58  * very strongly encouraged to do so.  If the parser supplies a
  59  * locator, it must do so before reporting any other document events.
  60  * If no locator has been set by the time the application receives
  61  * the {@link org.xml.sax.ContentHandler#startDocument startDocument}
  62  * event, the application should assume that a locator is not
  63  * available.</p>
  64  *
  65  * @since SAX 1.0
  66  * @author David Megginson
  67  * @see org.xml.sax.ContentHandler#setDocumentLocator
  68  */
  69 public interface Locator {
  70 
  71 
  72     /**
  73      * Return the public identifier for the current document event.
  74      *
  75      * <p>The return value is the public identifier of the document
  76      * entity or of the external parsed entity in which the markup
  77      * triggering the event appears.</p>
  78      *
  79      * @return A string containing the public identifier, or
  80      *         null if none is available.
  81      * @see #getSystemId
  82      */
  83     public abstract String getPublicId ();
  84 
  85 
  86     /**
  87      * Return the system identifier for the current document event.
  88      *
  89      * <p>The return value is the system identifier of the document
  90      * entity or of the external parsed entity in which the markup
  91      * triggering the event appears.</p>
  92      *
  93      * <p>If the system identifier is a URL, the parser must resolve it
  94      * fully before passing it to the application.  For example, a file
  95      * name must always be provided as a <em>file:...</em> URL, and other
  96      * kinds of relative URI are also resolved against their bases.</p>
  97      *
  98      * @return A string containing the system identifier, or null
  99      *         if none is available.
 100      * @see #getPublicId
 101      */
 102     public abstract String getSystemId ();
 103 
 104 
 105     /**
 106      * Return the line number where the current document event ends.
 107      * Lines are delimited by line ends, which are defined in
 108      * the XML specification.
 109      *
 110      * <p><strong>Warning:</strong> The return value from the method
 111      * is intended only as an approximation for the sake of diagnostics;
 112      * it is not intended to provide sufficient information
 113      * to edit the character content of the original XML document.
 114      * In some cases, these "line" numbers match what would be displayed
 115      * as columns, and in others they may not match the source text
 116      * due to internal entity expansion.  </p>
 117      *
 118      * <p>The return value is an approximation of the line number
 119      * in the document entity or external parsed entity where the
 120      * markup triggering the event appears.</p>
 121      *
 122      * <p>If possible, the SAX driver should provide the line position
 123      * of the first character after the text associated with the document
 124      * event.  The first line is line 1.</p>
 125      *
 126      * @return The line number, or -1 if none is available.
 127      * @see #getColumnNumber
 128      */
 129     public abstract int getLineNumber ();
 130 
 131 
 132     /**
 133      * Return the column number where the current document event ends.
 134      * This is one-based number of Java <code>char</code> values since
 135      * the last line end.
 136      *
 137      * <p><strong>Warning:</strong> The return value from the method
 138      * is intended only as an approximation for the sake of diagnostics;
 139      * it is not intended to provide sufficient information
 140      * to edit the character content of the original XML document.
 141      * For example, when lines contain combining character sequences, wide
 142      * characters, surrogate pairs, or bi-directional text, the value may
 143      * not correspond to the column in a text editor's display. </p>
 144      *
 145      * <p>The return value is an approximation of the column number
 146      * in the document entity or external parsed entity where the
 147      * markup triggering the event appears.</p>
 148      *
 149      * <p>If possible, the SAX driver should provide the line position
 150      * of the first character after the text associated with the document
 151      * event.  The first column in each line is column 1.</p>
 152      *
 153      * @return The column number, or -1 if none is available.
 154      * @see #getLineNumber
 155      */
 156     public abstract int getColumnNumber ();
 157 
 158 }
 159 
 160 // end of Locator.java