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.CDATASection; 21 22 /** 23 * Representation of a CDATA node in the HTML DOM. 24 * 25 * @author Marc Guillemot 26 * @author David K. Taylor 27 * @author Ronald Brill 28 */ 29 public class DomCDataSection extends DomText implements CDATASection { 30 31 /** 32 * Creates a new instance. 33 * 34 * @param page the Page that contains this element 35 * @param data the string data held by this node 36 */ 37 public DomCDataSection(final SgmlPage page, final String data) { 38 super(page, data); 39 } 40 41 /** 42 * @return the node type constant, in this case {@link org.w3c.dom.Node#CDATA_SECTION_NODE} 43 */ 44 @Override 45 public short getNodeType() { 46 return CDATA_SECTION_NODE; 47 } 48 49 /** 50 * {@inheritDoc} 51 */ 52 @Override 53 public String getNodeName() { 54 return "#cdata-section"; 55 } 56 57 /** 58 * {@inheritDoc} 59 */ 60 @Override 61 protected boolean printXml(final String indent, final boolean tagBefore, final PrintWriter printWriter) { 62 printWriter.print("<![CDATA["); 63 printWriter.print(getData()); 64 printWriter.print("]]>"); 65 return true; 66 } 67 68 /** 69 * {@inheritDoc} 70 */ 71 @Override 72 protected DomText createSplitTextNode(final int offset) { 73 return new DomCDataSection(getPage(), getData().substring(offset)); 74 } 75 }