< prev index next >

src/java.xml/share/classes/javax/xml/transform/dom/DOMResult.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.xml.transform.dom;
  27 
  28 import javax.xml.transform.Result;
  29 import org.w3c.dom.Node;
  30 
  31 /**
  32  * <p>Acts as a holder for a transformation result tree in the form of a Document Object Model (DOM) tree.</p>

  33  *
  34  * <p>If no output DOM source is set, the transformation will create a Document node as the holder for the result of the transformation,
  35  * which may be retrieved with {@link #getNode()}.</p>

  36  *
  37  * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
  38  * @since 1.4
  39  */
  40 public class DOMResult implements Result {
  41 
  42     /** <p>If {@link javax.xml.transform.TransformerFactory#getFeature}
  43      * returns <code>true</code> when passed this value as an argument,
  44      * the <code>Transformer</code> supports <code>Result</code> output of this type.</p>

  45      */
  46     public static final String FEATURE = "http://javax.xml.transform.dom.DOMResult/feature";
  47 
  48     /**
  49      * <p>Zero-argument default constructor.</p>
  50      *
  51      * <p><code>node</code>,
  52      * <code>siblingNode</code> and
  53      * <code>systemId</code>
  54      * will be set to <code>null</code>.</p>
  55      */
  56     public DOMResult() {
  57         setNode(null);
  58         setNextSibling(null);
  59         setSystemId(null);
  60     }
  61 
  62     /**
  63      * <p>Use a DOM node to create a new output target.</p>
  64      *
  65      * <p>In practice, the node should be
  66      * a {@link org.w3c.dom.Document} node,
  67      * a {@link org.w3c.dom.DocumentFragment} node, or
  68      * a {@link org.w3c.dom.Element} node.
  69      * In other words, a node that accepts children.</p>
  70      *
  71      * <p><code>siblingNode</code> and
  72      * <code>systemId</code>
  73      * will be set to <code>null</code>.</p>
  74      *
  75      * @param node The DOM node that will contain the result tree.
  76      */
  77     public DOMResult(Node node) {
  78         setNode(node);
  79         setNextSibling(null);
  80         setSystemId(null);
  81     }
  82 
  83     /**
  84      * <p>Use a DOM node to create a new output target with the specified System ID.<p>
  85      *
  86      * <p>In practice, the node should be
  87      * a {@link org.w3c.dom.Document} node,
  88      * a {@link org.w3c.dom.DocumentFragment} node, or
  89      * a {@link org.w3c.dom.Element} node.
  90      * In other words, a node that accepts children.</p>
  91      *
  92      * <p><code>siblingNode</code> will be set to <code>null</code>.</p>
  93      *
  94      * @param node The DOM node that will contain the result tree.
  95      * @param systemId The system identifier which may be used in association with this node.
  96      */
  97     public DOMResult(Node node, String systemId) {
  98         setNode(node);
  99         setNextSibling(null);
 100         setSystemId(systemId);
 101     }
 102 
 103     /**
 104      * <p>Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted before.</p>

 105      *
 106      * <p>In practice, <code>node</code> and <code>nextSibling</code> should be
 107      * a {@link org.w3c.dom.Document} node,
 108      * a {@link org.w3c.dom.DocumentFragment} node, or
 109      * a {@link org.w3c.dom.Element} node.
 110      * In other words, a node that accepts children.</p>
 111      *
 112      * <p>Use <code>nextSibling</code> to specify the child node
 113      * where the result nodes should be inserted before.
 114      * If <code>nextSibling</code> is not a sibling of <code>node</code>,
 115      * then an <code>IllegalArgumentException</code> is thrown.
 116      * If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
 117      * then an <code>IllegalArgumentException</code> is thrown.
 118      * If <code>nextSibling</code> is <code>null</code>,
 119      * then the behavior is the same as calling {@link #DOMResult(Node node)},
 120      * i.e. append the result nodes as the last child of the specified <code>node</code>.</p>
 121      *
 122      * <p><code>systemId</code> will be set to <code>null</code>.</p>
 123      *
 124      * @param node The DOM node that will contain the result tree.
 125      * @param nextSibling The child node where the result nodes should be inserted before.
 126      *
 127      * @throws IllegalArgumentException If <code>nextSibling</code> is not a sibling of <code>node</code> or
 128      *   <code>node</code> is <code>null</code> and <code>nextSibling</code>
 129      *   is not <code>null</code>.
 130      *
 131      * @since 1.5
 132      */
 133     public DOMResult(Node node, Node nextSibling) {
 134 
 135         // does the corrent parent/child relationship exist?
 136         if (nextSibling != null) {
 137             // cannot be a sibling of a null node
 138             if (node == null) {
 139                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 140             }
 141 
 142             // nextSibling contained by node?
 143             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 144                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 145             }
 146         }
 147 
 148         setNode(node);
 149         setNextSibling(nextSibling);
 150         setSystemId(null);
 151     }
 152 
 153     /**
 154      * <p>Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted before and
 155      * the specified System ID.</p>

 156      *
 157      * <p>In practice, <code>node</code> and <code>nextSibling</code> should be
 158      * a {@link org.w3c.dom.Document} node,
 159      * a {@link org.w3c.dom.DocumentFragment} node, or a
 160      * {@link org.w3c.dom.Element} node.
 161      * In other words, a node that accepts children.</p>
 162      *
 163      * <p>Use <code>nextSibling</code> to specify the child node
 164      * where the result nodes should be inserted before.
 165      * If <code>nextSibling</code> is not a sibling of <code>node</code>,
 166      * then an <code>IllegalArgumentException</code> is thrown.
 167      * If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
 168      * then an <code>IllegalArgumentException</code> is thrown.
 169      * If <code>nextSibling</code> is <code>null</code>,
 170      * then the behavior is the same as calling {@link #DOMResult(Node node, String systemId)},
 171      * i.e. append the result nodes as the last child of the specified node and use the specified System ID.</p>

 172      *
 173      * @param node The DOM node that will contain the result tree.
 174      * @param nextSibling The child node where the result nodes should be inserted before.
 175      * @param systemId The system identifier which may be used in association with this node.
 176      *
 177      * @throws IllegalArgumentException If <code>nextSibling</code> is not a
 178      *   sibling of <code>node</code> or
 179      *   <code>node</code> is <code>null</code> and <code>nextSibling</code>
 180      *   is not <code>null</code>.
 181      *
 182      * @since 1.5
 183      */
 184     public DOMResult(Node node, Node nextSibling, String systemId) {
 185 
 186         // does the corrent parent/child relationship exist?
 187         if (nextSibling != null) {
 188             // cannot be a sibling of a null node
 189             if (node == null) {
 190                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 191             }
 192 
 193             // nextSibling contained by node?
 194             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 195                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 196             }
 197         }
 198 
 199         setNode(node);
 200         setNextSibling(nextSibling);
 201         setSystemId(systemId);
 202     }
 203 
 204     /**
 205      * <p>Set the node that will contain the result DOM tree.<p>
 206      *
 207      * <p>In practice, the node should be
 208      * a {@link org.w3c.dom.Document} node,
 209      * a {@link org.w3c.dom.DocumentFragment} node, or
 210      * a {@link org.w3c.dom.Element} node.
 211      * In other words, a node that accepts children.</p>
 212      *
 213      * <p>An <code>IllegalStateException</code> is thrown if
 214      * <code>nextSibling</code> is not <code>null</code> and
 215      * <code>node</code> is not a parent of <code>nextSibling</code>.
 216      * An <code>IllegalStateException</code> is thrown if <code>node</code> is <code>null</code> and
 217      * <code>nextSibling</code> is not <code>null</code>.</p>
 218      *
 219      * @param node The node to which the transformation will be appended.
 220      *
 221      * @throws IllegalStateException If <code>nextSibling</code> is not
 222      *   <code>null</code> and
 223      *   <code>nextSibling</code> is not a child of <code>node</code> or
 224      *   <code>node</code> is <code>null</code> and
 225      *   <code>nextSibling</code> is not <code>null</code>.
 226      */
 227     public void setNode(Node node) {
 228         // does the corrent parent/child relationship exist?
 229         if (nextSibling != null) {
 230             // cannot be a sibling of a null node
 231             if (node == null) {
 232                 throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 233             }
 234 
 235             // nextSibling contained by node?
 236             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 237                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 238             }
 239         }
 240 
 241         this.node = node;
 242     }
 243 
 244     /**
 245      * <p>Get the node that will contain the result DOM tree.</p>
 246      *
 247      * <p>If no node was set via
 248      * {@link #DOMResult(Node node)},
 249      * {@link #DOMResult(Node node, String systeId)},
 250      * {@link #DOMResult(Node node, Node nextSibling)},
 251      * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
 252      * {@link #setNode(Node node)},
 253      * then the node will be set by the transformation, and may be obtained from this method once the transformation is complete.
 254      * Calling this method before the transformation will return <code>null</code>.</p>
 255      *
 256      * @return The node to which the transformation will be appended.
 257      */
 258     public Node getNode() {
 259         return node;
 260     }
 261 
 262     /**
 263      * <p>Set the child node before which the result nodes will be inserted.</p>
 264      *
 265      * <p>Use <code>nextSibling</code> to specify the child node
 266      * before which the result nodes should be inserted.
 267      * If <code>nextSibling</code> is not a descendant of <code>node</code>,
 268      * then an <code>IllegalArgumentException</code> is thrown.
 269      * If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
 270      * then an <code>IllegalStateException</code> is thrown.
 271      * If <code>nextSibling</code> is <code>null</code>,
 272      * then the behavior is the same as calling {@link #DOMResult(Node node)},
 273      * i.e. append the result nodes as the last child of the specified <code>node</code>.</p>
 274      *
 275      * @param nextSibling The child node before which the result nodes will be inserted.
 276      *
 277      * @throws IllegalArgumentException If <code>nextSibling</code> is not a
 278      *   descendant of <code>node</code>.
 279      * @throws IllegalStateException If <code>node</code> is <code>null</code>
 280      *   and <code>nextSibling</code> is not <code>null</code>.
 281      *
 282      * @since 1.5
 283      */
 284     public void setNextSibling(Node nextSibling) {
 285 
 286         // does the corrent parent/child relationship exist?
 287         if (nextSibling != null) {
 288             // cannot be a sibling of a null node
 289             if (node == null) {
 290                 throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 291             }
 292 
 293             // nextSibling contained by node?
 294             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 295                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 296             }
 297         }
 298 
 299         this.nextSibling = nextSibling;
 300     }
 301 
 302     /**
 303      * <p>Get the child node before which the result nodes will be inserted.</p>
 304      *
 305      * <p>If no node was set via
 306      * {@link #DOMResult(Node node, Node nextSibling)},
 307      * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
 308      * {@link #setNextSibling(Node nextSibling)},
 309      * then <code>null</code> will be returned.</p>
 310      *
 311      * @return The child node before which the result nodes will be inserted.
 312      *
 313      * @since 1.5
 314      */
 315     public Node getNextSibling() {
 316         return nextSibling;
 317     }
 318 
 319     /**
 320      * <p>Set the systemId that may be used in association with the node.</p>
 321      *
 322      * @param systemId The system identifier as a URI string.
 323      */
 324     public void setSystemId(String systemId) {
 325         this.systemId = systemId;
 326     }
 327 
 328     /**
 329      * <p>Get the System Identifier.</p>
 330      *
 331      * <p>If no System ID was set via
 332      * {@link #DOMResult(Node node, String systemId)},
 333      * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
 334      * {@link #setSystemId(String systemId)},
 335      * then <code>null</code> will be returned.</p>
 336      *
 337      * @return The system identifier.
 338      */
 339     public String getSystemId() {
 340         return systemId;
 341     }
 342 
 343     //////////////////////////////////////////////////////////////////////
 344     // Internal state.
 345     //////////////////////////////////////////////////////////////////////
 346 
 347     /**
 348      * <p>The node to which the transformation will be appended.</p>
 349      */
 350     private Node node = null;
 351 
 352     /**
 353      * <p>The child node before which the result nodes will be inserted.</p>
 354      *
 355      * @since 1.5
 356      */
 357     private Node nextSibling = null;
 358 
 359     /**
 360      * <p>The System ID that may be used in association with the node.</p>
 361      */
 362     private String systemId = null;
 363 }


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.xml.transform.dom;
  27 
  28 import javax.xml.transform.Result;
  29 import org.w3c.dom.Node;
  30 
  31 /**
  32  * Acts as a holder for a transformation result tree
  33  * in the form of a Document Object Model (DOM) tree.
  34  *
  35  * <p>If no output DOM source is set, the transformation will create 
  36  * a Document node as the holder for the result of the transformation,
  37  * which may be retrieved with {@link #getNode()}.
  38  *
  39  * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
  40  * @since 1.4
  41  */
  42 public class DOMResult implements Result {
  43 
  44     /** 
  45      * If {@link javax.xml.transform.TransformerFactory#getFeature}
  46      * returns {@code true} when passed this value as an argument,
  47      * the {@code Transformer} supports {@code Result} output of this type.
  48      */
  49     public static final String FEATURE = "http://javax.xml.transform.dom.DOMResult/feature";
  50 
  51     /**
  52      * Zero-argument default constructor.
  53      *
  54      * <p>{@code node},
  55      * {@code siblingNode} and
  56      * {@code systemId}
  57      * will be set to {@code null}.
  58      */
  59     public DOMResult() {
  60         setNode(null);
  61         setNextSibling(null);
  62         setSystemId(null);
  63     }
  64 
  65     /**
  66      * Use a DOM node to create a new output target.
  67      *
  68      * <p>In practice, the node should be
  69      * a {@link org.w3c.dom.Document} node,
  70      * a {@link org.w3c.dom.DocumentFragment} node, or
  71      * a {@link org.w3c.dom.Element} node.
  72      * In other words, a node that accepts children.
  73      *
  74      * <p>{@code siblingNode} and
  75      * {@code systemId}
  76      * will be set to {@code null}.
  77      *
  78      * @param node The DOM node that will contain the result tree.
  79      */
  80     public DOMResult(Node node) {
  81         setNode(node);
  82         setNextSibling(null);
  83         setSystemId(null);
  84     }
  85 
  86     /**
  87      * Use a DOM node to create a new output target with the specified System ID.
  88      *
  89      * <p>In practice, the node should be
  90      * a {@link org.w3c.dom.Document} node,
  91      * a {@link org.w3c.dom.DocumentFragment} node, or
  92      * a {@link org.w3c.dom.Element} node.
  93      * In other words, a node that accepts children.
  94      *
  95      * <p>{@code siblingNode} will be set to {@code null}.
  96      *
  97      * @param node The DOM node that will contain the result tree.
  98      * @param systemId The system identifier which may be used in association with this node.
  99      */
 100     public DOMResult(Node node, String systemId) {
 101         setNode(node);
 102         setNextSibling(null);
 103         setSystemId(systemId);
 104     }
 105 
 106     /**
 107      * Use a DOM node to create a new output target specifying 
 108      * the child node where the result nodes should be inserted before.
 109      *
 110      * <p>In practice, {@code node} and {@code nextSibling} should be
 111      * a {@link org.w3c.dom.Document} node,
 112      * a {@link org.w3c.dom.DocumentFragment} node, or
 113      * a {@link org.w3c.dom.Element} node.
 114      * In other words, a node that accepts children.
 115      *
 116      * <p>Use {@code nextSibling} to specify the child node
 117      * where the result nodes should be inserted before.
 118      * If {@code nextSibling} is not a sibling of {@code node},
 119      * then an {@code IllegalArgumentException} is thrown.
 120      * If {@code node} is {@code null} and {@code nextSibling} is not {@code null},
 121      * then an {@code IllegalArgumentException} is thrown.
 122      * If {@code nextSibling} is {@code null},
 123      * then the behavior is the same as calling {@link #DOMResult(Node node)},
 124      * i.e. append the result nodes as the last child of the specified {@code node}.
 125      *
 126      * <p>{@code systemId} will be set to {@code null}.
 127      *
 128      * @param node The DOM node that will contain the result tree.
 129      * @param nextSibling The child node where the result nodes should be inserted before.
 130      *
 131      * @throws IllegalArgumentException If {@code nextSibling} is not a sibling of {@code node} or
 132      *   {@code node} is {@code null} and {@code nextSibling}
 133      *   is not {@code null}.
 134      *
 135      * @since 1.5
 136      */
 137     public DOMResult(Node node, Node nextSibling) {
 138 
 139         // does the corrent parent/child relationship exist?
 140         if (nextSibling != null) {
 141             // cannot be a sibling of a null node
 142             if (node == null) {
 143                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 144             }
 145 
 146             // nextSibling contained by node?
 147             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 148                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 149             }
 150         }
 151 
 152         setNode(node);
 153         setNextSibling(nextSibling);
 154         setSystemId(null);
 155     }
 156 
 157     /**
 158      * Use a DOM node to create a new output target specifying the child 
 159      * node where the result nodes should be inserted before and
 160      * the specified System ID.
 161      *
 162      * <p>In practice, {@code node} and {@code nextSibling} should be
 163      * a {@link org.w3c.dom.Document} node,
 164      * a {@link org.w3c.dom.DocumentFragment} node, or a
 165      * {@link org.w3c.dom.Element} node.
 166      * In other words, a node that accepts children.
 167      *
 168      * <p>Use {@code nextSibling} to specify the child node
 169      * where the result nodes should be inserted before.
 170      * If {@code nextSibling} is not a sibling of {@code node},
 171      * then an {@code IllegalArgumentException} is thrown.
 172      * If {@code node} is {@code null} and {@code nextSibling} is not {@code null},
 173      * then an {@code IllegalArgumentException} is thrown.
 174      * If {@code nextSibling} is {@code null},
 175      * then the behavior is the same as calling {@link #DOMResult(Node node, String systemId)},
 176      * i.e. append the result nodes as the last child of the specified 
 177      * node and use the specified System ID.
 178      *
 179      * @param node The DOM node that will contain the result tree.
 180      * @param nextSibling The child node where the result nodes should be inserted before.
 181      * @param systemId The system identifier which may be used in association with this node.
 182      *
 183      * @throws IllegalArgumentException If {@code nextSibling} is not a
 184      *   sibling of {@code node} or
 185      *   {@code node} is {@code null} and {@code nextSibling}
 186      *   is not {@code null}.
 187      *
 188      * @since 1.5
 189      */
 190     public DOMResult(Node node, Node nextSibling, String systemId) {
 191 
 192         // does the corrent parent/child relationship exist?
 193         if (nextSibling != null) {
 194             // cannot be a sibling of a null node
 195             if (node == null) {
 196                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 197             }
 198 
 199             // nextSibling contained by node?
 200             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 201                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 202             }
 203         }
 204 
 205         setNode(node);
 206         setNextSibling(nextSibling);
 207         setSystemId(systemId);
 208     }
 209 
 210     /**
 211      * Set the node that will contain the result DOM tree.
 212      *
 213      * <p>In practice, the node should be
 214      * a {@link org.w3c.dom.Document} node,
 215      * a {@link org.w3c.dom.DocumentFragment} node, or
 216      * a {@link org.w3c.dom.Element} node.
 217      * In other words, a node that accepts children.
 218      *
 219      * <p>An {@code IllegalStateException} is thrown if
 220      * {@code nextSibling} is not {@code null} and
 221      * {@code node} is not a parent of {@code nextSibling}.
 222      * An {@code IllegalStateException} is thrown if {@code node} is {@code null} and
 223      * {@code nextSibling} is not {@code null}.
 224      *
 225      * @param node The node to which the transformation will be appended.
 226      *
 227      * @throws IllegalStateException If {@code nextSibling} is not
 228      *   {@code null} and
 229      *   {@code nextSibling} is not a child of {@code node} or
 230      *   {@code node} is {@code null} and
 231      *   {@code nextSibling} is not {@code null}.
 232      */
 233     public void setNode(Node node) {
 234         // does the corrent parent/child relationship exist?
 235         if (nextSibling != null) {
 236             // cannot be a sibling of a null node
 237             if (node == null) {
 238                 throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 239             }
 240 
 241             // nextSibling contained by node?
 242             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 243                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 244             }
 245         }
 246 
 247         this.node = node;
 248     }
 249 
 250     /**
 251      * Get the node that will contain the result DOM tree.
 252      *
 253      * <p>If no node was set via
 254      * {@link #DOMResult(Node node)},
 255      * {@link #DOMResult(Node node, String systeId)},
 256      * {@link #DOMResult(Node node, Node nextSibling)},
 257      * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
 258      * {@link #setNode(Node node)},
 259      * then the node will be set by the transformation, and may be obtained from this method once the transformation is complete.
 260      * Calling this method before the transformation will return {@code null}.
 261      *
 262      * @return The node to which the transformation will be appended.
 263      */
 264     public Node getNode() {
 265         return node;
 266     }
 267 
 268     /**
 269      * Set the child node before which the result nodes will be inserted.
 270      *
 271      * <p>Use {@code nextSibling} to specify the child node
 272      * before which the result nodes should be inserted.
 273      * If {@code nextSibling} is not a descendant of {@code node},
 274      * then an {@code IllegalArgumentException} is thrown.
 275      * If {@code node} is {@code null} and {@code nextSibling} is not {@code null},
 276      * then an {@code IllegalStateException} is thrown.
 277      * If {@code nextSibling} is {@code null},
 278      * then the behavior is the same as calling {@link #DOMResult(Node node)},
 279      * i.e. append the result nodes as the last child of the specified {@code node}.
 280      *
 281      * @param nextSibling The child node before which the result nodes will be inserted.
 282      *
 283      * @throws IllegalArgumentException If {@code nextSibling} is not a
 284      *   descendant of {@code node}.
 285      * @throws IllegalStateException If {@code node} is {@code null}
 286      *   and {@code nextSibling} is not {@code null}.
 287      *
 288      * @since 1.5
 289      */
 290     public void setNextSibling(Node nextSibling) {
 291 
 292         // does the corrent parent/child relationship exist?
 293         if (nextSibling != null) {
 294             // cannot be a sibling of a null node
 295             if (node == null) {
 296                 throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
 297             }
 298 
 299             // nextSibling contained by node?
 300             if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
 301                 throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
 302             }
 303         }
 304 
 305         this.nextSibling = nextSibling;
 306     }
 307 
 308     /**
 309      * Get the child node before which the result nodes will be inserted.
 310      *
 311      * <p>If no node was set via
 312      * {@link #DOMResult(Node node, Node nextSibling)},
 313      * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
 314      * {@link #setNextSibling(Node nextSibling)},
 315      * then {@code null} will be returned.
 316      *
 317      * @return The child node before which the result nodes will be inserted.
 318      *
 319      * @since 1.5
 320      */
 321     public Node getNextSibling() {
 322         return nextSibling;
 323     }
 324 
 325     /**
 326      * Set the systemId that may be used in association with the node.
 327      *
 328      * @param systemId The system identifier as a URI string.
 329      */
 330     public void setSystemId(String systemId) {
 331         this.systemId = systemId;
 332     }
 333 
 334     /**
 335      * Get the System Identifier.
 336      *
 337      * <p>If no System ID was set via
 338      * {@link #DOMResult(Node node, String systemId)},
 339      * {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
 340      * {@link #setSystemId(String systemId)},
 341      * then {@code null} will be returned.
 342      *
 343      * @return The system identifier.
 344      */
 345     public String getSystemId() {
 346         return systemId;
 347     }
 348 
 349     //////////////////////////////////////////////////////////////////////
 350     // Internal state.
 351     //////////////////////////////////////////////////////////////////////
 352 
 353     /**
 354      * The node to which the transformation will be appended.
 355      */
 356     private Node node = null;
 357 
 358     /**
 359      * The child node before which the result nodes will be inserted.
 360      *
 361      * @since 1.5
 362      */
 363     private Node nextSibling = null;
 364 
 365     /**
 366      * The System ID that may be used in association with the node.
 367      */
 368     private String systemId = null;
 369 }
< prev index next >