diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-09 16:25:06 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-09 16:39:36 +0300 |
commit | bfaf549a7814cfabbc6ce95b6c865d0fff0b5ead (patch) | |
tree | 548bbddcff0eef2a41ae526f1e1a8b77c003b974 /src/org/jsoup/nodes/DataNode.java | |
parent | f673c7b2655620fb1be87dd90d2edfb412f9fe5c (diff) | |
download | vaadin-framework-bfaf549a7814cfabbc6ce95b6c865d0fff0b5ead.tar.gz vaadin-framework-bfaf549a7814cfabbc6ce95b6c865d0fff0b5ead.zip |
Include jsoup library for modifying bootstap page DOM (#9274)
Diffstat (limited to 'src/org/jsoup/nodes/DataNode.java')
-rw-r--r-- | src/org/jsoup/nodes/DataNode.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/org/jsoup/nodes/DataNode.java b/src/org/jsoup/nodes/DataNode.java new file mode 100644 index 0000000000..a64f56f0a4 --- /dev/null +++ b/src/org/jsoup/nodes/DataNode.java @@ -0,0 +1,62 @@ +package org.jsoup.nodes; + +/** + A data node, for contents of style, script tags etc, where contents should not show in text(). + + @author Jonathan Hedley, jonathan@hedley.net */ +public class DataNode extends Node{ + private static final String DATA_KEY = "data"; + + /** + Create a new DataNode. + @param data data contents + @param baseUri base URI + */ + public DataNode(String data, String baseUri) { + super(baseUri); + attributes.put(DATA_KEY, data); + } + + public String nodeName() { + return "#data"; + } + + /** + Get the data contents of this node. Will be unescaped and with original new lines, space etc. + @return data + */ + public String getWholeData() { + return attributes.get(DATA_KEY); + } + + /** + * Set the data contents of this node. + * @param data unencoded data + * @return this node, for chaining + */ + public DataNode setWholeData(String data) { + attributes.put(DATA_KEY, data); + return this; + } + + void outerHtmlHead(StringBuilder accum, int depth, Document.OutputSettings out) { + accum.append(getWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain + } + + void outerHtmlTail(StringBuilder accum, int depth, Document.OutputSettings out) {} + + public String toString() { + return outerHtml(); + } + + /** + Create a new DataNode from HTML encoded data. + @param encodedData encoded data + @param baseUri bass URI + @return new DataNode + */ + public static DataNode createFromEncoded(String encodedData, String baseUri) { + String data = Entities.unescape(encodedData); + return new DataNode(data, baseUri); + } +} |