1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.utils;
  58. import javax.xml.transform.SourceLocator;
  59. import org.xml.sax.helpers.LocatorImpl;
  60. import org.xml.sax.Locator;
  61. import org.xml.sax.SAXParseException;
  62. import java.io.Serializable;
  63. /**
  64. * Class SAXSourceLocator extends org.xml.sax.helpers.LocatorImpl
  65. * for the purpose of implementing the SourceLocator interface,
  66. * and thus can be both a SourceLocator and a SAX Locator.
  67. */
  68. public class SAXSourceLocator extends LocatorImpl
  69. implements SourceLocator, Serializable
  70. {
  71. /** The SAX Locator object.
  72. * @serial
  73. */
  74. Locator m_locator;
  75. /**
  76. * Constructor SAXSourceLocator
  77. *
  78. */
  79. public SAXSourceLocator(){}
  80. /**
  81. * Constructor SAXSourceLocator
  82. *
  83. *
  84. * @param locator Source locator
  85. */
  86. public SAXSourceLocator(Locator locator)
  87. {
  88. m_locator = locator;
  89. this.setColumnNumber(locator.getColumnNumber());
  90. this.setLineNumber(locator.getLineNumber());
  91. this.setPublicId(locator.getPublicId());
  92. this.setSystemId(locator.getSystemId());
  93. }
  94. /**
  95. * Constructor SAXSourceLocator
  96. *
  97. *
  98. * @param locator Source locator
  99. */
  100. public SAXSourceLocator(javax.xml.transform.SourceLocator locator)
  101. {
  102. m_locator = null;
  103. this.setColumnNumber(locator.getColumnNumber());
  104. this.setLineNumber(locator.getLineNumber());
  105. this.setPublicId(locator.getPublicId());
  106. this.setSystemId(locator.getSystemId());
  107. }
  108. /**
  109. * Constructor SAXSourceLocator
  110. *
  111. *
  112. * @param spe SAXParseException exception.
  113. */
  114. public SAXSourceLocator(SAXParseException spe)
  115. {
  116. this.setLineNumber( spe.getLineNumber() );
  117. this.setColumnNumber( spe.getColumnNumber() );
  118. this.setPublicId( spe.getPublicId() );
  119. this.setSystemId( spe.getSystemId() );
  120. }
  121. /**
  122. * Return the public identifier for the current document event.
  123. *
  124. * <p>The return value is the public identifier of the document
  125. * entity or of the external parsed entity in which the markup
  126. * triggering the event appears.</p>
  127. *
  128. * @return A string containing the public identifier, or
  129. * null if none is available.
  130. * @see #getSystemId
  131. */
  132. public String getPublicId()
  133. {
  134. return (null == m_locator) ? super.getPublicId() : m_locator.getPublicId();
  135. }
  136. /**
  137. * Return the system identifier for the current document event.
  138. *
  139. * <p>The return value is the system identifier of the document
  140. * entity or of the external parsed entity in which the markup
  141. * triggering the event appears.</p>
  142. *
  143. * <p>If the system identifier is a URL, the parser must resolve it
  144. * fully before passing it to the application.</p>
  145. *
  146. * @return A string containing the system identifier, or null
  147. * if none is available.
  148. * @see #getPublicId
  149. */
  150. public String getSystemId()
  151. {
  152. return (null == m_locator) ? super.getSystemId() : m_locator.getSystemId();
  153. }
  154. /**
  155. * Return the line number where the current document event ends.
  156. *
  157. * <p><strong>Warning:</strong> The return value from the method
  158. * is intended only as an approximation for the sake of error
  159. * reporting; it is not intended to provide sufficient information
  160. * to edit the character content of the original XML document.</p>
  161. *
  162. * <p>The return value is an approximation of the line number
  163. * in the document entity or external parsed entity where the
  164. * markup triggering the event appears.</p>
  165. *
  166. * @return The line number, or -1 if none is available.
  167. * @see #getColumnNumber
  168. */
  169. public int getLineNumber()
  170. {
  171. return (null == m_locator) ? super.getLineNumber() : m_locator.getLineNumber();
  172. }
  173. /**
  174. * Return the column number where the current document event ends.
  175. *
  176. * <p><strong>Warning:</strong> The return value from the method
  177. * is intended only as an approximation for the sake of error
  178. * reporting; it is not intended to provide sufficient information
  179. * to edit the character content of the original XML document.</p>
  180. *
  181. * <p>The return value is an approximation of the column number
  182. * in the document entity or external parsed entity where the
  183. * markup triggering the event appears.</p>
  184. *
  185. * @return The column number, or -1 if none is available.
  186. * @see #getLineNumber
  187. */
  188. public int getColumnNumber()
  189. {
  190. return (null == m_locator) ? super.getColumnNumber() : m_locator.getColumnNumber();
  191. }
  192. }