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