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