KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > sax > Locator


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/sax/Locator.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/14 01:58:02 $
10
// $Revision: 1.1 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.sax;
28
29 import org.htmlparser.Parser;
30 import org.htmlparser.lexer.Lexer;
31
32 /**
33  * Transforms character offsets into line and column in the HTML file.
34  */

35 public class Locator
36     implements
37         org.xml.sax.Locator JavaDoc
38 {
39     /**
40      * Underlying parser object.
41      */

42     protected Parser mParser;
43
44     /**
45      * Creates a locator for the given parser.
46      * @param parser The parser with the {@link org.htmlparser.lexer.Page Page} being accessed.
47      */

48     public Locator (Parser parser)
49     {
50         mParser = parser;
51     }
52     
53     /**
54      * Return the public identifier for the current document event.
55      *
56      * <p>The return value is the public identifier of the document
57      * entity or of the external parsed entity in which the markup
58      * triggering the event appears.</p>
59      *
60      * @return A string containing the public identifier, or
61      * null if none is available.
62      * @see #getSystemId
63      */

64     public String JavaDoc getPublicId ()
65     {
66         return (null); // I assume this would be <title></title>
67
}
68     
69     
70     /**
71      * Return the system identifier for the current document event.
72      *
73      * <p>The return value is the system identifier of the document
74      * entity or of the external parsed entity in which the markup
75      * triggering the event appears.</p>
76      *
77      * <p>If the system identifier is a URL, the parser must resolve it
78      * fully before passing it to the application. For example, a file
79      * name must always be provided as a <em>file:...</em> URL, and other
80      * kinds of relative URI are also resolved against their bases.</p>
81      *
82      * @return A string containing the system identifier, or null
83      * if none is available.
84      * @see #getPublicId
85      */

86     public String JavaDoc getSystemId ()
87     {
88         return (mParser.getURL ());
89     }
90     
91     
92     /**
93      * Return the line number where the current document event ends.
94      * Lines are delimited by line ends, which are defined in
95      * the XML specification.
96      *
97      * <p><strong>Warning:</strong> The return value from the method
98      * is intended only as an approximation for the sake of diagnostics;
99      * it is not intended to provide sufficient information
100      * to edit the character content of the original XML document.
101      * In some cases, these "line" numbers match what would be displayed
102      * as columns, and in others they may not match the source text
103      * due to internal entity expansion. </p>
104      *
105      * <p>The return value is an approximation of the line number
106      * in the document entity or external parsed entity where the
107      * markup triggering the event appears.</p>
108      *
109      * <p>If possible, the SAX driver should provide the line position
110      * of the first character after the text associated with the document
111      * event. The first line is line 1.</p>
112      *
113      * @return The line number, or -1 if none is available.
114      * @see #getColumnNumber
115      */

116     public int getLineNumber ()
117     {
118         Lexer lexer;
119         
120         lexer = mParser.getLexer ();
121         return (lexer.getPage ().row (lexer.getCursor ()));
122     }
123     
124     
125     /**
126      * Return the column number where the current document event ends.
127      * This is one-based number of Java <code>char</code> values since
128      * the last line end.
129      *
130      * <p><strong>Warning:</strong> The return value from the method
131      * is intended only as an approximation for the sake of diagnostics;
132      * it is not intended to provide sufficient information
133      * to edit the character content of the original XML document.
134      * For example, when lines contain combining character sequences, wide
135      * characters, surrogate pairs, or bi-directional text, the value may
136      * not correspond to the column in a text editor's display. </p>
137      *
138      * <p>The return value is an approximation of the column number
139      * in the document entity or external parsed entity where the
140      * markup triggering the event appears.</p>
141      *
142      * <p>If possible, the SAX driver should provide the line position
143      * of the first character after the text associated with the document
144      * event. The first column in each line is column 1.</p>
145      *
146      * @return The column number, or -1 if none is available.
147      * @see #getLineNumber
148      */

149     public int getColumnNumber ()
150     {
151         Lexer lexer;
152         
153         lexer = mParser.getLexer ();
154         return (lexer.getPage ().column (lexer.getCursor ()));
155     }
156 }
157
Popular Tags