Source Home >> Java Source 1.6.0 >> javax.xml.transform.dom.DOMResult V 0.09
  • 001/*
  • 002 * The contents of this file are subject to the terms
  • 003 * of the Common Development and Distribution License
  • 004 * (the "License"). You may not use this file except
  • 005 * in compliance with the License.
  • 006 *
  • 007 * You can obtain a copy of the license at
  • 008 * https://jaxp.dev.java.net/CDDLv1.0.html.
  • 009 * See the License for the specific language governing
  • 010 * permissions and limitations under the License.
  • 011 *
  • 012 * When distributing Covered Code, include this CDDL
  • 013 * HEADER in each file and include the License file at
  • 014 * https://jaxp.dev.java.net/CDDLv1.0.html
  • 015 * If applicable add the following below this CDDL HEADER
  • 016 * with the fields enclosed by brackets "[]" replaced with
  • 017 * your own identifying information: Portions Copyright
  • 018 * [year] [name of copyright owner]
  • 019 */
  • 020
  • 021/*
  • 022 * $Id: XMLEntityReader.java,v 1.3 2005/11/03 17:02:21 jeffsuttor Exp $
  • 023 * @(#)DOMResult.java 1.23 05/11/17
  • 024 *
  • 025 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
  • 026 */
  • 027
  • 028package javax.xml.transform.dom;
  • 029
  • 030import javax.xml.transform.Result;
  • 031import org.w3c.dom.Node;
  • 032
  • 033/**
  • 034 * <p>Acts as a holder for a transformation result tree in the form of a Document Object Model (DOM) tree.</p>
  • 035 *
  • 036 * <p>If no output DOM source is set, the transformation will create a Document node as the holder for the result of the transformation,
  • 037 * which may be retrieved with {@link #getNode()}.</p>
  • 038 *
  • 039 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
  • 040 * @version $Revision: 1.2 $, $Date: 2005/06/10 03:50:39 $
  • 041 */
  • 042public class DOMResult implements Result {
  • 043
  • 044 /** <p>If {@link javax.xml.transform.TransformerFactory#getFeature}
  • 045 * returns <code>true</code> when passed this value as an argument,
  • 046 * the <code>Transformer</code> supports <code>Result</code> output of this type.</p>
  • 047 */
  • 048 public static final String FEATURE = "http://javax.xml.transform.dom.DOMResult/feature";
  • 049
  • 050 /**
  • 051 * <p>Zero-argument default constructor.</p>
  • 052 *
  • 053 * <p><code>node</code>,
  • 054 * <code>siblingNode</code> and
  • 055 * <code>systemId</code>
  • 056 * will be set to <code>null</code>.</p>
  • 057 */
  • 058 public DOMResult() {
  • 059 setNode(null);
  • 060 setNextSibling(null);
  • 061 setSystemId(null);
  • 062 }
  • 063
  • 064 /**
  • 065 * <p>Use a DOM node to create a new output target.</p>
  • 066 *
  • 067 * <p>In practice, the node should be
  • 068 * a {@link org.w3c.dom.Document} node,
  • 069 * a {@link org.w3c.dom.DocumentFragment} node, or
  • 070 * a {@link org.w3c.dom.Element} node.
  • 071 * In other words, a node that accepts children.</p>
  • 072 *
  • 073 * <p><code>siblingNode</code> and
  • 074 * <code>systemId</code>
  • 075 * will be set to <code>null</code>.</p>
  • 076 *
  • 077 * @param node The DOM node that will contain the result tree.
  • 078 */
  • 079 public DOMResult(Node node) {
  • 080 setNode(node);
  • 081 setNextSibling(null);
  • 082 setSystemId(null);
  • 083 }
  • 084
  • 085 /**
  • 086 * <p>Use a DOM node to create a new output target with the specified System ID.<p>
  • 087 *
  • 088 * <p>In practice, the node should be
  • 089 * a {@link org.w3c.dom.Document} node,
  • 090 * a {@link org.w3c.dom.DocumentFragment} node, or
  • 091 * a {@link org.w3c.dom.Element} node.
  • 092 * In other words, a node that accepts children.</p>
  • 093 *
  • 094 * <p><code>siblingNode</code> will be set to <code>null</code>.</p>
  • 095 *
  • 096 * @param node The DOM node that will contain the result tree.
  • 097 * @param systemId The system identifier which may be used in association with this node.
  • 098 */
  • 099 public DOMResult(Node node, String systemId) {
  • 100 setNode(node);
  • 101 setNextSibling(null);
  • 102 setSystemId(systemId);
  • 103 }
  • 104
  • 105 /**
  • 106 * <p>Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted before.</p>
  • 107 *
  • 108 * <p>In practice, <code>node</code> and <code>nextSibling</code> should be
  • 109 * a {@link org.w3c.dom.Document} node,
  • 110 * a {@link org.w3c.dom.DocumentFragment} node, or
  • 111 * a {@link org.w3c.dom.Element} node.
  • 112 * In other words, a node that accepts children.</p>
  • 113 *
  • 114 * <p>Use <code>nextSibling</code> to specify the child node
  • 115 * where the result nodes should be inserted before.
  • 116 * If <code>nextSibling</code> is not a sibling of <code>node</code>,
  • 117 * then an <code>IllegalArgumentException</code> is thrown.
  • 118 * If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
  • 119 * then an <code>IllegalArgumentException</code> is thrown.
  • 120 * If <code>nextSibling</code> is <code>null</code>,
  • 121 * then the behavior is the same as calling {@link #DOMResult(Node node)},
  • 122 * i.e. append the result nodes as the last child of the specified <code>node</code>.</p>
  • 123 *
  • 124 * <p><code>systemId</code> will be set to <code>null</code>.</p>
  • 125 *
  • 126 * @param node The DOM node that will contain the result tree.
  • 127 * @param nextSibling The child node where the result nodes should be inserted before.
  • 128 *
  • 129 * @throws IllegalArgumentException If <code>nextSibling</code> is not a sibling of <code>node</code> or
  • 130 * <code>node</code> is <code>null</code> and <code>nextSibling</code>
  • 131 * is not <code>null</code>.
  • 132 *
  • 133 * @since 1.5
  • 134 */
  • 135 public DOMResult(Node node, Node nextSibling) {
  • 136
  • 137 // does the corrent parent/child relationship exist?
  • 138 if (nextSibling != null) {
  • 139 // cannot be a sibling of a null node
  • 140 if (node == null) {
  • 141 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
  • 142 }
  • 143
  • 144 // nextSibling contained by node?
  • 145 if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  • 146 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
  • 147 }
  • 148 }
  • 149
  • 150 setNode(node);
  • 151 setNextSibling(nextSibling);
  • 152 setSystemId(null);
  • 153 }
  • 154
  • 155 /**
  • 156 * <p>Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted before and
  • 157 * the specified System ID.</p>
  • 158 *
  • 159 * <p>In practice, <code>node</code> and <code>nextSibling</code> should be
  • 160 * a {@link org.w3c.dom.Document} node,
  • 161 * a {@link org.w3c.dom.DocumentFragment} node, or a
  • 162 * {@link org.w3c.dom.Element} node.
  • 163 * In other words, a node that accepts children.</p>
  • 164 *
  • 165 * <p>Use <code>nextSibling</code> to specify the child node
  • 166 * where the result nodes should be inserted before.
  • 167 * If <code>nextSibling</code> is not a sibling of <code>node</code>,
  • 168 * then an <code>IllegalArgumentException</code> is thrown.
  • 169 * If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
  • 170 * then an <code>IllegalArgumentException</code> is thrown.
  • 171 * If <code>nextSibling</code> is <code>null</code>,
  • 172 * then the behavior is the same as calling {@link #DOMResult(Node node, String systemId)},
  • 173 * i.e. append the result nodes as the last child of the specified node and use the specified System ID.</p>
  • 174 *
  • 175 * @param node The DOM node that will contain the result tree.
  • 176 * @param nextSibling The child node where the result nodes should be inserted before.
  • 177 * @param systemId The system identifier which may be used in association with this node.
  • 178 *
  • 179 * @throws IllegalArgumentException If <code>nextSibling</code> is not a
  • 180 * sibling of <code>node</code> or
  • 181 * <code>node</code> is <code>null</code> and <code>nextSibling</code>
  • 182 * is not <code>null</code>.
  • 183 *
  • 184 * @since 1.5
  • 185 */
  • 186 public DOMResult(Node node, Node nextSibling, String systemId) {
  • 187
  • 188 // does the corrent parent/child relationship exist?
  • 189 if (nextSibling != null) {
  • 190 // cannot be a sibling of a null node
  • 191 if (node == null) {
  • 192 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
  • 193 }
  • 194
  • 195 // nextSibling contained by node?
  • 196 if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  • 197 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
  • 198 }
  • 199 }
  • 200
  • 201 setNode(node);
  • 202 setNextSibling(nextSibling);
  • 203 setSystemId(systemId);
  • 204 }
  • 205
  • 206 /**
  • 207 * <p>Set the node that will contain the result DOM tree.<p>
  • 208 *
  • 209 * <p>In practice, the node should be
  • 210 * a {@link org.w3c.dom.Document} node,
  • 211 * a {@link org.w3c.dom.DocumentFragment} node, or
  • 212 * a {@link org.w3c.dom.Element} node.
  • 213 * In other words, a node that accepts children.</p>
  • 214 *
  • 215 * <p>An <code>IllegalStateException</code> is thrown if
  • 216 * <code>nextSibling</code> is not <code>null</code> and
  • 217 * <code>node</code> is not a parent of <code>nextSibling</code>.
  • 218 * An <code>IllegalStateException</code> is thrown if <code>node</code> is <code>null</code> and
  • 219 * <code>nextSibling</code> is not <code>null</code>.</p>
  • 220 *
  • 221 * @param node The node to which the transformation will be appended.
  • 222 *
  • 223 * @throws IllegalStateException If <code>nextSibling</code> is not
  • 224 * <code>null</code> and
  • 225 * <code>nextSibling</code> is not a child of <code>node</code> or
  • 226 * <code>node</code> is <code>null</code> and
  • 227 * <code>nextSibling</code> is not <code>null</code>.
  • 228 */
  • 229 public void setNode(Node node) {
  • 230 // does the corrent parent/child relationship exist?
  • 231 if (nextSibling != null) {
  • 232 // cannot be a sibling of a null node
  • 233 if (node == null) {
  • 234 throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
  • 235 }
  • 236
  • 237 // nextSibling contained by node?
  • 238 if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  • 239 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
  • 240 }
  • 241 }
  • 242
  • 243 this.node = node;
  • 244 }
  • 245
  • 246 /**
  • 247 * <p>Get the node that will contain the result DOM tree.</p>
  • 248 *
  • 249 * <p>If no node was set via
  • 250 * {@link #DOMResult(Node node)},
  • 251 * {@link #DOMResult(Node node, String systeId)},
  • 252 * {@link #DOMResult(Node node, Node nextSibling)},
  • 253 * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
  • 254 * {@link #setNode(Node node)},
  • 255 * then the node will be set by the transformation, and may be obtained from this method once the transformation is complete.
  • 256 * Calling this method before the transformation will return <code>null</code>.</p>
  • 257 *
  • 258 * @return The node to which the transformation will be appended.
  • 259 */
  • 260 public Node getNode() {
  • 261 return node;
  • 262 }
  • 263
  • 264 /**
  • 265 * <p>Set the child node before which the result nodes will be inserted.</p>
  • 266 *
  • 267 * <p>Use <code>nextSibling</code> to specify the child node
  • 268 * before which the result nodes should be inserted.
  • 269 * If <code>nextSibling</code> is not a descendant of <code>node</code>,
  • 270 * then an <code>IllegalArgumentException</code> is thrown.
  • 271 * If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
  • 272 * then an <code>IllegalStateException</code> is thrown.
  • 273 * If <code>nextSibling</code> is <code>null</code>,
  • 274 * then the behavior is the same as calling {@link #DOMResult(Node node)},
  • 275 * i.e. append the result nodes as the last child of the specified <code>node</code>.</p>
  • 276 *
  • 277 * @param nextSibling The child node before which the result nodes will be inserted.
  • 278 *
  • 279 * @throws IllegalArgumentException If <code>nextSibling</code> is not a
  • 280 * descendant of <code>node</code>.
  • 281 * @throws IllegalStateException If <code>node</code> is <code>null</code>
  • 282 * and <code>nextSibling</code> is not <code>null</code>.
  • 283 *
  • 284 * @since 1.5
  • 285 */
  • 286 public void setNextSibling(Node nextSibling) {
  • 287
  • 288 // does the corrent parent/child relationship exist?
  • 289 if (nextSibling != null) {
  • 290 // cannot be a sibling of a null node
  • 291 if (node == null) {
  • 292 throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
  • 293 }
  • 294
  • 295 // nextSibling contained by node?
  • 296 if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
  • 297 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
  • 298 }
  • 299 }
  • 300
  • 301 this.nextSibling = nextSibling;
  • 302 }
  • 303
  • 304 /**
  • 305 * <p>Get the child node before which the result nodes will be inserted.</p>
  • 306 *
  • 307 * <p>If no node was set via
  • 308 * {@link #DOMResult(Node node, Node nextSibling)},
  • 309 * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
  • 310 * {@link #setNextSibling(Node nextSibling)},
  • 311 * then <code>null</code> will be returned.</p>
  • 312 *
  • 313 * @return The child node before which the result nodes will be inserted.
  • 314 *
  • 315 * @since 1.5
  • 316 */
  • 317 public Node getNextSibling() {
  • 318 return nextSibling;
  • 319 }
  • 320
  • 321 /**
  • 322 * <p>Set the systemId that may be used in association with the node.</p>
  • 323 *
  • 324 * @param systemId The system identifier as a URI string.
  • 325 */
  • 326 public void setSystemId(String systemId) {
  • 327 this.systemId = systemId;
  • 328 }
  • 329
  • 330 /**
  • 331 * <p>Get the System Identifier.</p>
  • 332 *
  • 333 * <p>If no System ID was set via
  • 334 * {@link #DOMResult(Node node, String systemId)},
  • 335 * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
  • 336 * {@link #setSystemId(String systemId)},
  • 337 * then <code>null</code> will be returned.</p>
  • 338 *
  • 339 * @return The system identifier.
  • 340 */
  • 341 public String getSystemId() {
  • 342 return systemId;
  • 343 }
  • 344
  • 345 //////////////////////////////////////////////////////////////////////
  • 346 // Internal state.
  • 347 //////////////////////////////////////////////////////////////////////
  • 348
  • 349 /**
  • 350 * <p>The node to which the transformation will be appended.</p>
  • 351 */
  • 352 private Node node = null;
  • 353
  • 354 /**
  • 355 * <p>The child node before which the result nodes will be inserted.</p>
  • 356 *
  • 357 * @since 1.5
  • 358 */
  • 359 private Node nextSibling = null;
  • 360
  • 361 /**
  • 362 * <p>The System ID that may be used in association with the node.</p>
  • 363 */
  • 364 private String systemId = null;
  • 365}

文件:DOMResult.java
包名:javax.xml.transform.dom
类名:DOMResult
继承:
接口:[Result]