1. // $Id: DOMSource.java,v 1.5.14.1.2.2 2004/07/13 22:27:49 jsuttor Exp $
  2. /*
  3. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  4. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  5. */
  6. /*
  7. * @(#)DOMSource.java 1.16 04/07/13
  8. */
  9. package javax.xml.transform.dom;
  10. import javax.xml.transform.Source;
  11. import org.w3c.dom.Node;
  12. /**
  13. * <p>Acts as a holder for a transformation Source tree in the
  14. * form of a Document Object Model (DOM) tree.</p>
  15. *
  16. * <p>Note that XSLT requires namespace support. Attempting to transform a DOM
  17. * that was not contructed with a namespace-aware parser may result in errors.
  18. * Parsers can be made namespace aware by calling
  19. * {@link javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean awareness)}.</p>
  20. *
  21. * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
  22. * @version $Revision: 1.5.14.1.2.2 $, $Date: 2004/07/13 22:27:49 $
  23. * @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level 2 Specification</a>
  24. */
  25. public class DOMSource implements Source {
  26. /**
  27. * <p><code>Node</code> to serve as DOM source.</p>
  28. */
  29. private Node node;
  30. /**
  31. * <p>The base ID (URL or system ID) from where URLs
  32. * will be resolved.</p>
  33. */
  34. private String systemID;
  35. /** If {@link javax.xml.transform.TransformerFactory#getFeature}
  36. * returns true when passed this value as an argument,
  37. * the Transformer supports Source input of this type.
  38. */
  39. public static final String FEATURE =
  40. "http://javax.xml.transform.dom.DOMSource/feature";
  41. /**
  42. * <p>Zero-argument default constructor. If this constructor is used, and
  43. * no DOM source is set using {@link #setNode(Node node)} , then the
  44. * <code>Transformer</code> will
  45. * create an empty source {@link org.w3c.dom.Document} using
  46. * {@link javax.xml.parsers.DocumentBuilder#newDocument()}.</p>
  47. *
  48. * @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
  49. */
  50. public DOMSource() { }
  51. /**
  52. * Create a new input source with a DOM node. The operation
  53. * will be applied to the subtree rooted at this node. In XSLT,
  54. * a "/" pattern still means the root of the tree (not the subtree),
  55. * and the evaluation of global variables and parameters is done
  56. * from the root node also.
  57. *
  58. * @param n The DOM node that will contain the Source tree.
  59. */
  60. public DOMSource(Node n) {
  61. setNode(n);
  62. }
  63. /**
  64. * Create a new input source with a DOM node, and with the
  65. * system ID also passed in as the base URI.
  66. *
  67. * @param node The DOM node that will contain the Source tree.
  68. * @param systemID Specifies the base URI associated with node.
  69. */
  70. public DOMSource(Node node, String systemID) {
  71. setNode(node);
  72. setSystemId(systemID);
  73. }
  74. /**
  75. * Set the node that will represents a Source DOM tree.
  76. *
  77. * @param node The node that is to be transformed.
  78. */
  79. public void setNode(Node node) {
  80. this.node = node;
  81. }
  82. /**
  83. * Get the node that represents a Source DOM tree.
  84. *
  85. * @return The node that is to be transformed.
  86. */
  87. public Node getNode() {
  88. return node;
  89. }
  90. /**
  91. * Set the base ID (URL or system ID) from where URLs
  92. * will be resolved.
  93. *
  94. * @param systemID Base URL for this DOM tree.
  95. */
  96. public void setSystemId(String systemID) {
  97. this.systemID = systemID;
  98. }
  99. /**
  100. * Get the base ID (URL or system ID) from where URLs
  101. * will be resolved.
  102. *
  103. * @return Base URL for this DOM tree.
  104. */
  105. public String getSystemId() {
  106. return this.systemID;
  107. }
  108. }