KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > utils > SAXSourceLocator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: SAXSourceLocator.java,v 1.8 2004/02/17 04:21:14 minchau Exp $
18  */

19 package org.apache.xml.utils;
20
21 import java.io.Serializable JavaDoc;
22
23 import javax.xml.transform.SourceLocator JavaDoc;
24
25 import org.xml.sax.Locator JavaDoc;
26 import org.xml.sax.SAXParseException JavaDoc;
27 import org.xml.sax.helpers.LocatorImpl JavaDoc;
28
29 /**
30  * Class SAXSourceLocator extends org.xml.sax.helpers.LocatorImpl
31  * for the purpose of implementing the SourceLocator interface,
32  * and thus can be both a SourceLocator and a SAX Locator.
33  */

34 public class SAXSourceLocator extends LocatorImpl JavaDoc
35         implements SourceLocator JavaDoc, Serializable JavaDoc
36 {
37   /** The SAX Locator object.
38    * @serial
39    */

40   Locator JavaDoc m_locator;
41
42   /**
43    * Constructor SAXSourceLocator
44    *
45    */

46   public SAXSourceLocator(){}
47
48   /**
49    * Constructor SAXSourceLocator
50    *
51    *
52    * @param locator Source locator
53    */

54   public SAXSourceLocator(Locator JavaDoc locator)
55   {
56     m_locator = locator;
57     this.setColumnNumber(locator.getColumnNumber());
58     this.setLineNumber(locator.getLineNumber());
59     this.setPublicId(locator.getPublicId());
60     this.setSystemId(locator.getSystemId());
61   }
62   
63   /**
64    * Constructor SAXSourceLocator
65    *
66    *
67    * @param locator Source locator
68    */

69   public SAXSourceLocator(javax.xml.transform.SourceLocator JavaDoc locator)
70   {
71     m_locator = null;
72     this.setColumnNumber(locator.getColumnNumber());
73     this.setLineNumber(locator.getLineNumber());
74     this.setPublicId(locator.getPublicId());
75     this.setSystemId(locator.getSystemId());
76   }
77
78   
79   /**
80    * Constructor SAXSourceLocator
81    *
82    *
83    * @param spe SAXParseException exception.
84    */

85   public SAXSourceLocator(SAXParseException JavaDoc spe)
86   {
87     this.setLineNumber( spe.getLineNumber() );
88     this.setColumnNumber( spe.getColumnNumber() );
89     this.setPublicId( spe.getPublicId() );
90     this.setSystemId( spe.getSystemId() );
91   }
92   
93   /**
94    * Return the public identifier for the current document event.
95    *
96    * <p>The return value is the public identifier of the document
97    * entity or of the external parsed entity in which the markup
98    * triggering the event appears.</p>
99    *
100    * @return A string containing the public identifier, or
101    * null if none is available.
102    * @see #getSystemId
103    */

104   public String JavaDoc getPublicId()
105   {
106     return (null == m_locator) ? super.getPublicId() : m_locator.getPublicId();
107   }
108
109   /**
110    * Return the system identifier for the current document event.
111    *
112    * <p>The return value is the system identifier of the document
113    * entity or of the external parsed entity in which the markup
114    * triggering the event appears.</p>
115    *
116    * <p>If the system identifier is a URL, the parser must resolve it
117    * fully before passing it to the application.</p>
118    *
119    * @return A string containing the system identifier, or null
120    * if none is available.
121    * @see #getPublicId
122    */

123   public String JavaDoc getSystemId()
124   {
125     return (null == m_locator) ? super.getSystemId() : m_locator.getSystemId();
126   }
127   
128   /**
129    * Return the line number where the current document event ends.
130    *
131    * <p><strong>Warning:</strong> The return value from the method
132    * is intended only as an approximation for the sake of error
133    * reporting; it is not intended to provide sufficient information
134    * to edit the character content of the original XML document.</p>
135    *
136    * <p>The return value is an approximation of the line number
137    * in the document entity or external parsed entity where the
138    * markup triggering the event appears.</p>
139    *
140    * @return The line number, or -1 if none is available.
141    * @see #getColumnNumber
142    */

143   public int getLineNumber()
144   {
145     return (null == m_locator) ? super.getLineNumber() : m_locator.getLineNumber();
146   }
147
148   /**
149    * Return the column number where the current document event ends.
150    *
151    * <p><strong>Warning:</strong> The return value from the method
152    * is intended only as an approximation for the sake of error
153    * reporting; it is not intended to provide sufficient information
154    * to edit the character content of the original XML document.</p>
155    *
156    * <p>The return value is an approximation of the column number
157    * in the document entity or external parsed entity where the
158    * markup triggering the event appears.</p>
159    *
160    * @return The column number, or -1 if none is available.
161    * @see #getLineNumber
162    */

163   public int getColumnNumber()
164   {
165     return (null == m_locator) ? super.getColumnNumber() : m_locator.getColumnNumber();
166   }
167 }
168
Popular Tags