1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 // $Id: DOMSource.java 446598 2006-09-15 12:55:40Z jeremias $
19 
20 package javax.xml.transform.dom;
21 
22 import javax.xml.transform.Source;
23 import org.w3c.dom.Node;
24 
25 /**
26  * <p>Acts as a holder for a transformation Source tree in the
27  * form of a Document Object Model (DOM) tree.</p>
28  *
29  * <p>Note that XSLT requires namespace support. Attempting to transform a DOM
30  * that was not contructed with a namespace-aware parser may result in errors.
31  * Parsers can be made namespace aware by calling
32  * {@link javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean awareness)}.</p>
33  *
34  * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
35  * @version $Revision: 446598 $, $Date: 2006-09-15 05:55:40 -0700 (Fri, 15 Sep 2006) $
36  * @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level 2 Specification</a>
37  */
38 public class DOMSource implements Source {
39 
40     /**
41      * <p><code>Node</code> to serve as DOM source.</p>
42      */
43     private Node node;
44 
45     /**
46      * <p>The base ID (URL or system ID) from where URLs
47      * will be resolved.</p>
48      */
49     private String systemID;
50 
51     /** If {@link javax.xml.transform.TransformerFactory#getFeature}
52      * returns true when passed this value as an argument,
53      * the Transformer supports Source input of this type.
54      */
55     public static final String FEATURE =
56         "http://javax.xml.transform.dom.DOMSource/feature";
57 
58     /**
59      * <p>Zero-argument default constructor.  If this constructor is used, and
60      * no DOM source is set using {@link #setNode(Node node)} , then the
61      * <code>Transformer</code> will
62      * create an empty source {@link org.w3c.dom.Document} using
63      * {@link javax.xml.parsers.DocumentBuilder#newDocument()}.</p>
64      *
65      * @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
66      */
DOMSource()67     public DOMSource() { }
68 
69     /**
70      * Create a new input source with a DOM node.  The operation
71      * will be applied to the subtree rooted at this node.  In XSLT,
72      * a "/" pattern still means the root of the tree (not the subtree),
73      * and the evaluation of global variables and parameters is done
74      * from the root node also.
75      *
76      * @param n The DOM node that will contain the Source tree.
77      */
DOMSource(Node n)78     public DOMSource(Node n) {
79         setNode(n);
80     }
81 
82     /**
83      * Create a new input source with a DOM node, and with the
84      * system ID also passed in as the base URI.
85      *
86      * @param node The DOM node that will contain the Source tree.
87      * @param systemID Specifies the base URI associated with node.
88      */
DOMSource(Node node, String systemID)89     public DOMSource(Node node, String systemID) {
90         setNode(node);
91         setSystemId(systemID);
92     }
93 
94     /**
95      * Set the node that will represents a Source DOM tree.
96      *
97      * @param node The node that is to be transformed.
98      */
setNode(Node node)99     public void setNode(Node node) {
100         this.node = node;
101     }
102 
103     /**
104      * Get the node that represents a Source DOM tree.
105      *
106      * @return The node that is to be transformed.
107      */
getNode()108     public Node getNode() {
109         return node;
110     }
111 
112     /**
113      * Set the base ID (URL or system ID) from where URLs
114      * will be resolved.
115      *
116      * @param systemID Base URL for this DOM tree.
117      */
setSystemId(String systemID)118     public void setSystemId(String systemID) {
119         this.systemID = systemID;
120     }
121 
122     /**
123      * Get the base ID (URL or system ID) from where URLs
124      * will be resolved.
125      *
126      * @return Base URL for this DOM tree.
127      */
getSystemId()128     public String getSystemId() {
129         return this.systemID;
130     }
131 }
132