当前位置:主页   - 电脑 - 网站开发 - ASP
asp的标签引擎类tagEngine.Class
来源:网络   作者:    更新时间:2010-09-26
收藏此页】    【字号    】    【打印】    【关闭

修改记录:

1,增加扩展函数,2006-12-3

<%
&apos;******************************
&apos;类名:tagEngine
&apos;名称:标签引擎
&apos;日期:2006-11-29
&apos;作者:西楼冷月
&apos;网址:www.xilou.net | www.chinaCMS.org
&apos;描述:只有提取标签功能,没有解析标签功能
&apos;版权:转载请注名出处,作者
&apos;******************************
&apos;最后修改:2006-12-3
&apos;修改次数:3
&apos;修改说明:修改正则,使匹配更精确
&apos;目前版本:v1.1.3
&apos;******************************
Class tagEngine

Private regEx&apos;正则对象

&apos;定义标签规则
Private tagbegin
Private tagend
Private blockbegin_begin
Private blockbegin_end
Private blockend_begin
Private blockend_end
&apos;//初始化
Private Sub Class_Initialize()
&apos;初始化标签规则
tagbegin="{"
tagend="}"
blockbegin_begin="<Block:"
blockbegin_end =">"
blockend_begin ="</Block:"
blockend_end =">"
&apos;初始化正则对象
Set regEx=new RegExp
regEx.IgnoreCase=True&apos;不区分大小写
regEx.Global=True&apos;全局匹配
End Sub
Private Sub Class_Terminate()
&apos;释放对象
If IsObject(regEx) Then Set regEx=Nothing
End Sub

&apos;方法:resetPattern()
&apos;参数:
&apos;返回:无返回值
&apos;作用:重设标签规则
Public Sub resetPattern(tagbegin,tagend,_
blockbegin_begin,_
blockbegin_end,_
blockend_begin,_
blockend_end _
)
tagbegin=tagbegin
tagend=tagend
blockbegin_begin=blockbegin_begin
blockbegin_end =blockbegin_end
blockend_begin =blockend_begin
blockend_end =blockend_end
End Sub

&apos;方法:getBlocks(temp,blockname)
&apos;参数:temp,要匹配的内容;blockname,区块标志名称
&apos;返回:返回集合对象(Matches)
&apos;作用:获取块标签集合
Public Function getBlocks(temp,blockname)
Dim pattern
pattern="("&blockbegin_begin&"[ ]*"&blockname&"b[wW]*?"&blockbegin_end
pattern=pattern&")([wW]*?)"&blockend_begin&"[ nr]*"&blockname&"[ ]*"&blockend_end
&apos;Response.Write pattern
regEx.Pattern=pattern
Set getBlocks=regEx.Execute(temp)&apos;返回匹配集合
End Function

&apos;方法:getBlockByAtt(temp,attributename,attributevalue)
&apos;参数:temp,要匹配的内容;attributename,属性名称;attributevalue,属性值
&apos;返回:返回集合对象(Matches)
&apos;作用:根据块标签里的某个属性的值取得符合的块集合
Public Function getBlockByAtt(temp,attributename,attributevalue)
Dim pattern
pattern="("&blockbegin_begin&"[wW]*?[ nr]+"&attributename
pattern=pattern&"[ ]*=[ ]*"&Chr(34)&attributevalue&""&Chr(34)&"[ nr]*[wW]*?"
pattern=pattern&blockbegin_end
pattern=pattern&")([wW]*?)"&blockend_begin&"[wW]*?"&blockend_end
&apos;Response.Write pattern
regEx.Pattern=pattern
Set getBlockByAtt=regEx.Execute(temp)&apos;返回匹配集合
End Function

&apos;方法:getAttValue(temp,attributename)
&apos;参数:temp,要匹配的内容;attributename,属性名称
&apos;返回:返回集合对象(Matches)
&apos;作用:获取块标签内的属性值
Public Function getAttValue(temp,attributename)
Dim pattern
pattern="[ nr]+"&attributename&"[ ]*=[ ]*"&Chr(34)&"([^fnrtv"&Chr(34)&"]*?)"&Chr(34)
&apos;Response.Write pattern
regEx.Pattern=pattern
Set getAttValue=regEx.Execute(temp)
End Function

&apos;方法:parseTag(temp,tagname,tagvalue)
&apos;参数:temp,要匹配的内容;attributename,属性名称;attributevalue,属性值
&apos;返回:返回替换后的字符串
&apos;作用:替换简单标签
Public Function parseTag(temp,tagname,tagvalue)
Dim pattern
&apos;pattern=tagbegin&"[ ]*"&tagname&"[ ]*"&tagend
pattern=tagbegin&tagname&tagend
regEx.pattern=pattern
parseTag=regEx.Replace(temp,tagvalue)
End Function

&apos;方法:clearBlocks(temp)
&apos;参数:temp,要匹配的内容
&apos;返回:返回清除后的字符串
&apos;作用:清除所有块标签
Public Function clearBlocks(temp)
Dim pattern
pattern=blockbegin_begin&"[wW]*?"&blockbegin_end&"[wW]*?"
pattern=pattern&blockend_begin&"[wW]*?"&blockend_end
regEx.pattern=pattern
clearBlocks=regEx.Replace(temp,"")
End Function

&apos;方法:clearTags(temp)
&apos;参数:temp,要匹配的内容
&apos;返回:返回清除后的字符串
&apos;作用:清除所有的单标签
Public Function clearTags(temp)
Dim pattern
pattern=tagbegin&"[^fnrtv]*?"&tagend
regEx.pattern=pattern
clearTags=regEx.Replace(temp,"")
End Function

&apos;方法:showError(errdes)
&apos;参数:errdes,错误描述
&apos;返回:无
&apos;作用:显示错误
Public Sub showError(errdes)
Dim errinfo,cssstyle
cssstyle="style="&Chr(34)
cssstyle=cssstyle&"font:bold 12px 150%,&apos;Arial&apos;;border:1px solid #CC3366;"
cssstyle=cssstyle&"width:50%;color:#990066;padding:2px;"&Chr(34)
errinfo=vbcrlf&"<ul "&cssstyle&"><li>"&errdes&"</li></ul>"&vbcrlf
Response.Write errinfo
End Sub

&apos;******************标准功能结束****************
&apos;以下是自定义扩展功能

&apos;方法:EXT_getSimpleBlocks(temp,blockname)
&apos;参数:temp,要匹配的内容;blockname,区块标志名称
&apos;返回:返回集合对象(Matches)
&apos;作用:获取简单块标签集合
&apos;例子:<Block:new id="" loop=""/>
Public Function EXT_getSimpleBlocks(temp,blockname)
Dim pattern
Dim blockbegin,blockend
&apos;重新定义标签规则
blockbegin="<Block:"
blockend ="/>"
pattern=blockbegin&"[ ]*"&blockname&"b[wW]*?"&blockend
regEx.pattern=pattern
Set EXT_getSimpleBlocks=regEx.Execute(temp)
End Function

&apos;******************标准功能结束****************
&apos;以下是自定义扩展功能

&apos;方法:EXT_getSimpleBlocks(temp,blockname)
&apos;参数:temp,要匹配的内容;blockname,区块标志名称
&apos;返回:返回集合对象(Matches)
&apos;作用:获取简单块标签集合
&apos;例子:<Block:new id="" loop=""/>
Public Function EXT_getSimpleBlocks(temp,blockname)
Dim pattern
Dim blockbegin,blockend
&apos;重新定义标签规则
blockbegin="<Block:"
blockend ="/>"
pattern=blockbegin&"[ ]*"&blockname&"b[wW]*?"&blockend
regEx.pattern=pattern
Set EXT_getSimpleBlocks=regEx.Execute(temp)
End Function

&apos;方法:EXT_getTEXT(path)
&apos;参数:path,要读取的文本相对或绝对路径
&apos;返回:返回文本内容
&apos;作用: 读取文件
&apos;例子:c=EXT_getTEXT("tpl.htm")
Public Function EXT_getTEXT(path)
Dim fso,f,text
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f=Fso.OpenTextFile(path)
text=f.ReadAll
If Err Then
Err.Clear
showError "读取文件出错..."
If IsObject(fso) Then Set fso=Nothing
Exit Function
End If
If IsObject(fso) Then Set fso=Nothing
EXT_getTEXT=text
End Function

&apos;方法:EXT_getIncludeFile(temp)
&apos;参数:temp,要匹配的内容
&apos;返回:返回集合对象(Matches)
&apos;作用: 解析<!--#include file="tpl.html"-->的区块
&apos;例子:EXT_getIncludeFile(temp)(0).SubMatches(0),返回第一个匹配的文件名
Public Function EXT_getIncludeFile(temp)
Dim pattern
Dim blockbegin,blockend
&apos;重新定义标签规则
blockbegin="<!--#include"
blockend ="-->"
pattern=blockbegin&"[ ]*file[ ]*=[ ]*""([wW]*?)""[ ]*"&blockend
regEx.pattern=pattern
Set EXT_getIncludeFile=regEx.Execute(temp)
End Function

End Class
%>

其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明