<%
'''''''''''''''''''''''''''''''''''''''' ''''''''''''
'Set template = new templatestate
'Template.opentemplate('template.html ') read the template content
'Template. value = "value" content
'Template. replacekeyword keyword URL replacement keyword
'Template. replacetext ("/$ content/$") replaces the template content
'Template. savetemplateas ("1.html") to generate a file
'''''''''''''''''''''''''''''''''''''''' ''''''''''''
Class templatestate
Public filepath
Public startposition
Public endposition
Public Value
Public templatecontent
Public FSO
Public File
Public RegEx
Private sub class_initialize
Filepath = ""
Startposition = ""
Endposition = ""
Value = ""
Templatecontent = ""
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set RegEx = new Regexp
With RegEx
. Multiline = true
. Ignorecase = true
. Global = true
End
End sub
Private sub class_terminate
Filepath = ""
Startposition = ""
Endposition = ""
Value = ""
Set RegEx = nothing
Set file = nothing
Set FSO = nothing
End sub
Private function filterstr (STR)
Filterstr = Str
If STR = "" Or isnull (filterstr) then
Filterstr = ""
Else
Filterstr = Replace (filterstr ,"/","//")
Filterstr = Replace (filterstr ,"(","/(")
Filterstr = Replace (filterstr ,")","/)")
Filterstr = Replace (filterstr ,"*","/*")
Filterstr = Replace (filterstr ,"? ","/? ")
Filterstr = Replace (filterstr ,"{","/{")
Filterstr = Replace (filterstr ,"}","/}")
Filterstr = Replace (filterstr ,".","/.")
Filterstr = Replace (filterstr, "+", "/+ ")
Filterstr = Replace (filterstr ,"[","/[")
Filterstr = Replace (filterstr, "]", "/]")
End if
End Function
Public Function opentemplate (sfilepath)
Set file = FSO. opentextfile (server. mappath (sfilepath), 1)
Templatecontent = file. readall ()
File. Close
Filepath = sfilepath
End Function
Public Function replacetemplate ()
If startposition = "" Or endposition = "" Or templatecontent = "" then
Exit Function
End if
Dim strpattern
Strpattern = filterstr (startposition) & "[/S] *? "& Filterstr (endposition)
RegEx. pattern = strpattern
Templatecontent = RegEx. Replace (templatecontent, startposition & vbcrlf & Value & vbcrlf & endposition)
End Function
Public Function replacetext (patrn)
RegEx. pattern = patrn
Templatecontent = RegEx. Replace (templatecontent, value)
End Function
Public Function replacekeyword (keyword, URL)
RegEx. pattern = keyword
Value = RegEx. Replace (value, "<a href =" & URL & ">" & keyword & "</a> ")
End Function
Public Function savetemplate ()
Set file = FSO. opentextfile (server. mappath (filepath), 2)
File. Write templatecontent
File. Close
End Function
Public Function savetemplateas (sfilepath)
Set file = FSO. opentextfile (server. mappath (sfilepath), 2, true)
File. Write templatecontent
File. Close
End Function
End Class
%>