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.dom;
  6. import javax.xml.transform.*;
  7. import java.lang.String;
  8. import java.io.OutputStream;
  9. import java.io.Writer;
  10. import org.w3c.dom.Node;
  11. /**
  12. * Acts as a holder for a transformation result tree, in the
  13. * form of a Document Object Model (DOM) tree. If no output DOM source is set,
  14. * the transformation will create a Document node as the holder
  15. * for the result of the transformation, which may be retrieved
  16. * with getNode.
  17. */
  18. public class DOMResult implements Result {
  19. /** If {@link javax.xml.transform.TransformerFactory#getFeature}
  20. * returns true when passed this value as an argument,
  21. * the Transformer supports Result output of this type.
  22. */
  23. public static final String FEATURE =
  24. "http://javax.xml.transform.dom.DOMResult/feature";
  25. /**
  26. * Zero-argument default constructor.
  27. */
  28. public DOMResult() {}
  29. /**
  30. * Use a DOM node to create a new output target. In practice,
  31. * the node should be a {@link org.w3c.dom.Document} node,
  32. * a {@link org.w3c.dom.DocumentFragment} node, or a
  33. * {@link org.w3c.dom.Element} node. In other words, a node
  34. * that accepts children.
  35. *
  36. * @param n The DOM node that will contain the result tree.
  37. */
  38. public DOMResult(Node node) {
  39. setNode(node);
  40. }
  41. /**
  42. * Create a new output target with a DOM node. In practice,
  43. * the node should be a {@link org.w3c.dom.Document} node,
  44. * a {@link org.w3c.dom.DocumentFragment} node, or a
  45. * {@link org.w3c.dom.Element} node. In other words, a node
  46. * that accepts children.
  47. *
  48. * @param node The DOM node that will contain the result tree.
  49. * @param systemID The system identifier which may be used in association
  50. * with this node.
  51. */
  52. public DOMResult(Node node, String systemID) {
  53. setNode(node);
  54. setSystemId(systemID);
  55. }
  56. /**
  57. * Set the node that will contain the result DOM tree. In practice,
  58. * the node should be a {@link org.w3c.dom.Document} node,
  59. * a {@link org.w3c.dom.DocumentFragment} node, or a
  60. * {@link org.w3c.dom.Element} node. In other words, a node
  61. * that accepts children.
  62. *
  63. * @param node The node to which the transformation
  64. * will be appended.
  65. */
  66. public void setNode(Node node) {
  67. this.node = node;
  68. }
  69. /**
  70. * Get the node that will contain the result DOM tree.
  71. * If no node was set via setNode, the node will be
  72. * set by the transformation, and may be obtained from
  73. * this method once the transformation is complete.
  74. *
  75. * @return The node to which the transformation
  76. * will be appended.
  77. */
  78. public Node getNode() {
  79. return node;
  80. }
  81. /**
  82. * Method setSystemId Set the systemID that may be used in association
  83. * with the node.
  84. *
  85. * @param systemId The system identifier as a URI string.
  86. */
  87. public void setSystemId(String systemId) {
  88. this.systemId = systemId;
  89. }
  90. /**
  91. * Get the system identifier that was set with setSystemId.
  92. *
  93. * @return The system identifier that was set with setSystemId, or null
  94. * if setSystemId was not called.
  95. */
  96. public String getSystemId() {
  97. return systemId;
  98. }
  99. //////////////////////////////////////////////////////////////////////
  100. // Internal state.
  101. //////////////////////////////////////////////////////////////////////
  102. /**
  103. * The node to which the transformation will be appended.
  104. */
  105. private Node node;
  106. /**
  107. * The systemID that may be used in association
  108. * with the node.
  109. */
  110. private String systemId;
  111. }