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