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 Source tree in the
  13. * form of a Document Object Model (DOM) tree.
  14. *
  15. * @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level 2 Specification</a>
  16. */
  17. public class DOMSource implements Source {
  18. /** If {@link javax.xml.transform.TransformerFactory#getFeature}
  19. * returns true when passed this value as an argument,
  20. * the Transformer supports Source input of this type.
  21. */
  22. public static final String FEATURE =
  23. "http://javax.xml.transform.dom.DOMSource/feature";
  24. /**
  25. * Zero-argument default constructor. If this is used, and
  26. * no DOM source is set, then the Transformer will
  27. * create an empty source Document using
  28. * {@link javax.xml.parsers.DocumentBuilder#newDocument}.
  29. */
  30. public DOMSource() {}
  31. /**
  32. * Create a new input source with a DOM node. The operation
  33. * will be applied to the subtree rooted at this node. In XSLT,
  34. * a "/" pattern still means the root of the tree (not the subtree),
  35. * and the evaluation of global variables and parameters is done
  36. * from the root node also.
  37. *
  38. * @param n The DOM node that will contain the Source tree.
  39. */
  40. public DOMSource(Node n) {
  41. setNode(n);
  42. }
  43. /**
  44. * Create a new input source with a DOM node, and with the
  45. * system ID also passed in as the base URI.
  46. *
  47. * @param node The DOM node that will contain the Source tree.
  48. * @param systemID Specifies the base URI associated with node.
  49. */
  50. public DOMSource(Node node, String systemID) {
  51. setNode(node);
  52. setSystemId(systemID);
  53. }
  54. /**
  55. * Set the node that will represents a Source DOM tree.
  56. *
  57. * @param node The node that is to be transformed.
  58. */
  59. public void setNode(Node node) {
  60. this.node = node;
  61. }
  62. /**
  63. * Get the node that represents a Source DOM tree.
  64. *
  65. * @return The node that is to be transformed.
  66. */
  67. public Node getNode() {
  68. return node;
  69. }
  70. /**
  71. * Set the base ID (URL or system ID) from where URLs
  72. * will be resolved.
  73. *
  74. * @param baseID Base URL for this DOM tree.
  75. */
  76. public void setSystemId(String baseID) {
  77. this.baseID = baseID;
  78. }
  79. /**
  80. * Get the base ID (URL or system ID) from where URLs
  81. * will be resolved.
  82. *
  83. * @return Base URL for this DOM tree.
  84. */
  85. public String getSystemId() {
  86. return this.baseID;
  87. }
  88. //////////////////////////////////////////////////////////////////////
  89. // Internal state.
  90. //////////////////////////////////////////////////////////////////////
  91. /**
  92. * Field node
  93. */
  94. private Node node;
  95. /**
  96. * The base ID (URL or system ID) from where URLs
  97. * will be resolved.
  98. */
  99. String baseID;
  100. }