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