ASP通用模板类(2)

2008-02-23 05:32:26来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


End Sub

Public Sub ClearStorage
ccStrStorage = ""
End Sub

Public Sub ClearCode
ccStrCode = ""
End Sub

Public Sub SaveFront
ccStrStorage = ccStrCode & ccStrStorage
End Sub

Public Sub SaveLast
ccStrStorage = ccStrStorage & ccStrCode
End Sub

Public Sub SaveCode
Call SaveToFile(1)
End Sub

Public Sub SaveStorage
Call SaveToFile(2)
End Sub

Public Sub SetVar(ccStrTag_in,ccStrValue_in)
ccStrCode = RePlace(ccStrCode,ccStrTag_in,ccStrValue_in)
End Sub

Private Sub SaveToFile(ccIntCode_in)
Dim ccStrSaveCode
If ccIntCode_in = 1 Then
ccStrSaveCode = ccStrCode
Else
ccStrSaveCode = ccStrStorage
End If
If ccIntObject = 1 Then
Set ccObjStream = Server.CreateObject("ADODB.Stream")
With ccObjStream
.Type = 2
.Mode = 3
.Open
.Charset = ccStrFormat
.Position = ccObjStream.Size
.WriteText ccStrSaveCode
.SaveToFile ccStrPath & ccStrSaveDirection & "\" & ccStrSaveFile,2
.Close
End With
Set ccObjStream = Nothing
Else
Set ccObjFSO = CreateObject("Scripting.FileSystemObject")
If ccObjFSO.FileExists(ccStrPath & ccStrSaveDirection & "\" & ccStrSaveFile) = True Then
ccObjFSO.DeleteFile(ccStrPath & ccStrSaveDirection & "\" & ccStrSaveFile)
End If
Set ccObjText = ccObjFSO.OpenTextFile(ccStrPath & ccStrSaveDirection & "\" & ccStrSaveFile,2,True,ccIntFormat)
ccObjText.Write ccStrSaveCode
Set ccObjText = Nothing
Set ccObjFSO = Nothing
End If
ccStrSaveCode = ""
End Sub

Public Sub Load
ccStrCode = ""
If ccBlnPrivateCache = True Then
If ccFncIsEmpty(ccStrCacheCode) = False Then
ccStrCode = ccStrCacheCode
Exit Sub
End If
End If
If ccBlnPublicCache = True Then
If ccFncIsEmpty(Application(ccStrCookieName&ccStrName)) = False Then
ccStrCode = Application(ccStrCookieName&ccStrName)
Exit Sub
End If
End If
If ccIntObject = 1 Then
Set ccObjStream = Server.CreateObject("ADODB.Stream")
With ccObjStream
.Type = 2
.Mode = 3
.Open
.Charset = ccStrFormat
.Position = ccObjStream.Size
.LoadFromFile ccStrPath & ccStrDirection & "\" & ccStrFile
ccStrCode = .ReadText
.Close
End With
Set ccObjStream = Nothing
Else
Set ccObjFSO = CreateObject("Scripting.FileSystemObject")
If ccObjFSO.FileExists(ccStrPath & ccStrDirection & "\" & ccStrFile) = True Then
Set ccObjText = ccObjFSO.OpenTextFile(ccStrPath & ccStrDirection & "\" & ccStrFile,1,False,ccIntFormat)
ccStrCode = ccObjText.ReadAll
Set ccObjText = Nothing
End If
Set ccObjFSO = Nothing
End If
If ccBlnPrivateCache = True Then
ccStrCacheCode = ccStrCode
End If
If ccBlnPublicCache = True Then
Application(ccStrCookieName&ccStrName) = ccStrCode
End If
End Sub

End Class

Function ccFncIsEmpty(ByRef ccStrValue_in)
If IsNull(ccStrValue_in) Or IsEmpty(ccStrValue_in) Or ccStrValue_in = "" Then
ccFncIsEmpty = True
Else
ccFncIsEmpty = False
End If
End Function


实例


模板文件内容

<#test#>

ASP程序代码


Dim objTemplate
Set objTemplate = New ccClsTemplate
objTemplate.Name = "Test"
objTemplate.Format = "UTF-8"
'开启缓存
objTemplate.PublicCache = True
objTemplate.PrivateCache = True
'设置模板目录和文件名
objTemplate.Direction = "test"
objTemplate.File = "test.html"
'设置保存文件目录和文件名
objTemplate.SaveDirection = "test"
objTemplate.SaveFile = "test3.html"
'载入模板
Call objTemplate.Load
'进行文本替换
Call objTemplate.SetVar("<#test#>","Hello world.")
'将文本保存至Storage暂存
Call objTemplate.SaveLast
'重新载入模板,此时将从私有缓存重新装载,提高效率
Call objTemplate.Load
'替换为其他值
Call objTemplate.SetVar("<#test#>"," By Cloudream.")
'保存至Storage结尾暂存
Call objTemplate.SaveLast
'保存Code至文件
Call objTemplate.SaveCode
Response.Write objTemplate.Storage

Set objTemplate = Nothing


显示结果


Hello world. By Cloudream.

保存文件结果


By Cloudream.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:关于解决商务平台ASP程序的源代码泄漏设想与思考

下一篇:Javascript利用xmlhttp获得服务器时钟的方法