View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html;
16  
17  import org.htmlunit.SgmlPage;
18  import org.w3c.dom.DocumentFragment;
19  
20  /**
21   * A DOM object for DocumentFragment.
22   *
23   * @author Ahmed Ashour
24   * @author Ronald Brill
25   */
26  public class DomDocumentFragment extends DomNode implements DocumentFragment {
27  
28      /** The symbolic node name. */
29      public static final String NODE_NAME = "#document-fragment";
30  
31      /**
32       * Creates a new instance.
33       * @param page the page which contains this node
34       */
35      public DomDocumentFragment(final SgmlPage page) {
36          super(page);
37      }
38  
39      /**
40       * {@inheritDoc}
41       * @return the node name, in this case {@link #NODE_NAME}
42       */
43      @Override
44      public String getNodeName() {
45          return NODE_NAME;
46      }
47  
48      /**
49       * {@inheritDoc}
50       * @return the node type constant, in this case {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE}
51       */
52      @Override
53      public short getNodeType() {
54          return DOCUMENT_FRAGMENT_NODE;
55      }
56  
57      /**
58       * {@inheritDoc}
59       */
60      @Override
61      public String asXml() {
62          final StringBuilder sb = new StringBuilder();
63          for (final DomNode node : getChildren()) {
64              sb.append(node.asXml());
65          }
66          return sb.toString();
67      }
68  
69      /**
70       * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
71       *
72       * @return {@code false}
73       */
74      @Override
75      public boolean isAttachedToPage() {
76          return false;
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public void setNodeValue(final String value) {
84          // Default behavior is to do nothing, overridden in some subclasses
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public void setPrefix(final String prefix) {
92          // Empty.
93      }
94  }