您的位置:首页 > 编程语言 > ASP

asp标签引擎 :tagEngine.Class.Asp

2006-12-02 16:42 232 查看
标签引擎,只是按设定的规则提取标签,没有解析标签功能.....
最大作用:灵活,可以自己定义标签规则,然后就可以定义自己的标签库.....
已经用在一个项目上了,不过是PHP版的....
具体应用以后有时间在写.......


asp,php,asp.net讨论群:3920122

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

Private regEx'正则对象

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

'方法:resetPattern()
'参数:
'返回:无返回值
'作用:重设标签规则
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

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

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

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

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

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

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

'方法:showError(errdes)
'参数:errdes,错误描述
'返回:无
'作用:显示错误
Public Sub showError(errdes)
    Dim errinfo,cssstyle
    cssstyle="style="&Chr(34)
    cssstyle=cssstyle&"font:bold 12px 150%,'Arial';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

'******************标准功能结束****************
'以下是自定义扩展功能

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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息