1. // $Id: SAXResult.java,v 1.2.24.1 2004/07/13 22:27:50 jsuttor Exp $
  2. /*
  3. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  4. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  5. */
  6. /*
  7. * @(#)SAXResult.java 1.13 04/07/13
  8. */
  9. package javax.xml.transform.sax;
  10. import javax.xml.transform.Result;
  11. import org.xml.sax.ContentHandler;
  12. import org.xml.sax.ext.LexicalHandler;
  13. /**
  14. * <p>Acts as an holder for a transformation Result.</p>
  15. *
  16. * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
  17. */
  18. public class SAXResult implements Result {
  19. /**
  20. * If {@link javax.xml.transform.TransformerFactory#getFeature}
  21. * returns true when passed this value as an argument,
  22. * the Transformer supports Result output of this type.
  23. */
  24. public static final String FEATURE =
  25. "http://javax.xml.transform.sax.SAXResult/feature";
  26. /**
  27. * Zero-argument default constructor.
  28. */
  29. public SAXResult() {
  30. }
  31. /**
  32. * Create a SAXResult that targets a SAX2 {@link org.xml.sax.ContentHandler}.
  33. *
  34. * @param handler Must be a non-null ContentHandler reference.
  35. */
  36. public SAXResult(ContentHandler handler) {
  37. setHandler(handler);
  38. }
  39. /**
  40. * Set the target to be a SAX2 {@link org.xml.sax.ContentHandler}.
  41. *
  42. * @param handler Must be a non-null ContentHandler reference.
  43. */
  44. public void setHandler(ContentHandler handler) {
  45. this.handler = handler;
  46. }
  47. /**
  48. * Get the {@link org.xml.sax.ContentHandler} that is the Result.
  49. *
  50. * @return The ContentHandler that is to be transformation output.
  51. */
  52. public ContentHandler getHandler() {
  53. return handler;
  54. }
  55. /**
  56. * Set the SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output.
  57. *
  58. * <p>This is needed to handle XML comments and the like. If the
  59. * lexical handler is not set, an attempt should be made by the
  60. * transformer to cast the {@link org.xml.sax.ContentHandler} to a
  61. * <code>LexicalHandler</code>.</p>
  62. *
  63. * @param handler A non-null <code>LexicalHandler</code> for
  64. * handling lexical parse events.
  65. */
  66. public void setLexicalHandler(LexicalHandler handler) {
  67. this.lexhandler = handler;
  68. }
  69. /**
  70. * Get a SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output.
  71. *
  72. * @return A <code>LexicalHandler</code>, or null.
  73. */
  74. public LexicalHandler getLexicalHandler() {
  75. return lexhandler;
  76. }
  77. /**
  78. * Method setSystemId Set the systemID that may be used in association
  79. * with the {@link org.xml.sax.ContentHandler}.
  80. *
  81. * @param systemId The system identifier as a URI string.
  82. */
  83. public void setSystemId(String systemId) {
  84. this.systemId = systemId;
  85. }
  86. /**
  87. * Get the system identifier that was set with setSystemId.
  88. *
  89. * @return The system identifier that was set with setSystemId, or null
  90. * if setSystemId was not called.
  91. */
  92. public String getSystemId() {
  93. return systemId;
  94. }
  95. //////////////////////////////////////////////////////////////////////
  96. // Internal state.
  97. //////////////////////////////////////////////////////////////////////
  98. /**
  99. * The handler for parse events.
  100. */
  101. private ContentHandler handler;
  102. /**
  103. * The handler for lexical events.
  104. */
  105. private LexicalHandler lexhandler;
  106. /**
  107. * The systemID that may be used in association
  108. * with the node.
  109. */
  110. private String systemId;
  111. }