001package org.jsoup.nodes; 002 003import java.io.IOException; 004 005/** 006 A data node, for contents of style, script tags etc, where contents should not show in text(). 007 008 @author Jonathan Hedley, jonathan@hedley.net */ 009public class DataNode extends LeafNode { 010 011 /** 012 Create a new DataNode. 013 @param data data contents 014 */ 015 public DataNode(String data) { 016 value = data; 017 } 018 019 /** 020 Create a new DataNode. 021 @param data data contents 022 @param baseUri Unused, Leaf Nodes do not hold base URis 023 @deprecated use {@link #DataNode(String)} instead 024 */ 025 public DataNode(String data, String baseUri) { 026 this(data); 027 } 028 029 public String nodeName() { 030 return "#data"; 031 } 032 033 /** 034 Get the data contents of this node. Will be unescaped and with original new lines, space etc. 035 @return data 036 */ 037 public String getWholeData() { 038 return coreValue(); 039 } 040 041 /** 042 * Set the data contents of this node. 043 * @param data unencoded data 044 * @return this node, for chaining 045 */ 046 public DataNode setWholeData(String data) { 047 coreValue(data); 048 return this; 049 } 050 051 void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { 052 accum.append(getWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain 053 } 054 055 void outerHtmlTail(Appendable accum, int depth, Document.OutputSettings out) {} 056 057 @Override 058 public String toString() { 059 return outerHtml(); 060 } 061 062 /** 063 Create a new DataNode from HTML encoded data. 064 @param encodedData encoded data 065 @param baseUri bass URI 066 @return new DataNode 067 */ 068 public static DataNode createFromEncoded(String encodedData, String baseUri) { 069 String data = Entities.unescape(encodedData); 070 return new DataNode(data); 071 } 072}