仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1532|回复: 19
打印 上一主题 下一主题

[学习教程] JAVA网页设计Use Java to implement the UBB future...

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:44:09 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
通过视频学习比传统的大课堂学习更适合成人化的学习规律。有人说大课堂气氛好,学习氛围浓,热闹,可以认识很多人。ubbUBB&JAVA
----UseJavatoimplementtheUBBfuture.

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

Thesedays,Iwritesomepublishsystem,justlikeBBS/newsetc.
Theclientaskedme,whethertheycaninserttheimageandhrefurltotheplaintextwhentheypublishedthem.
soiwritethis.
IusexmlfilefordynamicUBBextends.
UcanmaketheUBBruleofyourself.
TheonlythingthatuneedtodoismodifytheUBB.xmlconfigfile.

BestRegards
===============
pizer.chen/2001-9-4

===========================
ResourceLink
===========================
Itisbasedonxml&RegularExpressionstech.
aboutxml&regularExpressionucanfindthemhere:

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
aboutubbucanfindthemhere:
http://www.ubbdesign.com

========================
itused:
jakarta-regexp-1.2(downloadformhttp://jakarta.apache.org)
dom4j-0.6(over0.6version)(downloadformhttp://sourceforge.net)
jdk(over1.2version)(downloadformhttp://java.sun.com)

==========================
UBB.XML
itmustbestoredinCLASSPATH
==========================
theregularExpression&replacestringmapfile.
<!--============================-->

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

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

UBB.java

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

/*
*UBB.java
*
*Createdon2001年9月3日,下战书4:01
*/

packagecom.wacos.util.ubb;

importorg.dom4j.*;
importorg.dom4j.io.*;
importjava.io.*;
importjava.util.*;
importorg.apache.regexp.*;
/**
*
*@authorPizer.chen--iceant--陈鹏
*@version0.1
*/
publicclassUBB{

privatestaticfinalStringXML_CONFIG_FILE="UBB.xml";
privatestaticorg.dom4j.Documentdoc=null;

/**CreatesnewUBB*/
publicUBB(){
}

publicstaticStringparse(StringinStr){
try{
Listlist=getUBBCodeList();
StringubbCode="";
StringmapStr="";
Attributeattribute=null;
for(Iteratoriter=list.iterator();iter.hasNext();){
attribute=(Attribute)iter.next();
ubbCode=attribute.getValue();
mapStr=getMapValue(ubbCode);
inStr=REReplace.replace(ubbCode,mapStr,inStr);
}
returninStr;
}catch(Exceptionerr){
System.out.println(err);
returnerr.toString();
}
}

/**
*parsethexmlfiletoDocumentobject
**/
privatestaticDocumentxml2Document(){
try{
InputStreamis=Thread.currentThread().getContextClassLoader()
.getResourceAsStream(XML_CONFIG_FILE);
SAXReaderreader=newSAXReader();
Documentdocument=reader.read(is);
returndocument;
}catch(Exceptionerr){
System.out.println(err);
returnnull;
}
}

/**
*usexpathtogetthemap-tovalueoftheubb-code.
**/
privatestaticStringgetMapValue(StringubbCode){
try{
if(doc==null){
doc=xml2Document();
}
Nodenode=doc.selectSingleNode("//map[@ubb-code="+ubbCode+"]");
returnnode.valueOf("@map-to");
}catch(Exceptionerr){
System.out.println(err);
returnerr.toString();
}
}
/**
*getthe<mapubb-code="..."map-to="..">ubb-codeList
**/
privatestaticListgetUBBCodeList(){
try{
if(doc==null){
doc=xml2Document();
}
returndoc.selectNodes("//map/@ubb-code");
}catch(Exceptionerr){
System.out.println(err);
returnnull;
}
}
/**
*getthe<mapubb-code="..."map-to="..">map-toList
**/
privatestaticListgetUBBMapList(){
try{
if(doc==null){
doc=xml2Document();
}
returndoc.selectNodes("//map//@map-to");
}
catch(Exceptione){
System.out.println(e);
returnnull;
}
}
}

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

REReplace.java

========================
packagecom.wacos.util.ubb;

importjava.io.*;
importjava.util.*;
importorg.apache.regexp.*;

publicclassREReplace
{
/**
*replacetheinStrwithpattern1&pattern2
**/
publicstaticStringreplace(Stringpattern1,Stringpattern2,StringinStr){
try{
REre=newRE(pattern1);
intpoint=0;
while(re.match(inStr)){
REre2=newRE("$([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);
}
returninStr;
}
catch(Exceptione){
System.out.println(e);
returne.toString();
}
}

}


=============================
UBBTest
=============================
packagecom.wacos.util.ubb;

publicclassUBBTest
{
publicstaticvoidmain(String[]args)
{
try{
Stringtest="atestH1Font


[urlhref=http://www.21cn.com]测试hehe..";

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


唉!都是钱闹的1.Swing和.net开发比较------从市场份额看.net开发主要占据大部分的中小型和中型的的桌面开发,原因是它封装了很多工具
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-22 03:18

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表