ASP生成静态模版技术(带参数的标签)

来源:风之相随BLOG 时间:2009-03-03 12:29:00 

 

<!--模板-->
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td><tag:article_list class_id="314" PageSize="4" Len="8" showtime="0" /></td>
</tr>
</table>

  

<%
Call loadtemplate("test.htm")
'==============================
''替换模板内容
'==============================
Function loadtemplate(FileName)
Dim TempHtml
TempHtml = readfromfile(FileName)
'''处理用户标签
TempHtml = process_customtags(TempHtml)
loadtemplate = TempHtml
End Function


'==============================
'【功能】解析并替换相应的模板标签内容
'==============================
Function Parsetag(ByVal strtag)
Dim arrResult, className, arrAttributes, sTemp, i, objclass
'如果标签是空的则退出函数
If Len(strtag) = 0 Then Exit Function
arrResult = MySplit(strtag, ":")
className = MySplit(arrResult(1), " ")(0)
Parsetag = strtag
Dim nclass_id, nLen, nIsWhat, nshowtime
select Case LCase(className)
Case "article_list"
nclass_id = 0
nLen = 24
nPageSize = 10
nshowtime = 0
If Not IsBlank(GetAttribute("pagesize", strtag)) Then nPageSize = GetAttribute("pagesize", strtag)
If Not IsBlank(GetAttribute("class_id", strtag)) Then nclass_id = GetAttribute("class_id", strtag)
If Not IsBlank(GetAttribute("Len", strtag)) Then nLen = Int(GetAttribute("Len", strtag))
If Not IsBlank(GetAttribute("showtime", strtag)) Then nshowtime = Int(GetAttribute("showtime", strtag))
Parsetag = show_article_list(nclass_id, nPageSize, nLen, nshowtime)
End select
End Function


'==============================
'【功能】处理自定义标签
'==============================
Function process_customtags(ByVal sContent)
Dim objRegEx, Match, Matches
'建立正则表达式
Set objRegEx = New RegExp
'查找内容
objRegEx.Pattern = "<tag:[^<>]+?\/>"
'忽略大小写
objRegEx.IgnoreCase = True
'全局查找
objRegEx.Global = True
Set Matches = objRegEx.Execute(sContent)
'循环已发现的匹配
For Each Match in Matches
sContent = Replace(sContent, Match.Value, Parsetag(Match.Value))
Next
'消毁对象
Set Matches = Nothing
Set objRegEx = Nothing
'返回值
process_customtags = sContent
End Function


'==============================
'文件内容读取.
'==============================
Function readfromfile(ByVal File)
Dim objStream
On Error Resume Next
Set objStream = Server.createObject("ADODB.Stream")
If Err.Number = -2147221005 Then
Response.Write "<div align='center'>非常遗憾,您的主机不支持ADODB.Stream,不能使用本程序</div>"
Err.Clear
Response.End
End If
With objStream
.Type = 2
.Mode = 3
.Open
.LoadFromFile Server.MapPath(File)
If Err.Number<>0 Then
Response.Write "<div align='center'>文件<font color='#ff0000'>" & File & "</font>无法被打开,请检查是否存在!</font></div>"
Err.Clear
Response.End
End If
.Charset = "GB2312"
.Position = 2
read1file = .ReadText
.Close
End With
Set objStream = Nothing
End Function


'==============================
''显示文章内容
'==============================
Function show_article_list(class_id, nPageSize, nLen, nshowtime)
每人代码都不一样,自己写哈
End Function


'==============================
'判断是否为空
'==============================
Function IsBlank(ByRef TempVar)
IsBlank = False
select Case VarType(TempVar)
'Empty & Null
Case 0, 1
IsBlank = True
'String
Case 8
If Len(TempVar) = 0 Then
IsBlank = True
End If
'Object
Case 9
Dim tmpType
tmpType = TypeName(TempVar)
If (tmpType = "Nothing") or (tmpType = "Empty") Then
IsBlank = True
End If
'Array
Case 8192, 8204, 8209
If UBound(TempVar) = -1 Then
IsBlank = True
End If
End select
End Function
%>
标签:静态,模板,技术,标签,asp
0
投稿

猜你喜欢

  • 用蜜罐来阻止垃圾评论

    2007-11-06 12:35:00
  • ASP中的全角和半角之间的转化

    2008-06-06 13:34:00
  • ASP程序与SQL存储过程结合使用详解

    2011-03-25 10:50:00
  • 使用eval()解析JSON格式字符串应注意的问题

    2008-04-16 15:46:00
  • 《JavaScript语言精粹》译者序及样章试读

    2009-04-03 11:38:00
  • javascript让浏览器实现复读机的功能

    2008-10-10 11:49:00
  • asp无组件实现画简单图形的类

    2004-06-17 13:30:00
  • 解决Dreamweaver不支持中文文件名方法

    2008-01-09 12:52:00
  • 大家都来设计创意XP黑屏!

    2008-10-25 14:59:00
  • 做设计还是做产品

    2009-06-11 13:01:00
  • SQL Server数据迁移至云端应用技巧谈

    2011-05-05 08:01:00
  • 用Dreamweaver设计实现网页过渡转换功能

    2008-09-04 10:09:00
  • asp form 表单验证函数

    2011-04-04 11:10:00
  • 用MSXML2.ServerXMLHTTP的setTimeouts属性解决并死问题

    2010-03-02 20:21:00
  • 英文版面设计的8个禁忌

    2009-10-14 20:42:00
  • 交互设计模式(三)-Tagging(标签)

    2009-10-19 20:46:00
  • Oracle 数据显示 横表转纵表

    2009-07-26 08:57:00
  • 用户的期望以及背后真正的需求

    2009-06-19 12:39:00
  • Smush it - 一款图片压缩的Firefox插件,很好,很强大!

    2009-04-12 20:09:00
  • 常见Dreamweaver使用过程中的问题及解决办法

    2011-03-17 16:16:00
  • asp之家 网络编程 m.aspxhome.com