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 java.io.PrintWriter;
18  
19  import org.htmlunit.SgmlPage;
20  import org.w3c.dom.Comment;
21  
22  /**
23   * Wrapper for the DOM node Comment.
24   *
25   * @author Karel Kolman
26   * @author Ahmed Ashour
27   * @author Ronald Brill
28   */
29  public class DomComment extends DomCharacterData implements Comment {
30  
31      /** The symbolic node name. */
32      public static final String NODE_NAME = "#comment";
33  
34      /**
35       * Creates an instance of DomComment.
36       *
37       * @param page the Page that contains this element
38       * @param data the string data held by this node
39       */
40      public DomComment(final SgmlPage page, final String data) {
41          super(page, data);
42      }
43  
44      /**
45       * {@inheritDoc}
46       * @return the node type constant, in this case {@link org.w3c.dom.Node#COMMENT_NODE}
47       */
48      @Override
49      public short getNodeType() {
50          return COMMENT_NODE;
51      }
52  
53      /**
54       * @return the node name, in this case {@link #NODE_NAME}
55       */
56      @Override
57      public String getNodeName() {
58          return NODE_NAME;
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      @Override
65      protected boolean printXml(final String indent, final boolean tagBefore, final PrintWriter printWriter) {
66          printWriter.print(indent);
67          printWriter.print("<!--");
68          printWriter.print(getData());
69          printWriter.print("-->");
70          return printChildrenAsXml(indent, true, printWriter);
71      }
72  
73      /**
74       * Returns a simple string representation to facilitate debugging.
75       * @return a simple string representation
76       */
77      @Override
78      public String toString() {
79          return asXml();
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public void setPrefix(final String prefix) {
87          // Empty.
88      }
89  }