View Javadoc
1   /*
2    * Copyright (c) 2002-2025 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   */
25  public class DomDocumentFragment extends DomNode implements DocumentFragment {
26  
27      /** The symbolic node name. */
28      public static final String NODE_NAME = "#document-fragment";
29  
30      /**
31       * Creates a new instance.
32       * @param page the page which contains this node
33       */
34      public DomDocumentFragment(final SgmlPage page) {
35          super(page);
36      }
37  
38      /**
39       * {@inheritDoc}
40       * @return the node name, in this case {@link #NODE_NAME}
41       */
42      @Override
43      public String getNodeName() {
44          return NODE_NAME;
45      }
46  
47      /**
48       * {@inheritDoc}
49       * @return the node type constant, in this case {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE}
50       */
51      @Override
52      public short getNodeType() {
53          return DOCUMENT_FRAGMENT_NODE;
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public String asXml() {
61          final StringBuilder sb = new StringBuilder();
62          for (final DomNode node : getChildren()) {
63              sb.append(node.asXml());
64          }
65          return sb.toString();
66      }
67  
68      /**
69       * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
70       *
71       * @return {@code false}
72       */
73      @Override
74      public boolean isAttachedToPage() {
75          return false;
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public void setNodeValue(final String value) {
83          // Default behavior is to do nothing, overridden in some subclasses
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public void setPrefix(final String prefix) {
91          // Empty.
92      }
93  }