filterfontstyle.java

来自「JSP聊天系统」· Java 代码 · 共 59 行

JAVA
59
字号
package org.ehotsoft.yekki.filter;

import org.ehotsoft.yekki.util.StringUtil;

import java.io.Serializable;
import java.util.Properties;

public class FilterFontStyle extends Filter
    implements java.io.Serializable {

    private Properties props;

    public FilterFontStyle( Message message ) {

        super( message );
        props = new Properties();
		initializeProperties();
	}

    protected String filter( String content) {
        return fontStyleToHTML( content );
    }

    private void initializeProperties() {

        props.put("Bold", "on");
        props.put("Italics", "on");
    }

    private String fontStyleToHTML(String s) {

        if(s == null || s.length() == 0)
            return s;
        int ai[] = new int[1];
        int ai1[] = new int[1];
        int ai2[] = new int[1];
        int ai3[] = new int[1];
        if(props.getProperty("Bold").equals("on"))
        {
            s = StringUtil.replace(s, "[b]", "<b>", ai);
            s = StringUtil.replace(s, "[/b]", "</b>", ai2);
            int i = ai[0];
            for(int k = ai2[0]; i > k; k++)
                s = s.concat("</b>");

        }
        if(props.getProperty("Italics").equals("on"))
        {
            s = StringUtil.replace(s, "[i]", "<i>", ai1);
            s = StringUtil.replace(s, "[/i]", "</i>", ai3);
            int j = ai1[0];
            for(int l = ai3[0]; j > l; l++)
                s = s.concat("</i>");

        }
        return s;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?