Search in sources :

Example 1 with ContentToken

use of org.htmlcleaner.ContentToken in project stanbol by apache.

the class DomSerializer2 method createSubnodes.

private void createSubnodes(Document document, Element element, List tagChildren) {
    if (tagChildren != null) {
        Iterator it = tagChildren.iterator();
        while (it.hasNext()) {
            Object item = it.next();
            if (item instanceof CommentToken) {
                CommentToken commentNode = (CommentToken) item;
                Comment comment = document.createComment(commentNode.getContent().toString());
                element.appendChild(comment);
            } else if (item instanceof ContentToken) {
                ContentToken contentToken = (ContentToken) item;
                String content = contentToken.getContent();
                String nodeName = element.getNodeName();
                boolean specialCase = props.isUseCdataForScriptAndStyle() && ("script".equalsIgnoreCase(nodeName) || "style".equalsIgnoreCase(nodeName));
                if (escapeXml && !specialCase) {
                    content = escapeXml(content, props, true);
                }
                element.appendChild(specialCase ? document.createCDATASection(content) : document.createTextNode(content));
            } else if (item instanceof TagNode) {
                TagNode subTagNode = (TagNode) item;
                Element subelement = document.createElement(subTagNode.getName());
                ;
                setAttributes(subTagNode, subelement);
                // recursively create subnodes
                createSubnodes(document, subelement, subTagNode.getChildren());
                element.appendChild(subelement);
            } else if (item instanceof List) {
                List sublist = (List) item;
                createSubnodes(document, element, sublist);
            }
        }
    }
}
Also used : CommentToken(org.htmlcleaner.CommentToken) Comment(org.w3c.dom.Comment) ContentToken(org.htmlcleaner.ContentToken) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) List(java.util.List) TagNode(org.htmlcleaner.TagNode)

Aggregations

Iterator (java.util.Iterator)1 List (java.util.List)1 CommentToken (org.htmlcleaner.CommentToken)1 ContentToken (org.htmlcleaner.ContentToken)1 TagNode (org.htmlcleaner.TagNode)1 Comment (org.w3c.dom.Comment)1 Element (org.w3c.dom.Element)1