⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jubb.java

📁 JAVA编写的远程教育程序,包含了教育学的基本思想和网络应用程序的基本开发模式
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.whatratimes.util;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

/*
-----------程序说明-------------
程序名称:JAVA写的JUBB
程序作者:Redhat
发布时间:2003.5.23
主页:http://2002.buyionline.net
授权:免费、自由传播及自由修改但请保留原作者信息
版本:1.0
使用的时候最好转换成JAVABEAN,加入你和JAVA LIB中去.
*/

public class JUBB
{
    public static JUBB jubb = new JUBB();

    public static String getHTML(String ubb, int question_id)
    {
        return jubb.getAll(ubb, question_id);
    }

    public static String getNoTag(String ubb )
    {
        String s = ubb;
        s = jubb.replace(s, "&", "&");
        s = jubb.replace(s, "\"", """);
        s = jubb.replace(s, "<", "&lt;");
        s = jubb.replace(s, ">", "&gt;");
        return s;
    }

    public static String getBrText(String ubb)
    {
        String s = ubb;
        s = jubb.replace(s, "&", "&amp;");
        s = jubb.replace(s, "\"", "&quot;");
        s = jubb.replace(s, "<", "&lt;");
        s = jubb.replace(s, ">", "&gt;");
        return jubb.ReBr(s);
    }

    String u_s = new String("haha");
    String u_s1 = new String("haha");
    Pattern u_p;
    Matcher u_m;
    CharSequence u_s2;
    boolean result;

    /** 得到转换后的所有JUBB代码 */
    public String getAll(String ins, int question_id)
    {
        String s = ins;
        s = this.replace(s, "&", "&amp;");
        s = this.replace(s, "\"", "&quot;");
        s = this.replace(s, "<", "&lt;");
        s = this.replace(s, ">", "&gt;");
        s = this.ReColor(s);
        s = this.ReImg(s, question_id);
        s = this.ReUrl(s);
//        s = this.ReFly(s);
        s = this.ReEmail(s);
        s = this.ReBold(s);
//        s = this.ReSlope(s);
//        s = this.ReDownLine(s);
//        s = this.ReMove(s);
        s = this.ReTxtUrl(s);
        s = this.ReTxtEmail(s);
        s = this.ReTxtSize(s);
//        s = this.ReQuote(s);
//        s = this.ReCode(s);
//        s = this.ReSup(s);
//        s = this.ReSub(s);
//        s = this.ReDelLine(s);
//        s = this.ReFliph(s);
//        s = this.ReFlipv(s);
//        s = this.ReShadow(s);
//        s = this.ReGlow(s);
//        s = this.ReBlur(s);
//        s = this.ReSwf(s);
//        s = this.ReRm(s);
//        s = this.ReMp(s);
//        s = this.ReSk(s);
//        s = this.ReSound(s);
//        s = this.ReInvert(s);
//        s = this.ReXray(s);
//        s = this.ReLi(s);
//        s = this.ReLi1(s);
//        s = this.ReLi2(s);
        s = this.ReBr(s);
        s = this.ReAlign(s);
//        s = this.ReQt(s);
        s = this.ReFace(s);
        s = this.ReSpace(s);

        return s;
    }

    /** 每个替换都需要用到的公共函数 */
    public String replace(String strSource, String strFrom, String strTo)
    {
        String strDest = "";
        int intFromLen = strFrom.length();
        int intPos;
        while ((intPos = strSource.indexOf(strFrom)) != -1)
        {
            strDest = strDest + strSource.substring(0, intPos);
            strDest = strDest + strTo;
            strSource = strSource.substring(intPos + intFromLen);
        }
        strDest = strDest + strSource;
        return strDest;
    }



    //
    //    <font color="#FF0000">hhhhhh</font>
    /** 转换URL([url=http://www.sina.com.cn]新浪[/url]) */
    /** Color替换([color=#dbff00]aaaa[/color]) */
    public String ReColor(String ins)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[color=)([^\\]]+)(\\])(.+?)(\\[\\/color\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3) + this.u_m.group(4) + this.u_m.group(5), "<font color='" + this.u_m.group(2) + "'>" + this.u_m.group(4) + "</font>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

    /** IMG替换([img]http://domain.com/path/img.jpg[/img]) */
    public String ReImg(String ins, int question_id)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[img\\])(.+?)(\\[\\/img\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3), "<img src=../CourseQuestion/"+ question_id +"/" + this.u_m.group(2) + " border=0>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

    /** 图片底片效果([invert]img.jpg[/invert]) */
    public String ReInvert(String ins)
    {

        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[invert\\])(.+?)(\\[\\/invert\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3), "<table style=\"filter:invert\"><img src=" + this.u_m.group(2) + " border=0></table>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

    /** 图片曝光效果([xray]img.jpg[/xray]) */
    public String ReXray(String ins)
    {

        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[xray\\])(.+?)(\\[\\/xray\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3), "<table style=\"filter:xray\"><img src=" + this.u_m.group(2) + " border=0></table>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }


    /** 转换URL([url]http://somedomain[/url]) */
    public String ReUrl(String ins)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[url\\])(.+?)(\\[\\/url\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3), "<a href=" + this.u_m.group(2) + " target=_blank>" + this.u_m.group(2) + "</a>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

    /** 转换URL([url=http://www.sina.com.cn]新浪[/url]) */
    public String ReTxtUrl(String ins)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[url=)([^\\]]+)(\\])(.+?)(\\[\\/url\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3) + this.u_m.group(4) + this.u_m.group(5), "<a href=" + this.u_m.group(2) + " target=_blank title=" + this.u_m.group(4) + ">" + this.u_m.group(4) + "</a>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

    /** 转换EMAIL([email]redhat@hnwj.net[/email]) */
    public String ReEmail(String ins)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[email\\])(.+?)(\\[\\/email\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3), "<a href=mailto:" + this.u_m.group(2) + ">" + this.u_m.group(2) + "</a>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

    /** 转换Email([email=redhat@hnwj.net]给我写信[/email]) */
    public String ReTxtEmail(String ins)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[email=)([^\\]]+)([\\]])(.+?)(\\[\\/email\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3) + this.u_m.group(4) + this.u_m.group(5), "<a href=mailto:" + this.u_m.group(2) + ">" + this.u_m.group(4) + "</a>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {
        }

        return u_s;
    }

//<font face="Georgia, Times New Roman, Times, serif">AALISjjjlllutchTAAA</font>
//    [face=Arial Black]kkkk[/face]
    public String ReFace(String ins)
    {
        this.u_s1 = ins;
        this.u_s = ins;
        this.u_s2 = this.u_s1.subSequence(0, this.u_s1.length());

        try
        {
            this.u_p = Pattern.compile("(\\[face=)([^\\]]+)([\\]])(.+?)(\\[\\/face\\])", Pattern.CASE_INSENSITIVE);
            this.u_m = this.u_p.matcher(this.u_s2);
            this.result = this.u_m.find();
            while (result)
            {
                this.u_s = this.replace(this.u_s1, this.u_m.group(1) + this.u_m.group(2) + this.u_m.group(3) + this.u_m.group(4) + this.u_m.group(5), "<font face='" + this.u_m.group(2) + "'>" + this.u_m.group(4) + "</font>");
                this.u_s1 = this.u_s;
                this.u_m.find();
            }
        } catch (Exception e)
        {

⌨️ 快捷键说明

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