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