summaryrefslogtreecommitdiffstats
path: root/parser/html/java/htmlparser/ruby-gcj/DomUtils.java
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-01-16 07:32:48 -0500
committerMatt A. Tobin <email@mattatobin.com>2020-01-16 07:32:48 -0500
commited60101550022a2650edc41cd3a63b35fea836c5 (patch)
treee6967e47f27945599ec09c4401f7932751315beb /parser/html/java/htmlparser/ruby-gcj/DomUtils.java
parentfa816e1ec69d865114b7d061905574038fbd425b (diff)
parent927c386dd8c9526d8695d0202a08735984dc7b31 (diff)
downloadUXP-ed60101550022a2650edc41cd3a63b35fea836c5.tar
UXP-ed60101550022a2650edc41cd3a63b35fea836c5.tar.gz
UXP-ed60101550022a2650edc41cd3a63b35fea836c5.tar.lz
UXP-ed60101550022a2650edc41cd3a63b35fea836c5.tar.xz
UXP-ed60101550022a2650edc41cd3a63b35fea836c5.zip
Merge branch 'html5-parser-work'
Diffstat (limited to 'parser/html/java/htmlparser/ruby-gcj/DomUtils.java')
-rw-r--r--parser/html/java/htmlparser/ruby-gcj/DomUtils.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/parser/html/java/htmlparser/ruby-gcj/DomUtils.java b/parser/html/java/htmlparser/ruby-gcj/DomUtils.java
new file mode 100644
index 000000000..dc43da83d
--- /dev/null
+++ b/parser/html/java/htmlparser/ruby-gcj/DomUtils.java
@@ -0,0 +1,36 @@
+import java.util.HashSet;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+public class DomUtils {
+
+ private static HashSet<Document> pinned_list = new HashSet<Document>();
+
+ public static synchronized void pin(Document d) {
+ pinned_list.add(d);
+ }
+
+ public static synchronized void unpin(Document d) {
+ pinned_list.remove(d);
+ }
+
+ // return all the text content contained by a single element
+ public static void getElementContent(Element e, StringBuffer b) {
+ for (Node n = e.getFirstChild(); n!=null; n=n.getNextSibling()) {
+ if (n.getNodeType() == n.TEXT_NODE) {
+ b.append(n.getNodeValue());
+ } else if (n.getNodeType() == n.ELEMENT_NODE) {
+ getElementContent((Element) e, b);
+ }
+ }
+ }
+
+ // replace all child nodes of a given element with a single text element
+ public static void setElementContent(Element e, String s) {
+ while (e.hasChildNodes()) {
+ e.removeChild(e.getFirstChild());
+ }
+ e.appendChild(e.getOwnerDocument().createTextNode(s));
+ }
+}