QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

以下内容为反编译后的 HtmlCleaner.java 源代码,内容仅作参考


package com.tencent.mttreader.epub.parser.htmlcleaner;

import com.tencent.mttreader.epub.parser.htmlcleaner.audit.ErrorType;
import com.tencent.mttreader.epub.parser.htmlcleaner.conditional.ITagNodeCondition;
import com.xiaomi.mipush.sdk.Constants;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

public class HtmlCleaner {

    public static int f75564a = 4;

    public static int f75565b = 5;

    private CleanerProperties f75566c;

    private CleanerTransformations f75567d;

    public class ChildBreaks {

        private Stack<TagPos> f75569b;

        private Stack<TagPos> f75570c;

        private ChildBreaks() {
            this.f75569b = new Stack<>();
            this.f75570c = new Stack<>();
        }

        public void a(TagPos tagPos, TagPos tagPos2) {
            this.f75569b.add(tagPos);
            this.f75570c.add(tagPos2);
        }

        public boolean a() {
            return this.f75569b.isEmpty();
        }

        public String b() {
            return this.f75570c.peek().f75580c;
        }

        public TagPos c() {
            this.f75570c.pop();
            return this.f75569b.pop();
        }

        public int d() {
            if (this.f75570c.isEmpty()) {
                return -1;
            }
            return this.f75570c.peek().f75579b;
        }
    }

    public class NestingState {

        private OpenTags f75572b;

        private ChildBreaks f75573c;

        protected NestingState() {
            this.f75572b = new OpenTags();
            this.f75573c = new ChildBreaks();
        }

        public OpenTags a() {
            return this.f75572b;
        }

        public ChildBreaks b() {
            return this.f75573c;
        }
    }

    public class OpenTags {

        private TagPos f75576c;

        private List<TagPos> f75575b = new ArrayList();

        private Set<String> f75577d = new HashSet();

        OpenTags() {
        }

        public void a(String str) {
            TagPos tagPos;
            List<TagPos> list = this.f75575b;
            ListIterator<TagPos> listIterator = list.listIterator(list.size());
            while (true) {
                if (!listIterator.hasPrevious()) {
                    break;
                } else if (str.equals(listIterator.previous().f75580c)) {
                    listIterator.remove();
                    break;
                }
            }
            if (this.f75575b.isEmpty()) {
                tagPos = null;
            } else {
                tagPos = this.f75575b.get(r3.size() - 1);
            }
            this.f75576c = tagPos;
        }

        public void a(String str, int i) {
            this.f75576c = new TagPos(i, str);
            this.f75575b.add(this.f75576c);
            this.f75577d.add(str);
        }

        public boolean a() {
            return this.f75575b.isEmpty();
        }

        public boolean a(Set<String> set) {
            Iterator<TagPos> it = this.f75575b.iterator();
            while (it.hasNext()) {
                if (set.contains(it.next().f75580c)) {
                    return true;
                }
            }
            return false;
        }

        public TagPos b() {
            if (this.f75575b.isEmpty()) {
                return null;
            }
            return this.f75575b.get(0);
        }

        public TagPos b(String str) {
            if (str != null) {
                List<TagPos> list = this.f75575b;
                ListIterator<TagPos> listIterator = list.listIterator(list.size());
                TagInfo a2 = HtmlCleaner.this.b().a(str);
                while (listIterator.hasPrevious()) {
                    TagPos previous = listIterator.previous();
                    if (!str.equals(previous.f75580c)) {
                        if (a2 != null && a2.i(previous.f75580c)) {
                            break;
                        }
                    } else {
                        return previous;
                    }
                }
            }
            return null;
        }

        public TagPos c() {
            return this.f75576c;
        }

        public boolean c(String str) {
            return b(str) != null;
        }

        public TagPos d() {
            TagPos tagPos = null;
            if (!a()) {
                List<TagPos> list = this.f75575b;
                ListIterator<TagPos> listIterator = list.listIterator(list.size());
                while (true) {
                    TagPos tagPos2 = tagPos;
                    if (!listIterator.hasPrevious()) {
                        break;
                    }
                    tagPos = listIterator.previous();
                    if (tagPos.f75581d == null || tagPos.f75581d.o()) {
                        if (tagPos2 != null) {
                            return tagPos2;
                        }
                    }
                }
            }
            return tagPos;
        }

        public boolean d(String str) {
            return this.f75577d.contains(str);
        }
    }

    public class TagPos {

        private int f75579b;

        private String f75580c;

        private TagInfo f75581d;

        TagPos(int i, String str) {
            this.f75579b = i;
            this.f75580c = str;
            this.f75581d = HtmlCleaner.this.b().a(str);
        }
    }

    public HtmlCleaner() {
        this(null, null);
    }

    public HtmlCleaner(ITagInfoProvider iTagInfoProvider, CleanerProperties cleanerProperties) {
        CleanerProperties cleanerProperties2;
        ITagInfoProvider iTagInfoProvider2;
        this.f75566c = cleanerProperties == null ? new CleanerProperties() : cleanerProperties;
        if (iTagInfoProvider != null || this.f75566c.a() != null) {
            if (iTagInfoProvider != null) {
                this.f75566c.a(iTagInfoProvider == null ? Html4TagProvider.f75559a : iTagInfoProvider);
            }
        } else {
            if (this.f75566c.v() == f75564a) {
                cleanerProperties2 = this.f75566c;
                iTagInfoProvider2 = Html4TagProvider.f75559a;
            } else {
                cleanerProperties2 = this.f75566c;
                iTagInfoProvider2 = Html5TagProvider.f75561a;
            }
            cleanerProperties2.a(iTagInfoProvider2);
        }
    }

    private OpenTags a(CleanTimeValues cleanTimeValues) {
        return cleanTimeValues.e.peek().a();
    }

    private TagNode a(TagNode tagNode) {
        tagNode.p();
        return tagNode;
    }

    private TagNode a(String str) {
        return new TagNode(str);
    }

    private List<TagNode> a(List list, TagPos tagPos, Object obj, CleanTimeValues cleanTimeValues) {
        ArrayList arrayList = new ArrayList();
        ListIterator listIterator = list.listIterator(tagPos.f75579b);
        Object next = listIterator.next();
        TagNode tagNode = null;
        boolean z = false;
        while (true) {
            if ((obj != null || z) && (obj == null || next == obj)) {
                break;
            }
            if (a(next)) {
                TagNode tagNode2 = (TagNode) next;
                arrayList.add(tagNode2);
                List<? extends BaseToken> n = tagNode2.n();
                if (n != null) {
                    c(cleanTimeValues);
                    a((List) n, (ListIterator<BaseToken>) n.listIterator(0), cleanTimeValues);
                    c(n, cleanTimeValues);
                    tagNode2.b((List<BaseToken>) null);
                    d(cleanTimeValues);
                }
                TagNode a2 = a(tagNode2);
                a(b(a2.f(), cleanTimeValues), a2, cleanTimeValues);
                if (tagNode != null) {
                    tagNode.a((List) n);
                    tagNode.a(a2);
                    listIterator.set(null);
                } else if (n != null) {
                    n.add(a2);
                    listIterator.set(n);
                } else {
                    listIterator.set(a2);
                }
                a(cleanTimeValues).a(a2.f());
                tagNode = a2;
            } else if (tagNode != null) {
                listIterator.set(null);
                if (next != null) {
                    tagNode.a(next);
                }
            }
            if (listIterator.hasNext()) {
                next = listIterator.next();
            } else {
                z = true;
            }
        }
        return arrayList;
    }

    private void a(CleanTimeValues cleanTimeValues, TagNode tagNode, String str) {
        String a2 = tagNode.a("xmlns");
        if (a2.equals("https://www.w3.org/1999/xhtml") || a2.equals("http://w3.org/1999/xhtml")) {
            Map<String, String> g = tagNode.g();
            g.put("xmlns", "http://www.w3.org/1999/xhtml");
            tagNode.a(g);
            a2 = "http://www.w3.org/1999/xhtml";
        }
        if ((com.tencent.common.http.ContentType.SUBTYPE_HTML.equals(str) && a2.equals("http://www.w3.org/TR/REC-html40")) || a2.trim().isEmpty()) {
            tagNode.c("xmlns");
        } else {
            cleanTimeValues.m.push(a2);
            tagNode.b("", a2);
        }
    }

    private void a(CleanTimeValues cleanTimeValues, Set<String> set) {
        cleanTimeValues.i = cleanTimeValues.f;
        if (this.f75566c.k()) {
            List<? extends BaseToken> i = cleanTimeValues.g.i();
            cleanTimeValues.i = new TagNode(null);
            if (i != null) {
                Iterator<? extends BaseToken> it = i.iterator();
                while (it.hasNext()) {
                    cleanTimeValues.i.a(it.next());
                }
            }
        }
        Map<String, String> g = cleanTimeValues.i.g();
        if (cleanTimeValues.i.b("xmlns")) {
            cleanTimeValues.i.b("", cleanTimeValues.i.a("xmlns"));
        }
        if (!this.f75566c.p() || set == null) {
            return;
        }
        for (String str : set) {
            String str2 = "xmlns:" + str;
            if (!g.containsKey(str2) && !str.equals("xml")) {
                cleanTimeValues.i.a(str2, str);
            }
        }
    }

    private void a(TagInfo tagInfo, TagNode tagNode, CleanTimeValues cleanTimeValues) {
        if (tagInfo == null || tagNode == null) {
            return;
        }
        if (tagInfo.m() || (tagInfo.n() && cleanTimeValues.f75541a && !cleanTimeValues.f75542b)) {
            cleanTimeValues.f75543c.add(tagNode);
        }
    }

    private void a(TagNode tagNode, Map<String, String> map) {
        if (map != null) {
            Map<String, String> g = tagNode.g();
            for (Map.Entry<String, String> entry : map.entrySet()) {
                String key = entry.getKey();
                if (!g.containsKey(key)) {
                    tagNode.a(key, entry.getValue());
                }
            }
        }
    }

    private void a(List list, Object obj, CleanTimeValues cleanTimeValues) {
        TagPos d2;
        TagPos c2 = a(cleanTimeValues).c();
        if ((c2 == null || c2.f75581d == null || !c2.f75581d.h()) && (d2 = a(cleanTimeValues).d()) != null) {
            ((TagNode) list.get(d2.f75579b)).c(obj);
        }
    }

    private void a(List list, ListIterator<BaseToken> listIterator, CleanTimeValues cleanTimeValues, BaseToken baseToken) {
        if (cleanTimeValues.f75541a && !cleanTimeValues.f75542b && this.f75566c.r()) {
            if (baseToken instanceof CommentNode) {
                if (a(cleanTimeValues).c() == null) {
                    cleanTimeValues.f75543c.add(new ProxyTagNode((CommentNode) baseToken, cleanTimeValues.g));
                }
            } else if (baseToken instanceof ContentNode) {
                ContentNode contentNode = (ContentNode) baseToken;
                if (contentNode.f() && ((BaseToken) list.get(list.size() - 1)) == baseToken) {
                    cleanTimeValues.f75543c.add(new ProxyTagNode(contentNode, cleanTimeValues.g));
                }
            }
        }
        if (a(baseToken, cleanTimeValues)) {
            return;
        }
        a(list, baseToken, cleanTimeValues);
        listIterator.set(null);
    }

    private void a(List list, ListIterator<BaseToken> listIterator, CleanTimeValues cleanTimeValues, EndTagToken endTagToken) {
        String f = endTagToken.f();
        TagInfo b2 = b(f, cleanTimeValues);
        if ((b2 == null && this.f75566c.f() && !a(f, cleanTimeValues)) || ((b2 != null && b2.f() && this.f75566c.h()) || (b2 != null && !b2.j()))) {
            listIterator.set(null);
            return;
        }
        TagPos b3 = a(cleanTimeValues).b(f);
        if (b3 != null) {
            List<TagNode> a2 = a(list, b3, endTagToken, cleanTimeValues);
            if (a2.size() > 0 && a2.get(0).b("xmlns")) {
                cleanTimeValues.m.pop();
            }
            listIterator.set(null);
            for (int size = a2.size() - 1; size >= 0; size--) {
                TagNode tagNode = a2.get(size);
                if (size > 0 && b2 != null && b2.l(tagNode.f())) {
                    TagNode u = tagNode.u();
                    u.b(true);
                    listIterator.add(u);
                    listIterator.previous();
                }
            }
            if (!b(cleanTimeValues).a()) {
                while (b3.f75579b < b(cleanTimeValues).d()) {
                    b(cleanTimeValues).c();
                }
            }
            while (!b(cleanTimeValues).a() && f.equals(b(cleanTimeValues).b()) && b3.f75579b == b(cleanTimeValues).d()) {
                if (list.get(((TagPos) b(cleanTimeValues).f75569b.peek()).f75579b) != null) {
                    int i = b(cleanTimeValues).c().f75579b;
                    Object obj = list.get(i);
                    if (obj instanceof TagNode) {
                        a(listIterator, (TagNode) obj, cleanTimeValues);
                    } else if (obj instanceof List) {
                        Iterator it = ((List) obj).iterator();
                        while (it.hasNext()) {
                            listIterator.add((TagNode) it.next());
                            a(list, list.listIterator(list.size() - 1), cleanTimeValues);
                        }
                        list.set(i, null);
                    }
                } else {
                    b(cleanTimeValues).c();
                }
            }
        }
    }

    private void a(List list, ListIterator<BaseToken> listIterator, CleanTimeValues cleanTimeValues, TagNode tagNode, TagInfo tagInfo, TagPos tagPos) {
        int i;
        b(cleanTimeValues).a(tagPos, new TagPos(listIterator.previousIndex(), tagInfo.b()));
        this.f75566c.a(!tagNode.b("id"), (TagNode) list.get(tagPos.f75579b), ErrorType.UnpermittedChild);
        List<TagNode> a2 = a(list, tagPos, tagNode, cleanTimeValues);
        int size = a2.size();
        if (tagInfo.k() && size > 0) {
            ListIterator<TagNode> listIterator2 = a2.listIterator(size);
            ArrayList arrayList = new ArrayList();
            while (true) {
                if (!listIterator2.hasPrevious()) {
                    break;
                }
                TagNode previous = listIterator2.previous();
                if (!tagInfo.k(previous.f())) {
                    break;
                } else {
                    arrayList.add(0, previous);
                }
            }
            if (arrayList.size() > 0) {
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    TagNode tagNode2 = (TagNode) it.next();
                    if (a(tagNode2, listIterator)) {
                        it.remove();
                    } else {
                        listIterator.add(tagNode2.u());
                    }
                }
                for (i = 0; i < arrayList.size(); i++) {
                    listIterator.previous();
                }
            }
        }
        listIterator.previous();
    }

    private void a(ListIterator<BaseToken> listIterator, TagNode tagNode, CleanTimeValues cleanTimeValues) {
        TagNode u = tagNode.u();
        u.b(true);
        u.c("id");
        listIterator.add(u);
        a(cleanTimeValues).a(tagNode.f(), listIterator.previousIndex());
    }

    private boolean a(BaseToken baseToken, CleanTimeValues cleanTimeValues) {
        TagPos c2 = a(cleanTimeValues).c();
        if (c2 == null || c2.f75581d == null) {
            return true;
        }
        return c2.f75581d.a(baseToken);
    }

    private boolean a(TagInfo tagInfo, CleanTimeValues cleanTimeValues) {
        if (tagInfo == null || tagInfo.e().isEmpty()) {
            return true;
        }
        boolean z = false;
        Iterator<String> it = tagInfo.e().iterator();
        while (it.hasNext()) {
            if (a(cleanTimeValues).c(it.next())) {
                z = true;
            }
        }
        return z;
    }

    private static boolean a(TagNode tagNode, TagNode tagNode2) {
        return tagNode.f75610a.equals(tagNode2.f75610a) && tagNode.g().equals(tagNode2.g());
    }

    private static boolean a(TagNode tagNode, ListIterator<BaseToken> listIterator) {
        int i = 0;
        int i2 = 0;
        while (listIterator.hasNext() && i < 3) {
            BaseToken next = listIterator.next();
            i++;
            if (!(next instanceof TagNode)) {
                break;
            }
            TagNode tagNode2 = (TagNode) next;
            if (!tagNode2.v() || !a(tagNode2, tagNode)) {
                break;
            }
            i2++;
        }
        for (int i3 = 0; i3 < i; i3++) {
            listIterator.previous();
        }
        return i2 == 3;
    }

    private boolean a(Object obj) {
        return (obj instanceof TagNode) && !((TagNode) obj).o();
    }

    private boolean a(String str, CleanTimeValues cleanTimeValues) {
        String peek;
        if (!this.f75566c.p() || str == null) {
            return false;
        }
        if (str.contains(Constants.COLON_SEPARATOR)) {
            return true;
        }
        return (cleanTimeValues.m == null || cleanTimeValues.m.size() == 0 || (peek = cleanTimeValues.m.peek()) == null || peek.equals("http://www.w3.org/1999/xhtml")) ? false : true;
    }

    private boolean a(List list, CleanTimeValues cleanTimeValues) {
        boolean z = false;
        for (Object obj : list) {
            if ((obj instanceof TagNode) && !cleanTimeValues.k.contains(obj)) {
                TagNode tagNode = (TagNode) obj;
                if (b(tagNode, cleanTimeValues)) {
                    z = true;
                } else if (!tagNode.s()) {
                    z |= a(tagNode.i(), cleanTimeValues);
                }
            }
        }
        return z;
    }

    private ChildBreaks b(CleanTimeValues cleanTimeValues) {
        return cleanTimeValues.e.peek().b();
    }

    private TagInfo b(String str, CleanTimeValues cleanTimeValues) {
        if (a(str, cleanTimeValues)) {
            return null;
        }
        return b().a(str);
    }

    private void b(List list, CleanTimeValues cleanTimeValues) {
        boolean z;
        Iterator it = list.iterator();
        while (true) {
            boolean z2 = true;
            if (!it.hasNext()) {
                break;
            }
            Object next = it.next();
            if (next != null) {
                if (next instanceof TagNode) {
                    TagNode tagNode = (TagNode) next;
                    a(b().a(tagNode.f()), tagNode, cleanTimeValues);
                } else if (next instanceof ContentNode) {
                    z2 = true ^ "".equals(next.toString());
                }
                if (z2) {
                    cleanTimeValues.g.a(next);
                }
            }
        }
        for (TagNode tagNode2 : cleanTimeValues.f75543c) {
            TagNode c2 = tagNode2.c();
            while (true) {
                if (c2 == null) {
                    z = true;
                    break;
                } else {
                    if (cleanTimeValues.f75543c.contains(c2)) {
                        z = false;
                        break;
                    }
                    c2 = c2.c();
                }
            }
            if (z) {
                tagNode2.d();
                cleanTimeValues.h.a(tagNode2);
            }
        }
    }

    private void b(List list, ListIterator<BaseToken> listIterator, CleanTimeValues cleanTimeValues, BaseToken baseToken) {
        CleanerProperties cleanerProperties;
        ErrorType errorType;
        CleanerProperties cleanerProperties2;
        ErrorType errorType2;
        TagNode tagNode;
        TagNode tagNode2 = (TagNode) baseToken;
        String f = tagNode2.f();
        TagInfo b2 = b(f, cleanTimeValues);
        TagPos c2 = a(cleanTimeValues).a() ? null : a(cleanTimeValues).c();
        TagInfo b3 = c2 == null ? null : b(c2.f75580c, cleanTimeValues);
        cleanTimeValues.f75544d.add(f);
        if (tagNode2.b("xmlns")) {
            a(cleanTimeValues, tagNode2, f);
        }
        if (a(f, cleanTimeValues)) {
            tagNode2.d(true);
        } else {
            tagNode2.d(false);
        }
        if (com.tencent.common.http.ContentType.SUBTYPE_HTML.equals(f)) {
            tagNode = cleanTimeValues.f;
        } else if ("body".equals(f)) {
            cleanTimeValues.f75542b = true;
            tagNode = cleanTimeValues.g;
        } else {
            if (!"head".equals(f)) {
                if (b2 == null && this.f75566c.f() && !a(f, cleanTimeValues)) {
                    listIterator.set(null);
                    cleanerProperties2 = this.f75566c;
                    errorType2 = ErrorType.Unknown;
                } else {
                    if (b2 == null || !b2.f() || !this.f75566c.h()) {
                        if (b2 == null && b3 != null && !b3.o()) {
                            a(list, c2, tagNode2, cleanTimeValues);
                            listIterator.previous();
                            return;
                        }
                        if (b2 == null || !b2.l() || !a(cleanTimeValues).a(b2.c())) {
                            if (b2 != null && b2.g() && a(cleanTimeValues).d(f)) {
                                listIterator.set(null);
                                cleanerProperties = this.f75566c;
                                errorType = ErrorType.UniqueTagDuplicated;
                            } else if (a(b2, cleanTimeValues)) {
                                if (b(b2, cleanTimeValues)) {
                                    TagNode a2 = a(b2.d().iterator().next());
                                    if (a((BaseToken) a2, cleanTimeValues)) {
                                        a2.b(true);
                                        listIterator.previous();
                                        listIterator.add(a2);
                                        listIterator.previous();
                                        cleanerProperties = this.f75566c;
                                        errorType = ErrorType.RequiredParentMissing;
                                    }
                                } else {
                                    if (b2 != null && c2 != null && b2.a(b3)) {
                                        a(list, listIterator, cleanTimeValues, tagNode2, b2, c2);
                                        return;
                                    }
                                    if (a(baseToken, cleanTimeValues)) {
                                        if (b2 == null || b2.j()) {
                                            a(cleanTimeValues).a(f, listIterator.previousIndex());
                                            return;
                                        }
                                        TagNode a3 = a(tagNode2);
                                        a(b2, a3, cleanTimeValues);
                                        listIterator.set(a3);
                                        return;
                                    }
                                }
                                a(list, baseToken, cleanTimeValues);
                            } else {
                                listIterator.set(null);
                                cleanerProperties = this.f75566c;
                                errorType = ErrorType.FatalTagMissing;
                            }
                            cleanerProperties.a(true, tagNode2, errorType);
                            return;
                        }
                        listIterator.set(null);
                    }
                    listIterator.set(null);
                    cleanerProperties2 = this.f75566c;
                    errorType2 = ErrorType.Deprecated;
                }
                cleanerProperties2.b(true, tagNode2, errorType2);
                return;
            }
            cleanTimeValues.f75541a = true;
            tagNode = cleanTimeValues.h;
        }
        a(tagNode, tagNode2.g());
        listIterator.set(null);
    }

    private boolean b(TagInfo tagInfo, CleanTimeValues cleanTimeValues) {
        boolean z;
        TagPos b2;
        TagPos b3;
        if (tagInfo == null || tagInfo.d().isEmpty()) {
            return false;
        }
        int i = -1;
        for (String str : tagInfo.e()) {
            if (str != null && (b3 = a(cleanTimeValues).b(str)) != null) {
                i = b3.f75579b;
            }
        }
        loop1: while (true) {
            z = true;
            for (String str2 : tagInfo.d()) {
                if (str2 != null && (b2 = a(cleanTimeValues).b(str2)) != null) {
                    if (b2.f75579b <= i) {
                        break;
                    }
                    z = false;
                }
            }
        }
        if (!z) {
            return false;
        }
        ListIterator listIterator = a(cleanTimeValues).f75575b.listIterator(a(cleanTimeValues).f75575b.size());
        while (listIterator.hasPrevious()) {
            TagPos tagPos = (TagPos) listIterator.previous();
            if (tagInfo.j(tagPos.f75580c)) {
                return tagPos.f75579b <= i;
            }
        }
        return true;
    }

    private boolean b(TagNode tagNode, CleanTimeValues cleanTimeValues) {
        if (cleanTimeValues.j != null) {
            for (ITagNodeCondition iTagNodeCondition : cleanTimeValues.j) {
                if (iTagNodeCondition.a(tagNode)) {
                    a(tagNode, cleanTimeValues);
                    this.f75566c.a(iTagNodeCondition, tagNode);
                    return true;
                }
            }
        }
        if (cleanTimeValues.l == null || cleanTimeValues.l.isEmpty()) {
            return false;
        }
        Iterator<ITagNodeCondition> it = cleanTimeValues.l.iterator();
        while (it.hasNext()) {
            if (it.next().a(tagNode)) {
                return false;
            }
        }
        if (!tagNode.q()) {
            this.f75566c.c(true, tagNode, ErrorType.NotAllowedTag);
        }
        a(tagNode, cleanTimeValues);
        return true;
    }

    private NestingState c(CleanTimeValues cleanTimeValues) {
        return cleanTimeValues.e.push(new NestingState());
    }

    private void c(List list, CleanTimeValues cleanTimeValues) {
        TagPos b2 = a(cleanTimeValues).b();
        Iterator it = a(cleanTimeValues).f75575b.iterator();
        while (it.hasNext()) {
            this.f75566c.a(true, (TagNode) list.get(((TagPos) it.next()).f75579b), ErrorType.UnclosedTag);
        }
        if (b2 != null) {
            a(list, b2, (Object) null, cleanTimeValues);
        }
    }

    private NestingState d(CleanTimeValues cleanTimeValues) {
        return cleanTimeValues.e.pop();
    }

    public CleanerProperties a() {
        return this.f75566c;
    }

    public TagNode a(InputStream inputStream) throws IOException {
        return a(inputStream, this.f75566c.A());
    }

    public TagNode a(InputStream inputStream, String str) throws IOException {
        return a(new InputStreamReader(inputStream, str), new CleanTimeValues());
    }

    protected TagNode a(Reader reader, CleanTimeValues cleanTimeValues) throws IOException {
        c(cleanTimeValues);
        cleanTimeValues.f75541a = false;
        cleanTimeValues.f75542b = false;
        cleanTimeValues.f75543c.clear();
        cleanTimeValues.f75544d.clear();
        cleanTimeValues.j = new HashSet(this.f75566c.x());
        cleanTimeValues.l = new HashSet(this.f75566c.z());
        this.f75567d = this.f75566c.D();
        cleanTimeValues.k.clear();
        cleanTimeValues.f = a(com.tencent.common.http.ContentType.SUBTYPE_HTML);
        cleanTimeValues.g = a("body");
        cleanTimeValues.h = a("head");
        cleanTimeValues.i = null;
        cleanTimeValues.f.a(cleanTimeValues.h);
        cleanTimeValues.f.a(cleanTimeValues.g);
        HtmlTokenizer htmlTokenizer = new HtmlTokenizer(this, reader, cleanTimeValues);
        htmlTokenizer.c();
        List<BaseToken> a2 = htmlTokenizer.a();
        c(a2, cleanTimeValues);
        b(a2, cleanTimeValues);
        a(cleanTimeValues, htmlTokenizer.b());
        do {
        } while (a(a2, cleanTimeValues));
        if (cleanTimeValues.k != null && !cleanTimeValues.k.isEmpty()) {
            for (TagNode tagNode : cleanTimeValues.k) {
                TagNode c2 = tagNode.c();
                if (c2 != null) {
                    c2.b(tagNode);
                }
            }
        }
        cleanTimeValues.i.a(htmlTokenizer.d());
        d(cleanTimeValues);
        return cleanTimeValues.i;
    }

    protected void a(TagNode tagNode, CleanTimeValues cleanTimeValues) {
        tagNode.c(true);
        cleanTimeValues.k.add(tagNode);
    }

    public void a(List list, ListIterator<BaseToken> listIterator, CleanTimeValues cleanTimeValues) {
        while (listIterator.hasNext()) {
            BaseToken next = listIterator.next();
            if (next instanceof EndTagToken) {
                a(list, listIterator, cleanTimeValues, (EndTagToken) next);
            } else if (a(next)) {
                b(list, listIterator, cleanTimeValues, next);
            } else {
                a(list, listIterator, cleanTimeValues, next);
            }
        }
    }

    public ITagInfoProvider b() {
        return this.f75566c.a();
    }

    public CleanerTransformations c() {
        return this.f75567d;
    }
}