mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-19 19:03:07 +09:00
Add java htmlparser sources that match the original 52-level state
https://hg.mozilla.org/projects/htmlparser/ Commit: abe62ab2a9b69ccb3b5d8a231ec1ae11154c571d
This commit is contained in:
parent
3efecbe3cc
commit
36189e6a63
248 changed files with 62553 additions and 0 deletions
36
parser/html/java/htmlparser/ruby-gcj/DomUtils.java
Normal file
36
parser/html/java/htmlparser/ruby-gcj/DomUtils.java
Normal file
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue