1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.io.PrintWriter ; 41 42 49 public class DomText extends DomCharacterData { 50 51 52 public static final String NODE_NAME = "#text"; 53 54 60 public DomText( final HtmlPage page, final String data) { 61 super(page, data); 62 } 63 64 65 70 public DomText splitText(final int offset) { 71 if (offset < 0 || offset > getLength() ) { 72 throw new IllegalArgumentException ("offset: "+offset+" data.length: "+getLength()); 73 } 74 75 final DomText newText = new DomText(getPage(), getData().substring(offset)); 77 setData(getData().substring(0, offset)); 78 79 if (getParentNode() != null) { 81 newText.setParentNode(getParentNode()); 82 newText.setPreviousSibling(this); 83 newText.setNextSibling(getNextSibling()); 84 setNextSibling(newText); 85 } 86 87 return newText; 88 } 89 90 98 public String asText() { 99 return getData(); 100 } 101 102 105 public short getNodeType() { 106 return DomNode.TEXT_NODE; 107 } 108 109 112 public String getNodeName() { 113 return NODE_NAME; 114 } 115 116 122 protected void printXml( final String indent, final PrintWriter printWriter ) { 123 124 printWriter.print(indent); 125 printWriter.println(getData()); 126 printChildrenAsXml( indent, printWriter ); 127 } 128 } 129 | Popular Tags |