Search in sources :

Example 11 with TagNode

use of org.htmlcleaner.TagNode in project iaf by ibissource.

the class XmlUtils method toXhtml.

public static String toXhtml(String htmlString) {
    if (StringUtils.isNotEmpty(htmlString)) {
        String xhtmlString = skipDocTypeDeclaration(htmlString.trim());
        if (xhtmlString.startsWith("<html>") || xhtmlString.startsWith("<html ")) {
            CleanerProperties props = new CleanerProperties();
            HtmlCleaner cleaner = new HtmlCleaner(props);
            TagNode tagNode = cleaner.clean(xhtmlString);
            return new SimpleXmlSerializer(props).getAsString(tagNode);
        }
    }
    return null;
}
Also used : SimpleXmlSerializer(org.htmlcleaner.SimpleXmlSerializer) CleanerProperties(org.htmlcleaner.CleanerProperties) HtmlCleaner(org.htmlcleaner.HtmlCleaner) TagNode(org.htmlcleaner.TagNode)

Example 12 with TagNode

use of org.htmlcleaner.TagNode in project FastHub by k0shk0sh.

the class DrawableHandler method handleTagNode.

@Override
public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
    String src = node.getAttributeByName("src");
    if (!InputHelper.isEmpty(src)) {
        if (!PrefGetter.isAutoImageDisabled()) {
            builder.append("");
            if (isNull())
                return;
            builder.append("\n");
            DrawableGetter imageGetter = new DrawableGetter(textView, width);
            builder.setSpan(new ImageSpan(imageGetter.getDrawable(src)), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new CenterSpan(), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.append("\n");
        } else {
            builder.append(SpannableBuilder.builder().clickable("Image", v -> SchemeParser.launchUri(v.getContext(), src)));
            builder.append("\n");
        }
    }
}
Also used : DrawableGetter(com.fastaccess.provider.timeline.handler.drawable.DrawableGetter) SPAN_EXCLUSIVE_EXCLUSIVE(android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) ImageSpan(android.text.style.ImageSpan) InputHelper(com.fastaccess.helper.InputHelper) CenterSpan(net.nightwhistler.htmlspanner.spans.CenterSpan) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) DrawableGetter(com.fastaccess.provider.timeline.handler.drawable.DrawableGetter) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) SpannableStringBuilder(android.text.SpannableStringBuilder) TextView(android.widget.TextView) PrefGetter(com.fastaccess.helper.PrefGetter) TagNodeHandler(net.nightwhistler.htmlspanner.TagNodeHandler) TagNode(org.htmlcleaner.TagNode) AllArgsConstructor(lombok.AllArgsConstructor) CenterSpan(net.nightwhistler.htmlspanner.spans.CenterSpan) ImageSpan(android.text.style.ImageSpan)

Example 13 with TagNode

use of org.htmlcleaner.TagNode in project FastHub by k0shk0sh.

the class ListsHandler method beforeChildren.

@Override
public void beforeChildren(TagNode node, SpannableStringBuilder builder) {
    TodoItems todoItem = null;
    if (node.getChildTags() != null && node.getChildTags().length > 0) {
        for (TagNode tagNode : node.getChildTags()) {
            Logger.e(tagNode.getName(), tagNode.getText());
            if (tagNode.getName() != null && tagNode.getName().equals("input")) {
                todoItem = new TodoItems();
                todoItem.isChecked = tagNode.getAttributeByName("checked") != null;
                break;
            }
        }
    }
    if ("ol".equals(getParentName(node))) {
        builder.append(String.valueOf(getMyIndex(node))).append(". ");
    } else if ("ul".equals(getParentName(node))) {
        if (todoItem != null) {
            if (checked == null || unchecked == null) {
                builder.append(todoItem.isChecked ? "☑" : "☐");
            } else {
                builder.append(SpannableBuilder.builder().append(todoItem.isChecked ? checked : unchecked)).append(" ");
            }
        } else {
            builder.append("\u2022 ");
        }
    }
}
Also used : TagNode(org.htmlcleaner.TagNode)

Example 14 with TagNode

use of org.htmlcleaner.TagNode in project FastHub by k0shk0sh.

the class PreTagHandler method getPlainText.

private void getPlainText(StringBuffer buffer, Object node) {
    if (node instanceof ContentNode) {
        ContentNode contentNode = (ContentNode) node;
        String text = contentNode.getContent().toString();
        buffer.append(text);
    } else if (node instanceof TagNode) {
        TagNode tagNode = (TagNode) node;
        for (Object child : tagNode.getChildren()) {
            this.getPlainText(buffer, child);
        }
    }
}
Also used : ContentNode(org.htmlcleaner.ContentNode) TagNode(org.htmlcleaner.TagNode)

Example 15 with TagNode

use of org.htmlcleaner.TagNode in project FastHub by k0shk0sh.

the class TableHandler method readNode.

private void readNode(Object node, Table table) {
    if (node instanceof TagNode) {
        TagNode tagNode = (TagNode) node;
        if (tagNode.getName().equals("td") || tagNode.getName().equals("th")) {
            Spanned result = this.getSpanner().fromTagNode(tagNode);
            table.addCell(result);
            return;
        }
        if (tagNode.getName().equals("tr")) {
            table.addRow();
        }
        for (Object child : tagNode.getChildTags()) {
            readNode(child, table);
        }
    }
}
Also used : Spanned(android.text.Spanned) TagNode(org.htmlcleaner.TagNode)

Aggregations

TagNode (org.htmlcleaner.TagNode)16 HtmlCleaner (org.htmlcleaner.HtmlCleaner)8 CleanerProperties (org.htmlcleaner.CleanerProperties)7 Test (org.junit.Test)3 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Transformer (javax.xml.transform.Transformer)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 DomSerializer (org.htmlcleaner.DomSerializer)2 SimpleXmlSerializer (org.htmlcleaner.SimpleXmlSerializer)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Spanned (android.text.Spanned)1 SPAN_EXCLUSIVE_EXCLUSIVE (android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)1 ImageSpan (android.text.style.ImageSpan)1