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 com.sun.org.apache.xml.internal.utils;
  20. import java.io.Serializable;
  21. import javax.xml.transform.SourceLocator;
  22. import org.xml.sax.Locator;
  23. import org.xml.sax.SAXParseException;
  24. import org.xml.sax.helpers.LocatorImpl;
  25. /**
  26. * Class SAXSourceLocator extends org.xml.sax.helpers.LocatorImpl
  27. * for the purpose of implementing the SourceLocator interface,
  28. * and thus can be both a SourceLocator and a SAX Locator.
  29. */
  30. public class SAXSourceLocator extends LocatorImpl
  31. implements SourceLocator, Serializable
  32. {
  33. /** The SAX Locator object.
  34. * @serial
  35. */
  36. Locator m_locator;
  37. /**
  38. * Constructor SAXSourceLocator
  39. *
  40. */
  41. public SAXSourceLocator(){}
  42. /**
  43. * Constructor SAXSourceLocator
  44. *
  45. *
  46. * @param locator Source locator
  47. */
  48. public SAXSourceLocator(Locator locator)
  49. {
  50. m_locator = locator;
  51. this.setColumnNumber(locator.getColumnNumber());
  52. this.setLineNumber(locator.getLineNumber());
  53. this.setPublicId(locator.getPublicId());
  54. this.setSystemId(locator.getSystemId());
  55. }
  56. /**
  57. * Constructor SAXSourceLocator
  58. *
  59. *
  60. * @param locator Source locator
  61. */
  62. public SAXSourceLocator(javax.xml.transform.SourceLocator locator)
  63. {
  64. m_locator = null;
  65. this.setColumnNumber(locator.getColumnNumber());
  66. this.setLineNumber(locator.getLineNumber());
  67. this.setPublicId(locator.getPublicId());
  68. this.setSystemId(locator.getSystemId());
  69. }
  70. /**
  71. * Constructor SAXSourceLocator
  72. *
  73. *
  74. * @param spe SAXParseException exception.
  75. */
  76. public SAXSourceLocator(SAXParseException spe)
  77. {
  78. this.setLineNumber( spe.getLineNumber() );
  79. this.setColumnNumber( spe.getColumnNumber() );
  80. this.setPublicId( spe.getPublicId() );
  81. this.setSystemId( spe.getSystemId() );
  82. }
  83. /**
  84. * Return the public identifier for the current document event.
  85. *
  86. * <p>The return value is the public identifier of the document
  87. * entity or of the external parsed entity in which the markup
  88. * triggering the event appears.</p>
  89. *
  90. * @return A string containing the public identifier, or
  91. * null if none is available.
  92. * @see #getSystemId
  93. */
  94. public String getPublicId()
  95. {
  96. return (null == m_locator) ? super.getPublicId() : m_locator.getPublicId();
  97. }
  98. /**
  99. * Return the system identifier for the current document event.
  100. *
  101. * <p>The return value is the system identifier of the document
  102. * entity or of the external parsed entity in which the markup
  103. * triggering the event appears.</p>
  104. *
  105. * <p>If the system identifier is a URL, the parser must resolve it
  106. * fully before passing it to the application.</p>
  107. *
  108. * @return A string containing the system identifier, or null
  109. * if none is available.
  110. * @see #getPublicId
  111. */
  112. public String getSystemId()
  113. {
  114. return (null == m_locator) ? super.getSystemId() : m_locator.getSystemId();
  115. }
  116. /**
  117. * Return the line number where the current document event ends.
  118. *
  119. * <p><strong>Warning:</strong> The return value from the method
  120. * is intended only as an approximation for the sake of error
  121. * reporting; it is not intended to provide sufficient information
  122. * to edit the character content of the original XML document.</p>
  123. *
  124. * <p>The return value is an approximation of the line number
  125. * in the document entity or external parsed entity where the
  126. * markup triggering the event appears.</p>
  127. *
  128. * @return The line number, or -1 if none is available.
  129. * @see #getColumnNumber
  130. */
  131. public int getLineNumber()
  132. {
  133. return (null == m_locator) ? super.getLineNumber() : m_locator.getLineNumber();
  134. }
  135. /**
  136. * Return the column number where the current document event ends.
  137. *
  138. * <p><strong>Warning:</strong> The return value from the method
  139. * is intended only as an approximation for the sake of error
  140. * reporting; it is not intended to provide sufficient information
  141. * to edit the character content of the original XML document.</p>
  142. *
  143. * <p>The return value is an approximation of the column number
  144. * in the document entity or external parsed entity where the
  145. * markup triggering the event appears.</p>
  146. *
  147. * @return The column number, or -1 if none is available.
  148. * @see #getLineNumber
  149. */
  150. public int getColumnNumber()
  151. {
  152. return (null == m_locator) ? super.getColumnNumber() : m_locator.getColumnNumber();
  153. }
  154. }