进入旧版 | 服务项目 | 成功案例 | 联系方式 | 过客留言 | 友情链接
   
设为首页
加入收藏
联系我们
网站首页 | 新闻资讯 | 操作系统 | 办公软件 | 网络软件 | 工具软件 | 媒体动画 | 网页制作 | 网站开发 | 程序开发 | 平面设计
Photoshop视频教程 | Word入门 | Flash入门 | JScript | VBScript | ASP | PHP | ADO | 网页特效 | 3DS MAX6.0命令 | 系统进程
您当前的位置:GOODSGY电脑学习网 -> 网站开发 -> JSP -> 文章内容  
Use Java to implement the UBB future.

UBB & JAVA
    ----Use Java to implement the UBB future.

[Author] pizer.chen -- iceant -- 陈鹏
iceant@21cn.com
[icq   ] 77777369

These days,I write some publish system,just like BBS/news etc.
The client asked me ,whether they can insert the image and href url to the plain text when they published them.
so i write this.
I use XML file for dynamic UBB extends.
U can make the UBB rule of yourself.
The only thing that u need to do is modify the UBB.XML config file.

Best Regards
===============
                                                                    pizer.chen/2001-9-4

===========================
    Resource Link
===========================
It is based on XML & RegularExpressions tech.
about XML & regularExpression u can find them here:

http://www.w3.org/XML/ ;    
http://XML.apache.org
http://www.meurrens.org/ip-Links/java/regex/navi.HTML
http://www.savarese.org/oro/
http://jakarta.apache.org/oro
about ubb u can find them here:
http://www.ubbdesign.com

========================
it used :
    jakarta-regexp-1.2              (download form http://jakarta.apache.org)
    dom4j-0.6(over 0.6 version)     (download form http://sourceforge.net)
    jdk(over 1.2 version)           (download form http://java.sun.com)

==========================
        UBB.XML
it must be stored in CLASSPATH
==========================
the regularExpression & replace string map file.
<!--============================-->

<?XML version="1.0" encoding="UTF-8"?>
<UBB-map>
    <map ubb-code="\[b\](.+?)\[\/b\]" map-to="<b>$1</b>"/>         <!--<b>$1</b>-->
    <map ubb-code="\[i\](.+?)\[\/i\]" map-to="<i>$1</i>"/>         <!--<i>$1</i>-->
    <map ubb-code="\[h1\](.+?)\[\/h1\]" map-to="<h1>$1</h1>"/>     <!--<h1>$1</h1>-->
    <map ubb-code="\(.+?)\[\/url\]" map-to="<a href=../../"$1" target="_blank">$2</a>"/>        <!--<a href=../../"$1" target="_blank">$2</a>-->
    <!--...-->
</UBB-map>

=========================

        UBB.java

=========================

/*
* UBB.java
*
* Created on 2001年9月3日, 下午4:01
*/

package com.wacos.util.ubb;

import org.dom4j.*;
import org.dom4j.io.*;
import java.io.*;
import java.util.*;
import org.apache.regexp.*;
/**
*
* @author  Pizer.chen -- iceant -- 陈鹏
* @version 0.1
*/
public class UBB {
    
    private static final String XML_CONFIG_FILE = "UBB.XML";
    private static org.dom4j.Document doc = null;
     
    /** Creates new UBB */
    public UBB() {
    }
    
    public static String parse(String inStr){
        try{
            List list = getUBBCodeList();
            String ubbCode="";
            String mapStr="";
            Attribute attribute=null;
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                attribute = (Attribute) iter.next();
                ubbCode = attribute.getValue();
                mapStr= getMapValue(ubbCode);
                inStr=REReplace.replace(ubbCode,mapStr,inStr);
            }
            return inStr;
        }catch(Exception err){
            System.out.println(err);
            return err.toString();
        }
    }

    /**
     * parse the XML file to Document object
    **/
    private static Document XML2Document(){
        try{
            InputStream is = Thread.currentThread().getContextClassLoader()
                            .getResourceAsStream(XML_CONFIG_FILE);
            SAXReader reader = new SAXReader();
            Document document = reader.read(is);
            return document;
        }catch(Exception err){
            System.out.println(err);
            return null;
        }
    }

    /**
     * use xpath to get the map-to value of the ubb-code.
    **/
    private static String getMapValue(String ubbCode){
        try{
            if(doc==null){
                doc=XML2Document();
            }
            Node node = doc.selectSingleNode("//map[@ubb-code='"+ubbCode+"']");
            return node.valueOf( "@map-to" );
        }catch(Exception err){
            System.out.println(err);
            return err.toString();
        }
    }
    /**
     * get the <map ubb-code="..." map-to=".."> ubb-code List
    **/
    private static List getUBBCodeList(){
        try{
            if(doc==null){
                doc=XML2Document();
            }
            return doc.selectNodes( "//map/@ubb-code" );
        }catch(Exception err){
            System.out.println(err);
            return null;
        }
    }
    /**
     * get the <map ubb-code="..." map-to=".."> map-to List
    **/
    private static List getUBBMapList(){
        try {
            if(doc==null){
                doc=XML2Document();
            }
            return doc.selectNodes("//map//@map-to");
        }
        catch (Exception e) {
            System.out.println(e);
            return null;
        }
    }
}

========================

     REReplace.java

========================
package com.wacos.util.ubb;

import java.io.*;
import java.util.*;
import org.apache.regexp.*;

public class REReplace
{
    /**
     * replace the inStr with pattern1 & pattern2
    **/
    public static String replace(String pattern1,String pattern2,String inStr){
        try {
            RE re = new RE(pattern1);
            int point=0;
            while(re.match(inStr)){
                RE re2 = new RE("\\$([0-9])");
                while(re2.match(pattern2)){
                    point = Integer.parseInt(re2.getParen(1));
                    pattern2=re2.subst(pattern2,re.getParen(point),RE.REPLACE_FIRSTONLY);
                }
                inStr = re.subst(inStr,pattern2);
            }
            return inStr;
        }
        catch (Exception e) {
            System.out.println(e);
            return e.toString();
        }  
    }

}


=============================
        UBBTest
=============================
package com.wacos.util.ubb;

public class UBBTest
{
    public static void main(String[] args)
    {
        try{
            String test ="atest

H1 Font

\r\n [url href=http://www.21cn.com]测试hehe..";

            System.out.println(UBB.parse(test));
        }catch(Exception err){
            System.out.println(err);
        }
    }
}


在百度中搜索:Use Java to implement the UBB future.
在Google中搜索:Use Java to implement the UBB future.
在Yahoo中搜索:Use Java to implement the UBB future.

收藏到网摘:新浪VIVI 365key 我摘 POCO网摘 博采中心 YouNote 和讯网摘 天天收藏
[] [返回上一页] [打 印] [收 藏]

 相关文章    最新文章
· 微软开始调查Vista更新造成USB失效问题
· 微软Vista补丁存有缺陷 导致USB设备无法响..
· Oracle为Linux提供clusterware
· 如何删除Illustrator中过多的样式?
· [组图] QQ技巧:QQ引起USB键盘间歇性失效的..
· [组图] 用IEPlus武装IE获取傲游的快感
· [组图] Shape,Custom Shape,Layer Clipp..
· [组图] Photoshop CS2 custom menu自定义菜..
· adusermon.exe
· userinit.exe
 
· 提升JSP页面响应速度的七大秘籍绝招
· 开发一个调试JSP的Eclipse插件
· JSP报表打印的一种简单解决方案
· JSP/Servlet的重定向技术综述
· java的md5加密类(zt)
· 一个用来访问http服务器的东西。功能类似..
· 菜鸟调试手记一(sql server 中文问题)
· Java性能优化技巧集锦(2)
· 用java压缩文件示例(没有中文问题)
· 使用XML/HTC/DHTML模拟标准Windows菜单

∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
站内搜索

精彩图文
  网站导航  
操作系统 办公软件 网络软件
Vista Windows2003 WindowsXP Windows2000/NT Windows9X/ME Linux 其他 Word Excel Powerpoint Outlook 金山系列 其他 网页浏览 上传下载 联络聊天 邮件工具 服务器软件 网络辅助
工具软件 媒体动画 网页制作
系统工具 媒体工具 压缩工具 图文处理 文件管理 其他 3DMAX Authorware Director Maya 视频处理 其他 Flash Dreamweaver FireWorks FrontPage LiveMotion Golive HTML/CSS 其它
网站开发 平面设计 程序设计
ASP JSP PHP CGI JavaScript VBScript XML/SOAP Web服务器 Photoshop PhotoImpact CorelDraw Illustrator Freehand 设计欣赏 其他 VB VC .NET C/C++ DELPHI JAVA

冀ICP备05019428号
Copyright © 2004-2008 电脑学习网 Inc.All rights reserved.
TEL:13832340607
QQ:39873155
E_Mail:goodsgy(#)hotmail.com   (把(#)替换成@)
MSN:goodsgy(#)hotmail.com   (把(#)替换成@)