1. // SAX default implementation for Locator.
  2. // http://www.saxproject.org
  3. // No warranty; no copyright -- use this as you will.
  4. // $Id: LocatorImpl.java,v 1.1.24.1 2004/05/01 08:34:45 jsuttor Exp $
  5. package org.xml.sax.helpers;
  6. import org.xml.sax.Locator;
  7. /**
  8. * Provide an optional convenience implementation of Locator.
  9. *
  10. * <blockquote>
  11. * <em>This module, both source code and documentation, is in the
  12. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  13. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  14. * for further information.
  15. * </blockquote>
  16. *
  17. * <p>This class is available mainly for application writers, who
  18. * can use it to make a persistent snapshot of a locator at any
  19. * point during a document parse:</p>
  20. *
  21. * <pre>
  22. * Locator locator;
  23. * Locator startloc;
  24. *
  25. * public void setLocator (Locator locator)
  26. * {
  27. * // note the locator
  28. * this.locator = locator;
  29. * }
  30. *
  31. * public void startDocument ()
  32. * {
  33. * // save the location of the start of the document
  34. * // for future use.
  35. * Locator startloc = new LocatorImpl(locator);
  36. * }
  37. *</pre>
  38. *
  39. * <p>Normally, parser writers will not use this class, since it
  40. * is more efficient to provide location information only when
  41. * requested, rather than constantly updating a Locator object.</p>
  42. *
  43. * @since SAX 1.0
  44. * @author David Megginson
  45. * @version 2.0.1 (sax2r2)
  46. * @see org.xml.sax.Locator Locator
  47. */
  48. public class LocatorImpl implements Locator
  49. {
  50. /**
  51. * Zero-argument constructor.
  52. *
  53. * <p>This will not normally be useful, since the main purpose
  54. * of this class is to make a snapshot of an existing Locator.</p>
  55. */
  56. public LocatorImpl ()
  57. {
  58. }
  59. /**
  60. * Copy constructor.
  61. *
  62. * <p>Create a persistent copy of the current state of a locator.
  63. * When the original locator changes, this copy will still keep
  64. * the original values (and it can be used outside the scope of
  65. * DocumentHandler methods).</p>
  66. *
  67. * @param locator The locator to copy.
  68. */
  69. public LocatorImpl (Locator locator)
  70. {
  71. setPublicId(locator.getPublicId());
  72. setSystemId(locator.getSystemId());
  73. setLineNumber(locator.getLineNumber());
  74. setColumnNumber(locator.getColumnNumber());
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Implementation of org.xml.sax.Locator
  78. ////////////////////////////////////////////////////////////////////
  79. /**
  80. * Return the saved public identifier.
  81. *
  82. * @return The public identifier as a string, or null if none
  83. * is available.
  84. * @see org.xml.sax.Locator#getPublicId
  85. * @see #setPublicId
  86. */
  87. public String getPublicId ()
  88. {
  89. return publicId;
  90. }
  91. /**
  92. * Return the saved system identifier.
  93. *
  94. * @return The system identifier as a string, or null if none
  95. * is available.
  96. * @see org.xml.sax.Locator#getSystemId
  97. * @see #setSystemId
  98. */
  99. public String getSystemId ()
  100. {
  101. return systemId;
  102. }
  103. /**
  104. * Return the saved line number (1-based).
  105. *
  106. * @return The line number as an integer, or -1 if none is available.
  107. * @see org.xml.sax.Locator#getLineNumber
  108. * @see #setLineNumber
  109. */
  110. public int getLineNumber ()
  111. {
  112. return lineNumber;
  113. }
  114. /**
  115. * Return the saved column number (1-based).
  116. *
  117. * @return The column number as an integer, or -1 if none is available.
  118. * @see org.xml.sax.Locator#getColumnNumber
  119. * @see #setColumnNumber
  120. */
  121. public int getColumnNumber ()
  122. {
  123. return columnNumber;
  124. }
  125. ////////////////////////////////////////////////////////////////////
  126. // Setters for the properties (not in org.xml.sax.Locator)
  127. ////////////////////////////////////////////////////////////////////
  128. /**
  129. * Set the public identifier for this locator.
  130. *
  131. * @param publicId The new public identifier, or null
  132. * if none is available.
  133. * @see #getPublicId
  134. */
  135. public void setPublicId (String publicId)
  136. {
  137. this.publicId = publicId;
  138. }
  139. /**
  140. * Set the system identifier for this locator.
  141. *
  142. * @param systemId The new system identifier, or null
  143. * if none is available.
  144. * @see #getSystemId
  145. */
  146. public void setSystemId (String systemId)
  147. {
  148. this.systemId = systemId;
  149. }
  150. /**
  151. * Set the line number for this locator (1-based).
  152. *
  153. * @param lineNumber The line number, or -1 if none is available.
  154. * @see #getLineNumber
  155. */
  156. public void setLineNumber (int lineNumber)
  157. {
  158. this.lineNumber = lineNumber;
  159. }
  160. /**
  161. * Set the column number for this locator (1-based).
  162. *
  163. * @param columnNumber The column number, or -1 if none is available.
  164. * @see #getColumnNumber
  165. */
  166. public void setColumnNumber (int columnNumber)
  167. {
  168. this.columnNumber = columnNumber;
  169. }
  170. ////////////////////////////////////////////////////////////////////
  171. // Internal state.
  172. ////////////////////////////////////////////////////////////////////
  173. private String publicId;
  174. private String systemId;
  175. private int lineNumber;
  176. private int columnNumber;
  177. }
  178. // end of LocatorImpl.java