/*
 * Decompiled with CFR 0.152.
 */
package com.hst.common.filter;

import com.hst.common.exception.StringFilterException;

public class StringFilter {
    private StringBuffer stringBuffer;

    public StringFilter(String strFilter) {
        this.stringBuffer = new StringBuffer(strFilter);
    }

    public void linkFilter() throws StringFilterException {
        try {
            boolean theFlag;
            do {
                int upperIndex = this.stringBuffer.indexOf("<A");
                int lowerIndex = this.stringBuffer.indexOf("<a");
                int inputIndex = 0;
                int n = inputIndex = upperIndex > lowerIndex ? lowerIndex : upperIndex;
                if (upperIndex == -1) {
                    inputIndex = lowerIndex;
                }
                if (lowerIndex == -1) {
                    inputIndex = upperIndex;
                }
                if (inputIndex > -1) {
                    int endIndex = this.stringBuffer.indexOf(">", inputIndex);
                    this.stringBuffer.delete(inputIndex, endIndex + 1);
                    int tempIndex = 0;
                    tempIndex = this.stringBuffer.indexOf("</a>");
                    if (tempIndex > -1) {
                        this.stringBuffer.delete(tempIndex, tempIndex + 4);
                    }
                    if ((tempIndex = this.stringBuffer.indexOf("</A>")) > -1) {
                        this.stringBuffer.delete(tempIndex, tempIndex + 4);
                    }
                    theFlag = true;
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void spaceFilter() throws StringFilterException {
        try {
            boolean theFlag;
            do {
                int index;
                if ((index = this.stringBuffer.indexOf("&nbsp;")) > -1) {
                    this.stringBuffer.delete(index, index + 6);
                    theFlag = true;
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void imgFilter() throws StringFilterException {
        boolean theFlag = false;
        try {
            do {
                int index;
                int index1 = this.stringBuffer.indexOf("<IMG");
                int index2 = this.stringBuffer.indexOf("<img");
                if (index1 == -1) {
                    index1 = index2;
                }
                if (index2 == -1) {
                    index2 = index1;
                }
                int n = index = index1 >= index2 ? index2 : index1;
                if (index > -1) {
                    int endIndex = this.stringBuffer.indexOf(">", index);
                    this.stringBuffer.delete(index, endIndex + 1);
                    theFlag = true;
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void checkboxFilter() throws StringFilterException {
        boolean theFlag = false;
        try {
            do {
                int index;
                if ((index = this.stringBuffer.indexOf("checkbox")) > -1) {
                    int firstIndex = this.stringBuffer.lastIndexOf("<", index);
                    int lastIndex = this.stringBuffer.indexOf(">", index);
                    this.stringBuffer.delete(firstIndex, lastIndex + 1);
                    theFlag = true;
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void hiddenFilter() throws StringFilterException {
        boolean theFlag = false;
        try {
            do {
                int index;
                if ((index = this.stringBuffer.indexOf("hidden")) > -1) {
                    int firstIndex = this.stringBuffer.lastIndexOf("<", index);
                    int lastIndex = this.stringBuffer.indexOf(">", index);
                    this.stringBuffer.delete(firstIndex, lastIndex + 1);
                    theFlag = true;
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void inputFilter() throws StringFilterException {
        boolean theFlag = true;
        try {
            do {
                int index;
                int index1 = this.stringBuffer.indexOf("<INPUT");
                int index2 = this.stringBuffer.indexOf("<input");
                if (index1 == -1) {
                    index1 = index2;
                }
                if (index2 == -1) {
                    index2 = index1;
                }
                int n = index = index1 >= index2 ? index2 : index1;
                if (index > -1) {
                    int closeTagIndex = this.stringBuffer.indexOf(">", index);
                    int valueFirstIndex = this.stringBuffer.indexOf("value=\"", index);
                    boolean bz = false;
                    if (valueFirstIndex > -1 && closeTagIndex > valueFirstIndex) {
                        bz = true;
                    } else {
                        valueFirstIndex = this.stringBuffer.indexOf("value=", index);
                    }
                    if (valueFirstIndex > -1) {
                        if (closeTagIndex > valueFirstIndex) {
                            String value;
                            int valueLastIndex;
                            if (bz) {
                                valueLastIndex = this.stringBuffer.indexOf(" ", valueFirstIndex + 7);
                                if (valueLastIndex > closeTagIndex || valueLastIndex == -1) {
                                    valueLastIndex = closeTagIndex;
                                }
                                value = this.stringBuffer.substring(valueFirstIndex + 7, valueLastIndex);
                            } else {
                                valueLastIndex = this.stringBuffer.indexOf(" ", valueFirstIndex + 6);
                                if (valueLastIndex > closeTagIndex || valueLastIndex == -1) {
                                    valueLastIndex = closeTagIndex;
                                }
                                value = this.stringBuffer.substring(valueFirstIndex + 6, valueLastIndex);
                            }
                            this.stringBuffer.delete(index, closeTagIndex + 1);
                            this.stringBuffer.insert(index, value);
                            continue;
                        }
                        this.stringBuffer.delete(index, closeTagIndex + 1);
                        continue;
                    }
                    this.stringBuffer.delete(index, closeTagIndex + 1);
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void textareaFilter() throws StringFilterException {
        boolean theFlag = false;
        try {
            do {
                int index;
                if ((index = this.stringBuffer.indexOf("<TEXTAREA")) > -1) {
                    int lastIndex = this.stringBuffer.indexOf(">", index);
                    this.stringBuffer.delete(index, lastIndex + 1);
                    int endTagIndex = this.stringBuffer.indexOf("</TEXTAREA>");
                    if (endTagIndex > -1) {
                        this.stringBuffer.delete(endTagIndex, endTagIndex + 11);
                    }
                    theFlag = true;
                    continue;
                }
                theFlag = false;
            } while (theFlag);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void classFilter() throws StringFilterException {
        int index = 0;
        int beginIndex = 0;
        try {
            do {
                int valueLastIndex2;
                if ((index = this.stringBuffer.indexOf("class=", beginIndex + 1)) <= -1) continue;
                int valueLastIndex = 0;
                int valueLastIndex1 = this.stringBuffer.indexOf(">", index);
                valueLastIndex = valueLastIndex1 > (valueLastIndex2 = this.stringBuffer.indexOf(" ", index)) ? valueLastIndex2 : valueLastIndex1;
                this.stringBuffer = this.stringBuffer.replace(index + 6, valueLastIndex, "number_formater");
                beginIndex = this.stringBuffer.indexOf("class=", index);
            } while (index != -1);
        }
        catch (Throwable t) {
            throw new StringFilterException(t);
        }
    }

    public void filter() {
        this.stringBuffer = new StringBuffer(this.stringBuffer.toString().replaceAll("<[^<>]+>", ""));
    }

    public String toString() {
        return this.stringBuffer.toString();
    }
}
