1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 /*
6 * Copyright 1999-2004 The Apache Software Foundation.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 /*
21 * $Id: SAXSourceLocator.java,v 1.2.4.1 2005/09/15 08:15:52 suresh_emailid Exp $
22 */
23 package com.sun.org.apache.xml.internal.utils;
24
25 import java.io.Serializable;
26
27 import javax.xml.transform.SourceLocator;
28
29 import org.xml.sax.Locator;
30 import org.xml.sax.SAXParseException;
31 import org.xml.sax.helpers.LocatorImpl;
32
33 /**
34 * Class SAXSourceLocator extends org.xml.sax.helpers.LocatorImpl
35 * for the purpose of implementing the SourceLocator interface,
36 * and thus can be both a SourceLocator and a SAX Locator.
37 */
38 public class SAXSourceLocator extends LocatorImpl
39 implements SourceLocator, Serializable
40 {
41 static final long serialVersionUID = 3181680946321164112L;
42 /** The SAX Locator object.
43 * @serial
44 */
45 Locator m_locator;
46
47 /**
48 * Constructor SAXSourceLocator
49 *
50 */
51 public SAXSourceLocator(){}
52
53 /**
54 * Constructor SAXSourceLocator
55 *
56 *
57 * @param locator Source locator
58 */
59 public SAXSourceLocator(Locator locator)
60 {
61 m_locator = locator;
62 this.setColumnNumber(locator.getColumnNumber());
63 this.setLineNumber(locator.getLineNumber());
64 this.setPublicId(locator.getPublicId());
65 this.setSystemId(locator.getSystemId());
66 }
67
68 /**
69 * Constructor SAXSourceLocator
70 *
71 *
72 * @param locator Source locator
73 */
74 public SAXSourceLocator(javax.xml.transform.SourceLocator locator)
75 {
76 m_locator = null;
77 this.setColumnNumber(locator.getColumnNumber());
78 this.setLineNumber(locator.getLineNumber());
79 this.setPublicId(locator.getPublicId());
80 this.setSystemId(locator.getSystemId());
81 }
82
83
84 /**
85 * Constructor SAXSourceLocator
86 *
87 *
88 * @param spe SAXParseException exception.
89 */
90 public SAXSourceLocator(SAXParseException spe)
91 {
92 this.setLineNumber( spe.getLineNumber() );
93 this.setColumnNumber( spe.getColumnNumber() );
94 this.setPublicId( spe.getPublicId() );
95 this.setSystemId( spe.getSystemId() );
96 }
97
98 /**
99 * Return the public identifier for the current document event.
100 *
101 * <p>The return value is the public identifier of the document
102 * entity or of the external parsed entity in which the markup
103 * triggering the event appears.</p>
104 *
105 * @return A string containing the public identifier, or
106 * null if none is available.
107 * @see #getSystemId
108 */
109 public String getPublicId()
110 {
111 return (null == m_locator) ? super.getPublicId() : m_locator.getPublicId();
112 }
113
114 /**
115 * Return the system identifier for the current document event.
116 *
117 * <p>The return value is the system identifier of the document
118 * entity or of the external parsed entity in which the markup
119 * triggering the event appears.</p>
120 *
121 * <p>If the system identifier is a URL, the parser must resolve it
122 * fully before passing it to the application.</p>
123 *
124 * @return A string containing the system identifier, or null
125 * if none is available.
126 * @see #getPublicId
127 */
128 public String getSystemId()
129 {
130 return (null == m_locator) ? super.getSystemId() : m_locator.getSystemId();
131 }
132
133 /**
134 * Return the line number where the current document event ends.
135 *
136 * <p><strong>Warning:</strong> The return value from the method
137 * is intended only as an approximation for the sake of error
138 * reporting; it is not intended to provide sufficient information
139 * to edit the character content of the original XML document.</p>
140 *
141 * <p>The return value is an approximation of the line number
142 * in the document entity or external parsed entity where the
143 * markup triggering the event appears.</p>
144 *
145 * @return The line number, or -1 if none is available.
146 * @see #getColumnNumber
147 */
148 public int getLineNumber()
149 {
150 return (null == m_locator) ? super.getLineNumber() : m_locator.getLineNumber();
151 }
152
153 /**
154 * Return the column number where the current document event ends.
155 *
156 * <p><strong>Warning:</strong> The return value from the method
157 * is intended only as an approximation for the sake of error
158 * reporting; it is not intended to provide sufficient information
159 * to edit the character content of the original XML document.</p>
160 *
161 * <p>The return value is an approximation of the column number
162 * in the document entity or external parsed entity where the
163 * markup triggering the event appears.</p>
164 *
165 * @return The column number, or -1 if none is available.
166 * @see #getLineNumber
167 */
168 public int getColumnNumber()
169 {
170 return (null == m_locator) ? super.getColumnNumber() : m_locator.getColumnNumber();
171 }
172 }