Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/transform/dom/DOMSource.java
32288 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.transform.dom;2627import javax.xml.transform.Source;2829import org.w3c.dom.Node;3031/**32* <p>Acts as a holder for a transformation Source tree in the33* form of a Document Object Model (DOM) tree.</p>34*35* <p>Note that XSLT requires namespace support. Attempting to transform a DOM36* that was not contructed with a namespace-aware parser may result in errors.37* Parsers can be made namespace aware by calling38* {@link javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean awareness)}.</p>39*40* @author <a href="[email protected]">Jeff Suttor</a>41* @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level 2 Specification</a>42*/43public class DOMSource implements Source {4445/**46* <p><code>Node</code> to serve as DOM source.</p>47*/48private Node node;4950/**51* <p>The base ID (URL or system ID) from where URLs52* will be resolved.</p>53*/54private String systemID;5556/** If {@link javax.xml.transform.TransformerFactory#getFeature}57* returns true when passed this value as an argument,58* the Transformer supports Source input of this type.59*/60public static final String FEATURE =61"http://javax.xml.transform.dom.DOMSource/feature";6263/**64* <p>Zero-argument default constructor. If this constructor is used, and65* no DOM source is set using {@link #setNode(Node node)} , then the66* <code>Transformer</code> will67* create an empty source {@link org.w3c.dom.Document} using68* {@link javax.xml.parsers.DocumentBuilder#newDocument()}.</p>69*70* @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)71*/72public DOMSource() { }7374/**75* Create a new input source with a DOM node. The operation76* will be applied to the subtree rooted at this node. In XSLT,77* a "/" pattern still means the root of the tree (not the subtree),78* and the evaluation of global variables and parameters is done79* from the root node also.80*81* @param n The DOM node that will contain the Source tree.82*/83public DOMSource(Node n) {84setNode(n);85}8687/**88* Create a new input source with a DOM node, and with the89* system ID also passed in as the base URI.90*91* @param node The DOM node that will contain the Source tree.92* @param systemID Specifies the base URI associated with node.93*/94public DOMSource(Node node, String systemID) {95setNode(node);96setSystemId(systemID);97}9899/**100* Set the node that will represents a Source DOM tree.101*102* @param node The node that is to be transformed.103*/104public void setNode(Node node) {105this.node = node;106}107108/**109* Get the node that represents a Source DOM tree.110*111* @return The node that is to be transformed.112*/113public Node getNode() {114return node;115}116117/**118* Set the base ID (URL or system ID) from where URLs119* will be resolved.120*121* @param systemID Base URL for this DOM tree.122*/123public void setSystemId(String systemID) {124this.systemID = systemID;125}126127/**128* Get the base ID (URL or system ID) from where URLs129* will be resolved.130*131* @return Base URL for this DOM tree.132*/133public String getSystemId() {134return this.systemID;135}136}137138139