001 /*
002 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.xml.transform.dom;
027
028 import javax.xml.transform.Source;
029
030 import org.w3c.dom.Node;
031
032 /**
033 * <p>Acts as a holder for a transformation Source tree in the
034 * form of a Document Object Model (DOM) tree.</p>
035 *
036 * <p>Note that XSLT requires namespace support. Attempting to transform a DOM
037 * that was not contructed with a namespace-aware parser may result in errors.
038 * Parsers can be made namespace aware by calling
039 * {@link javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean awareness)}.</p>
040 *
041 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
042 * @version $Revision: 1.2 $, $Date: 2005/06/10 03:50:40 $
043 * @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level 2 Specification</a>
044 */
045 public class DOMSource implements Source {
046
047 /**
048 * <p><code>Node</code> to serve as DOM source.</p>
049 */
050 private Node node;
051
052 /**
053 * <p>The base ID (URL or system ID) from where URLs
054 * will be resolved.</p>
055 */
056 private String systemID;
057
058 /** If {@link javax.xml.transform.TransformerFactory#getFeature}
059 * returns true when passed this value as an argument,
060 * the Transformer supports Source input of this type.
061 */
062 public static final String FEATURE = "http://javax.xml.transform.dom.DOMSource/feature";
063
064 /**
065 * <p>Zero-argument default constructor. If this constructor is used, and
066 * no DOM source is set using {@link #setNode(Node node)} , then the
067 * <code>Transformer</code> will
068 * create an empty source {@link org.w3c.dom.Document} using
069 * {@link javax.xml.parsers.DocumentBuilder#newDocument()}.</p>
070 *
071 * @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
072 */
073 public DOMSource() {
074 }
075
076 /**
077 * Create a new input source with a DOM node. The operation
078 * will be applied to the subtree rooted at this node. In XSLT,
079 * a "/" pattern still means the root of the tree (not the subtree),
080 * and the evaluation of global variables and parameters is done
081 * from the root node also.
082 *
083 * @param n The DOM node that will contain the Source tree.
084 */
085 public DOMSource(Node n) {
086 setNode(n);
087 }
088
089 /**
090 * Create a new input source with a DOM node, and with the
091 * system ID also passed in as the base URI.
092 *
093 * @param node The DOM node that will contain the Source tree.
094 * @param systemID Specifies the base URI associated with node.
095 */
096 public DOMSource(Node node, String systemID) {
097 setNode(node);
098 setSystemId(systemID);
099 }
100
101 /**
102 * Set the node that will represents a Source DOM tree.
103 *
104 * @param node The node that is to be transformed.
105 */
106 public void setNode(Node node) {
107 this .node = node;
108 }
109
110 /**
111 * Get the node that represents a Source DOM tree.
112 *
113 * @return The node that is to be transformed.
114 */
115 public Node getNode() {
116 return node;
117 }
118
119 /**
120 * Set the base ID (URL or system ID) from where URLs
121 * will be resolved.
122 *
123 * @param systemID Base URL for this DOM tree.
124 */
125 public void setSystemId(String systemID) {
126 this .systemID = systemID;
127 }
128
129 /**
130 * Get the base ID (URL or system ID) from where URLs
131 * will be resolved.
132 *
133 * @return Base URL for this DOM tree.
134 */
135 public String getSystemId() {
136 return this.systemID;
137 }
138 }
|