tambc
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
5 Posts :: 21 Stories :: 5 Comments :: 0 Trackbacks
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2007年2月 (2)
2006年12月 (3)
文章分類
Ajax
C#(1)
Delphi(3)
Hibernate(1)
Java(14)
JavaScript(7)
Oracle
Spring
SQLServer(1)
Struts
全文檢索(3)
工作流學(xué)習(xí)
文章檔案
2007年2月 (1)
2007年1月 (1)
2006年12月 (16)
搜索
最新評論
1.?re: textarea控制字符數(shù)
收益匪淺
--ljh
2.?re: textarea控制字符數(shù)
評論內(nèi)容較長,點擊標題查看
--fdsa
3.?re: 免費部署 與同時訪問此網(wǎng)頁的網(wǎng)友聊天[未登錄]
股票
--秋風(fēng)
4.?re: 實現(xiàn)HTTP長連接(服務(wù)器推)
yao lianjie
--張偉
5.?re: 近來使用velocity來生成網(wǎng)站靜態(tài)頁面
re: 近來使用velocity來生成網(wǎng)站靜態(tài)頁面的地址
--gv
閱讀排行榜
1.?近來使用velocity來生成網(wǎng)站靜態(tài)頁面(1393)
2.?轉(zhuǎn):基于Java的開源 Carrot2 搜索結(jié)果聚合聚類引擎 2.0(700)
3.?使用C3P0時一個怪異的事情(471)
4.?用JS讓查看源代碼時什么也看不到(411)
5.?免費部署 與同時訪問此網(wǎng)頁的網(wǎng)友聊天(338)
評論排行榜
1.?免費部署 與同時訪問此網(wǎng)頁的網(wǎng)友聊天(1)
2.?近來使用velocity來生成網(wǎng)站靜態(tài)頁面(1)
3.?用JS讓查看源代碼時什么也看不到(0)
4.?轉(zhuǎn):基于Java的開源 Carrot2 搜索結(jié)果聚合聚類引擎 2.0(0)
5.?使用C3P0時一個怪異的事情(0)
java的ubb類
?
import
??java.util.regex.?
*
?;?
//
?導(dǎo)入正則表達式包中的類?
?
/**?*/
/**
?
?*??使網(wǎng)頁支持ubbcode.
?*??
@author
??shanwei
?*??
@version
??1.0
??
*/
?
?
public
???
final
???
class
??Ubbcode?
{
?
?????
private
???
static
???
final
??String?ImagePath??
=
???
"
?images/?
"
?;??
//
?定義圖片路徑?
?????
private
???
static
???
final
??String?emotImagePath??
=
???
"
?images/emot/?
"
?;
?
?????
/**?*/
/**
?
?????*?@description?轉(zhuǎn)換代碼,使之支持ubbcode.
?????*??
@param
??strContent?轉(zhuǎn)換前的代碼.
?????*??
@return
??result?轉(zhuǎn)換后的內(nèi)容.
??????
*/
?
?????
public
???
static
??String?UBBCode(String?strContent)?
{??
//
????????strContent??
=
??dvHTMLEncode(strContent);
????????strContent??
=
??FilterJS(strContent);
????????String?re;
?????????
//
?re.IgnoreCase?=true
?????????
//
?re.Global=True?
????????Pattern?pattern??
=
???
null
?;??
//
????????Matcher?matcher??
=
???
null
?;
?????????
//
?轉(zhuǎn)換IMG?
????????re??
=
???
"
?\\[IMG\\](http|https|ftp):\\/\\/(.[^\\[]*)\\[\\/IMG\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<?a?onfocus=this.blur()?href=\?
"
?$?
1
?:?
//
?$2\"?target=_blank><IMG?SRC=\"$1:??
//
?$2\"?border=0?alt=按此在新窗口瀏覽圖片?onload=\"javascript:if(this.width>?screen.width-333)this.width=screen.width-333\"></a>");
?????????
//
?轉(zhuǎn)換UPLOAD?
????????re??
=
???
"
?\\[UPLOAD=(gif|jpg|jpeg|bmp|png)\\](.[^\\[]*)(gif|jpg|jpeg|bmp|png)\\[\\/UPLOAD\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<br><IMG?SRC=\?
""
??+?ImagePath?+??
"
?$?
1
?.gif?\?
"
??border=0>此主題相關(guān)圖片如下:<br><A?HREF=\?
"
?$?
2
?$?
1
?\?
"
??TARGET=_blank>?<IMG?SRC=\?
"
?$?
2
?$?
1
?\?
"
??border=0?alt=按此在新窗口瀏覽圖片?onload=\?
"
?javascript:?
if
??(?
this
?.width?
>
?screen.width?
-
?
333
?)?
this
?.width?
=
?screen.width?
-
?
333
?\?
"
?></A>?
"
?);
????????re??
=
???
"
?\\[UPLOAD=(.[^\\[]*)\\](.[^\\[]*)\\[\\/UPLOAD\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<br><IMG?SRC=\?
""
??+?ImagePath?+?
?????????????????????????????????????????
"
?$1.gif\?
"
??border?
=
?
0
?
>
???
<
?a?href?
=
?\?
"
?$2\?
"
?
>
?點擊瀏覽該文件?
</
?a?
>
?
"
?);?
?????????
//
?轉(zhuǎn)換DIR?
????????re??
=
???
"
?\\[DIR=*([0-9]*),*([0-9]*)\\](.[^\\[]*)\\[\\/DIR]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<object?classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000?codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0?width=$1?height=$2><param?name=src?value=$3><embed?src=$3?pluginspage=http://www.macromedia.com/shockwave/download/?width=$1?height=$2></embed></object>?
"
?);
?????????
//
?轉(zhuǎn)換QT?
????????re??
=
???
"
?\\[QT=*([0-9]*),*([0-9]*)\\](.[^\\[]*)\\[\\/QT]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<embed?src=$3?width=$1?height=$2?autoplay=true?loop=false?controller=true?playeveryframe=false?cache=false?scale=TOFIT?bgcolor=#000000?kioskmode=false?targetcache=false?pluginspage=http://www.apple.com/quicktime/>;?
"
?);
?????????
//
?轉(zhuǎn)換MP?
????????re??
=
???
"
?\\[MP=*([0-9]*),*([0-9]*)\\](.[^\\[]*)\\[\\/MP]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<object?align=middle?classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95?class=OBJECT?id=MediaPlayer?width=$1?height=$2?><param?name=ShowStatusBar?value=-1><param?name=Filename?value=$3><embed?type=application/x-oleobject?codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701?flename=mp?src=$3??width=$1?height=$2></embed></object>?
"
?);
?????????
//
?轉(zhuǎn)換RM?
????????re??
=
???
"
?\\[RM=*([0-9]*),*([0-9]*)\\](.[^\\[]*)\\[\\/RM]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<OBJECT?classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA?class=OBJECT?id=RAOCX?width=$1?height=$2><PARAM?NAME=SRC?VALUE=$3><PARAM?NAME=CONSOLE?VALUE=Clip1><PARAM?NAME=CONTROLS?VALUE=imagewindow><PARAM?NAME=AUTOSTART?VALUE=true></OBJECT><br><OBJECT?classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA?height=32?id=video2?width=$1><PARAM?NAME=SRC?VALUE=$3><PARAM?NAME=AUTOSTART?VALUE=-1><PARAM?NAME=CONTROLS?VALUE=controlpanel><PARAM?NAME=CONSOLE?VALUE=Clip1></OBJECT>?
"
?);
?????????
//
?轉(zhuǎn)換FLASH?
????????re??
=
???
"
?(\\[FLASH\\])(.[^\\[]*)(\\[\\/FLASH\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<a?href=\?
"
?$?
2
?\?
"
??TARGET=_blank><IMG?SRC=\?
""
??+?ImagePath?+??
"
?swf.gif\?
"
??border=0?alt=點擊開新窗口欣賞該FLASH動畫!?height=16?width=16>[全屏欣賞]</a><br><OBJECT?codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0?classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000?width=500?height=400><PARAM?NAME=movie?VALUE=\?
"
?$?
2
?\?
"
?><PARAM?NAME=quality?VALUE=high><embed?src=\?
"
?$?
2
?\?
"
??quality=high?pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'?type='application/x-shockwave-flash'?width=500?height=400>$2</embed></OBJECT>?
"
?);
????????re??
=
???
"
?(\\[FLASH=*([0-9]*),*([0-9]*)\\])(.[^\\[]*)(\\[\\/FLASH\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<a?href=\?
"
?$?
4
?\?
"
??TARGET=_blank><IMG?SRC=\?
""
??+?ImagePath?+??
"
?swf.gif?\?
"
??border=0?alt=點擊開新窗口欣賞該FLASH動畫!?height=16?width=16>[全屏欣賞]</a>?<br><OBJECT?codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0?classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000?width=$2?height=$3><PARAM?NAME=movie?VALUE=\?
"
?$?
4
?\?
"
?><PARAM?NAME=quality?VALUE=high><embed?src=\?
"
?$?
4
?\?
"
??quality=high?pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'?type='application/x-shockwave-flash'?width=$2?height=$3>$4</embed></OBJECT>?
"
?);
?????????
//
?轉(zhuǎn)換URL?
????????re??
=
???
"
?(\\[URL\\])(.[^\\[]*)(\\[\\/URL\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<A?HREF=\?
"
?$?
2
?\?
"
??TARGET=_blank>$2</A>?
"
?);
????????re??
=
???
"
?(\\[URL=(.[^\\[]*)\\])(.[^\\[]*)(\\[\\/URL\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<A?HREF=\?
"
?$?
2
?\?
"
??TARGET=_blank>$3</A>?
"
?);
?????????
//
?轉(zhuǎn)換EMAIL?
????????re??
=
???
"
?(\\[EMAIL\\])(\\S+\\@.[^\\[]*)(\\[\\/EMAIL\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<img?align=absmiddle?src=\?
""
??+?
????????????????????????????????????????ImagePath??
+
?
?????????????????????????????????????????
"
?email1.gif\?
"
?
><
?A?HREF?
=
?\?
"
?mailto:$2\?
"
?
>
?$?
2
?
</
?A?
>
?
"
?);?
????????re??
=
???
"
?(\\[EMAIL=(\\S+\\@.[^\\[]*)\\])(.[^\\[]*)(\\[\\/EMAIL\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<img?align=absmiddle?src=\?
""
??+?
????????????????????????????????????????ImagePath??
+
?
?????????????????????????????????????????
"
?email1.gif\?
"
?
><
?A?HREF?
=
?\?
"
?mailto:$2\?
"
??TARGET?
=
?_blank?
>
?$?
3
?
</
?A?
>
?
"
?);?
?
?????????
//
?自動識別網(wǎng)址?
????????re??
=
?
?????????????????
"
?^((http|https|ftp|rtsp|mms):(\\/\\/|\\\\)[A-Za-z0-9\\./=\\?%\\-&_~`@':+!]+)?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<img?align=absmiddle?src=pic/url.gif?border=0><a?target=_blank?href=$1>$1</a>?
"
?);
????????re??
=
?
?????????????????
"
?((http|https|ftp|rtsp|mms):(\\/\\/|\\\\)[A-Za-z0-9\\./=\\?%\\-&_~`@':+!]+)$?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<img?align=absmiddle?src=pic/url.gif?border=0><a?target=_blank?href=$1>$1</a>?
"
?);
????????re??
=
???
"
?([^>=\?
"
?])((http?
|
?https?
|
?ftp?
|
?rtsp?
|
?mms):(\\?
/
?\\?
/|
?\\\\)[A?
-
?Za?
-
?z0?
-
?
9
?\\.?
/=
?\\?
?%
?\\?
-&
?_?
~
?`@?
'
?:+!]+)";?
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?$1<img?align=absmiddle?src=pic/url.gif?border=0><a?target=_blank?href=$2>$2</a>?
"
?);
?
?????????
//
?自動識別www等開頭的網(wǎng)址?
????????re??
=
???
"
?([^(http://|http:\\\\)])((www|cn)[.](\\w)+[.]{1,}(net|com|cn|org|cc)(((\\/[\\~]*|\\[\\~]*)(\\w)+)|[.](\\w)+)*(((([?](\\w)+){1}[=]*))*((\\w)+){1}([\\&](\\w)+[\\=](\\w)+)*)*)?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<img?align=absmiddle?src=pic/url.gif?border=0><a?target=_blank?href=http://$2>$2</a>?
"
?);
?
?????????
//
?自動識別Email地址,如打開本功能在瀏覽內(nèi)容很多的帖子會引起服務(wù)器停頓?
????????re??
=
???
"
?([^(=)])((\\w)+[@]{1}((\\w)+[.]){1,3}(\\w)+)?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<img?align=absmiddle?src=pic/url.gif?border=0><a?target=_blank?href=\?
"
?mailto:$?
2
?\?
"
?>$2</a>?
"
?);
?????????
//
?轉(zhuǎn)換EM?
????????re??
=
???
"
?\\[em(.[^\\[]*)\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<img?src=\?
""
??+?emotImagePath?+?
?????????????????????????????????????????
"
?em$1.gif\?
"
??border?
=
?
0
??align?
=
?middle?
>
?
"
?);?
?????????
//
?轉(zhuǎn)換HTML?
????????re??
=
???
"
?\\[HTML\\](.[^\\[]*)\\[\\/HTML\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<?table?width='100%'?border='0'?cellspacing='0'?cellpadding='6'?class=tableborder1>?<td><b>以下內(nèi)容為程序代碼:</b><br>$1</td><?/table>?
"
?);
?????????
//
?轉(zhuǎn)換CODE?
????????re??
=
???
"
?\\[code\\](.[^\\[]*)\\[\\/code\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<?table?width='100%'?border='0'?cellspacing='0'?cellpadding='6'?class=tableborder1>?<td><b>以下內(nèi)容為程序代碼:</b><br>$1</td><?/table>?
"
?);
?????????
//
?轉(zhuǎn)換COLOR?
????????re??
=
???
"
?\\[color=(.[^\\[]*)\\](.[^\\[]*)\\[\\/color\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<font?color=$1>$2</font>?
"
?);
?????????
//
?轉(zhuǎn)換FACE?
????????re??
=
???
"
?\\[face=(.[^\\[]*)\\](.[^\\[]*)\\[\\/face\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<font?face=$1>$2</font>?
"
?);
?????????
//
?轉(zhuǎn)換ALIGN?
????????re??
=
???
"
?\\[align=(center|left|right)\\](.*)\\[\\/align\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<div?align=$1>$2</div>?
"
?);
?????????
//
?轉(zhuǎn)換QUOTE?
????????re??
=
???
"
?\\[QUOTE\\](.*)\\[\\/QUOTE\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<table?style=\?
"
?width:?
80
?
%
?\?
"
??cellpadding=5?cellspacing=1?class=tableborder1><TR><TD?class=tableborder1>$1</td></tr></table><br>?
"
?);
?????????
//
?轉(zhuǎn)換FLY?
????????re??
=
???
"
?\\[fly\\](.*)\\[\\/fly\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<marquee?width=90%?behavior=alternate?scrollamount=3>$1</marquee>?
"
?);
?????????
//
?轉(zhuǎn)換MOVE?
????????re??
=
???
"
?\\[move\\](.*)\\[\\/move\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<MARQUEE?scrollamount=3>$1</marquee>?
"
?);
?????????
//
?轉(zhuǎn)換GLOW?
????????re??
=
?
?????????????????
"
?\\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\\](.[^\\[]*)\\[\\/GLOW]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<table?width=$1?style=\?
"
?filter:glow(color?
=
?$?
2
?,?strength?
=
?$?
3
?)\?
"
?>$4</table>?
"
?);
?????????
//
?轉(zhuǎn)換SHADOW?
????????re??
=
?
?????????????????
"
?\\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\\](.[^\\[]*)\\[\\/SHADOW]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(
?????????????????
"
?<table?width=$1?style=\?
"
?filter:shadow(color?
=
?$?
2
?,?strength?
=
?$?
3
?)\?
"
?>$4</table>?
"
?);
?
????????re??
=
???
"
?\\[i\\](.[^\\[]*)\\[\\/i\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<i>$1</i>?
"
?);
????????re??
=
???
"
?\\[u\\](.[^\\[]*)(\\[\\/u\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<u>$1</u>?
"
?);
????????re??
=
???
"
?\\[b\\](.[^\\[]*)(\\[\\/b\\])?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<b>$1</b>?
"
?);
????????re??
=
???
"
?\\[size=([1-4])\\](.[^\\[]*)\\[\\/size\\]?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(strContent);
????????strContent??
=
??matcher.replaceAll(?
"
?<font?size=$1>$2</font>?
"
?);
?????????
/**/
/*
?re?="(\\s)";
?????????????????matcher?=?pattern.matcher(strContent);??
?????????????????strContent=matcher.replaceAll("<I>$1</I>");?
*/
?
????????re??
=
???
null
?;
?????????
return
??strContent;
????}
?
/**?*/
/**
?
?*??過濾javascript代碼.
?*??
@param
??v轉(zhuǎn)換前的代碼.
?*??
@return
??v轉(zhuǎn)換后的內(nèi)容.
??
*/
?
?
?????
public
???
static
??String?FilterJS(String?v)?
{
?????????
if
??(?
!
?v.equals(?
"
?null?
"
?)??
&&
??v??
!=
???
null
?)?
{
????????????String?t,?re;
????????????re??
=
???
"
?(javascript)?
"
?;
????????????t??
=
??re.replace(v,??
"
?javascript?
"
?);
????????????re??
=
???
"
?(jscript:)?
"
?;
????????????t??
=
??re.replace(t,??
"
?jscript:?
"
?);
????????????re??
=
???
"
?(js:)?
"
?;
????????????t??
=
??re.replace(t,??
"
?js:?
"
?);
????????????re??
=
???
"
?(value)?
"
?;
????????????t??
=
??re.replace(t,??
"
?value?
"
?);
????????????re??
=
???
"
?(about:)?
"
?;
????????????t??
=
??re.replace(t,??
"
?about:?
"
?);
????????????re??
=
???
"
?(file:)?
"
?;
????????????t??
=
??re.replace(t,??
"
?file:?
"
?);
????????????re??
=
???
"
?(document.cookie)?
"
?;
????????????t??
=
??re.replace(t,??
"
?documents.cookie?
"
?);
????????????re??
=
???
"
?(vbscript:)?
"
?;
????????????t??
=
??re.replace(t,??
"
?vbscript:?
"
?);
????????????re??
=
???
"
?(vbs:)?
"
?;
????????????t??
=
??re.replace(t,??
"
?vbs:?
"
?);
????????????re??
=
???
"
?(on(mouse|exit|error|click|key))?
"
?;
????????????t??
=
??re.replace(t,??
"
?on$2?
"
?);
????????????re??
=
???
"
?(&#)?
"
?;
????????????t??
=
??re.replace(t,??
"
?&#?
"
?);
????????????re??
=
???
null
?;
????????}
?????????
return
??v;
????}
?
/**?*/
/**
?
?*??替換一些特殊符號為html語法標記.
?*??
@param
??fString轉(zhuǎn)換前的代碼.
?*??
@return
??fString轉(zhuǎn)換后的內(nèi)容.
??
*/
??
?
? ?
public
???
static
??String?dvHTMLEncode(String?fString)?
{
?????????
if
??(?
!
?fString.equals(?
"
?null?
"
?)??
&&
??fString??
!=
???
null
?)?
{
????????????fString??
=
??replace(fString,??
"
?>?
"
?,??
"
?>?
"
?);
????????????fString??
=
??replace(fString,??
"
?<?
"
?,??
"
?<?
"
?);
????????????fString??
=
??replace(fString,??
"
?&?
"
?,??
"
?&?
"
?);
????????????fString??
=
??replace(fString,??
"
???
"
?,??
"
???
"
?);
????????????fString??
=
??replace(fString,??
"
?\?
""
?,??
"""
?);
????????????fString??
=
??replace(fString,??
"
?\'?
"
?,??
"
?'?
"
?);
????????????fString??
=
??replace(fString,??
"
?\r?
"
?,??
""
?);
????????????fString??
=
??replace(fString,??
"
?\n?
"
?,??
"
?<BR>??
"
?);
????????????fString??
=
??replace(fString,??
"
?\\?
"
?,??
"
?\?
"
?);
????????}
?????????
return
??fString;
????}
?
/**?*/
/**
?
?*??html語法標記轉(zhuǎn)換符號本身.
?*??
@param
??fString轉(zhuǎn)換前的代碼.
?*??
@return
??fString轉(zhuǎn)換后的內(nèi)容.
??
*/
???
?
???
public
???
static
??String?dvHTMLCode(String?fString)?
{
?????????
if
??(?
!
?fString.equals(?
"
?null?
"
?)??
&&
??fString??
!=
???
null
?)?
{
????????????fString??
=
??replace(fString,??
"
?>?
"
?,??
"
?>?
"
?);
????????????fString??
=
??replace(fString,??
"
?<?
"
?,??
"
?<?
"
?);
????????????fString??
=
??replace(fString,??
"
?&?
"
?,??
"
?&?
"
?);
????????????fString??
=
??replace(fString,??
"
???
"
?,??
"
???
"
?);
????????????fString??
=
??replace(fString,??
"""
?,??
"
?\?
""
?);
????????????fString??
=
??replace(fString,??
"
?'?
"
?,??
"
?\'?
"
?);
????????????fString??
=
??replace(fString,??
"
?\?
"
?,??
"
?\\?
"
?);
????????????fString??
=
??replace(fString,??
"
?<BR>?
"
?,??
"
?\n?
"
?);
????????}
?????????
return
??fString;
????}
?
?????
public
???
static
??String?nohtml(String?str)?
{
????????String?re;
????????Pattern?pattern??
=
???
null
?;
????????Matcher?matcher??
=
???
null
?;
????????re??
=
???
"
?(\\<.[^\\<]*\\>)?
"
?;
????????pattern??
=
??Pattern.compile(re);
????????matcher??
=
??pattern.matcher(str);
????????str??
=
??matcher.replaceAll(?
"
???
"
?);
????????re??
=
???
"
?(\\<\\/[^\\<]*\\>)?
"
?;
????????str??
=
??re.replace(str,??
"
???
"
?);
????????re??
=
???
null
?;
?????????
return
??str;
????}
?
/**?*/
/**
?
?*??分割函數(shù).
?*??
@param
??source原字符串,div將要被分割的字符串.
?*??
@return
??returnStr分割后的字符串.
??
*/
???
?
????
public
???
static
??String[]?split(String?source,?String?div)?
{
?????????
int
??arynum??
=
???
0
?,?intIdx??
=
???
0
?,?intIdex??
=
???
0
?,?div_length??
=
??div.length();
?????????
if
??(source.compareTo(?
""
?)??
!=
???
0
?)?
{
?????????????
if
??(source.indexOf(div)??
!=
???
-
?
1
?)?
{
????????????????intIdx??
=
??source.indexOf(div);
?????????????????
for
??(?
int
??intCount??
=
???
1
?;?;?intCount?
++
?)?
{
?????????????????????
if
??(source.indexOf(div,?intIdx??
+
??div_length)??
!=
???
-
?
1
?)?
{
????????????????????????intIdx??
=
??source.indexOf(div,?intIdx??
+
??div_length);
????????????????????????arynum??
=
??intCount;
????????????????????}
??
else
??
{
????????????????????????arynum??
+=
???
2
?;
?????????????????????????
break
?;
????????????????????}
????????????????}
????????????}
??
else
??
{
????????????????arynum??
=
???
1
?;
????????????}
????????}
??
else
??
{
????????????arynum??
=
???
0
?;
?
????????}
????????intIdx??
=
???
0
?;
????????intIdex??
=
???
0
?;
????????String[]?returnStr??
=
???
new
??String[arynum];
?
?
if
??(source.compareTo(?
""
?)??
!=
???
0
?)?
{
?????????????
if
??(source.indexOf(div)??
!=
???
-
?
1
?)?
{
????????????????intIdx??
=
??(?
int
?)?source.indexOf(div);
????????????????returnStr[?
0
?]??
=
??(String)?source.substring(?
0
?,?intIdx);
?????????????????
for
??(?
int
??intCount??
=
???
1
?;?;?intCount?
++
?)?
{
?????????????????????
if
??(source.indexOf(div,?intIdx??
+
??div_length)??
!=
???
-
?
1
?)?
{
????????????????????????intIdex??
=
??(?
int
?)?source.indexOf(div,?intIdx??
+
??div_length);
????????????????????????returnStr[intCount]??
=
??(String)?source.substring(intIdx??
+
?
????????????????????????????????div_length,
????????????????????????????????intIdex);
????????????????????????intIdx??
=
??(?
int
?)?source.indexOf(div,?intIdx??
+
??div_length);
????????????????????}
??
else
??
{
????????????????????????returnStr[intCount]??
=
??(String)?source.substring(intIdx??
+
?
????????????????????????????????div_length,
????????????????????????????????source.length());
?????????????????????????
break
?;
????????????????????}
????????????????}
????????????}
??
else
??
{
????????????????returnStr[?
0
?]??
=
??(String)?source.substring(?
0
?,?source.length());
?????????????????
return
??returnStr;
????????????}
????????}
??
else
??
{
?????????????
return
??returnStr;
????????}
?????????
return
??returnStr;
????}
?
/**?*/
/**
?
?*??替換函數(shù).
?*??
@param
??str替換前的字符串,substr被替換的字符,restr替換的字符.
?*??
@return
??替換后并且經(jīng)過除空處理的字符串.
??
*/
???
?????
public
???
static
??String?replace(String?str,?String?substr,?String?restr)?
{
????????String[]?tmp??
=
??split(str,?substr);
????????String?returnstr??
=
???
null
?;
?????????
if
??(tmp.length??
!=
???
0
?)?
{
????????????returnstr??
=
??tmp[?
0
?];
?????????????
for
??(?
int
??i??
=
???
0
?;?i??
<
??tmp.length??
-
???
1
?;?i?
++
?)?
{
????????????????returnstr??
=
??dealNull(returnstr)??
+
??restr??
+
??tmp[i??
+
???
1
?];
????????????}
????????}
?????????
return
??dealNull(returnstr);
????}
?
/**?*/
/**
?
?*??除空處理函數(shù).
?*??
@param
??str原字符串.
?*??
@return
??處理后的字符串.
??
*/
???
?????
public
???
static
??String?dealNull(String?str)?
{
????????String?returnstr??
=
???
null
?;
?????????
if
??(str??
==
???
null
?)?
{
????????????returnstr??
=
???
""
?;
????????}
??
else
??
{
????????????returnstr??
=
??str;
????????}
?????????
return
??returnstr;
????}
?
?????
public
???
static
??String?tostring(Character?i)?
{
????????Character?c??
=
??i;
?????????
return
??c.toString();
????}
?
}
posted on 2006-12-22 16:22
tambc
閱讀(220)
評論(0)
編輯
收藏
所屬分類:
Java
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
HttpClient和HtmlParser配合實現(xiàn)自動登陸系統(tǒng)抽取頁面信息
Acegi+hibernate 動態(tài)實現(xiàn)基于角色的權(quán)限管理
服務(wù)器是怎么要求客戶端強行彈出身份驗證窗口的
java的ubb類
java版的escape和unescape
用java實現(xiàn)漢字的筆畫數(shù)(轉(zhuǎn)貼)
用Yale CAS Server 來實現(xiàn)單點登陸(SSO)
實現(xiàn)HTTP長連接(服務(wù)器推)
Powered by:
BlogJava
Copyright © tambc
主站蜘蛛池模板:
松桃
|
荆州市
|
阳曲县
|
舟曲县
|
湟源县
|
湖口县
|
商南县
|
濉溪县
|
自贡市
|
石柱
|
徐州市
|
亳州市
|
栾川县
|
遂宁市
|
通化市
|
宁晋县
|
河北区
|
曲水县
|
沙坪坝区
|
瑞丽市
|
铜鼓县
|
禄劝
|
湟源县
|
德兴市
|
巴彦淖尔市
|
铜梁县
|
方正县
|
白水县
|
邳州市
|
兴文县
|
林西县
|
瑞金市
|
永昌县
|
洪洞县
|
汶上县
|
天柱县
|
扶风县
|
兴义市
|
石河子市
|
介休市
|
松原市
|