关于ASP模板类代码参考

Class Template

关于ASP模板类代码参考

Private m_FileName, m_Root, m_Unknowns, m_LastError, m_HaltOnErr

Private m_ValueList, m_BlockList

Private m_RegExp

Private Sub Class_Initialize

Set m_ValueList = CreateObject("ionary")

Set m_BlockList = CreateObject("ionary")

set m_RegExp = New RegExp

m_reCase = True

m_al = True

m_FileName = ""

m_Root = "."

m_Unknowns = "remove"

m_LastError = ""

m_HaltOnErr = true

End Sub

Private Sub Class_Terminate

Set m_RegExp = Nothing

Set m_BlockMatches = Nothing

Set m_ValueMatches = nothing

End Sub

Public Property Get ClassName()

ClassName = "Template"

End Property

Public Property Get Version()

Version = "1.0"

End Property

Private Function LoadFile(ByVal chartype)

Dim Filename, fso, hndFile

Filename = m_Root

If Right(Filename, 1)<>"/" And Right(Filename, 1)<>"" Then Filename = Filename & "/"

Filename = Server.MapPath(Filename & m_FileName)

Set StreamObject = teObject("am")

= 1

= 3

tion = 0

FromFile Filename

tion = 0

= 2

Set = chartype

LoadFile = text()

If LoadFile = "" Then ShowError("0x11

Could Not Load The File " & m_FileName & "!")

End Function

Private Sub ShowError(ByVal msg)

m_LastError = msg

e "Error ID : " & msg & ""

If m_HaltOnErr Then

End Sub

Public Sub set_root(ByVal Value)

m_Root = Value

End Sub

Public Function get_root()

get_root = m_Root

End Function

Public Property Let Root(ByVal Value)

set_root(Value)

End Property

Public Property Get Root()

Root = m_Root

End Property

Public Sub set_file(ByVal handle,ByVal filename,ByVal chartype)

m_FileName = filename

m_ Handle, LoadFile(chartype)

End Sub

Public Function get_file()

get_file = m_FileName

End Function

Public Sub set_unknowns(ByVal unknowns)

m_Unknowns = unknowns

End Sub

Public Function get_unknowns()

get_unknowns = m_Unknowns

End Function

Public Property Let Unknowns(ByVal unknown)

m_Unknowns = unknown

End Property

Public Property Get Unknowns()

Unknowns = m_Unknowns

End Property

Public Sub set_block(ByVal Parent, ByVal BlockTag, ByVal Name)

Dim Matches

m_ern = "([sS.]*)"

If Not m_ts(Parent) Then ShowError("0x12

Undefined Block Tag " & Parent & "!")

set Matches = m_ute(m_(Parent))

For Each Match In Matches

m_ BlockTag, atches(0)

m_(Parent) = Replace(m_(Parent), e, "{" & Name & "}")

Next

set Matches = nothing

End Sub

Public Sub set_var(ByVal Name, ByVal Value, ByVal AppEnd)

Dim Val

If IsNull(Value) Then Val = "" Else Val = Value

If m_ts(Name) Then

If AppEnd Then m_(Name) = m_(Name) & Val _

Else m_(Name) = Val

Else

m_ Name, Value

End If

End Sub

Public Sub unset_var(ByVal Name)

If m_ts(Name) Then m_ve(Name)

End Sub

Private Function InstanceValue(ByVal BlockTag)

Dim keys, i

InstanceValue = m_(BlockTag)

keys = m_

For i=0 To m_t-1

InstanceValue = Replace(InstanceValue, "{" & keys(i) & "}", m_(keys(i)))

Next

End Function

Public Sub parse(ByVal Name, ByVal BlockTag, ByVal AppEnd)

If Not m_ts(BlockTag) Then ShowError("0x12

Undefined Block Tag " & Parent & "!")

If m_ts(Name) Then

If AppEnd Then m_(Name) = m_(Name) & InstanceValue(BlockTag) _

Else m_(Name) = InstanceValue(BlockTag)

Else

m_ Name, InstanceValue(BlockTag)

End If

End Sub

Private Function finish(ByVal content)

Select Case m_Unknowns

Case "keep" finish = content

Case "remove"

m_ern = "{[^ trn}]+}"

finish = m_ace(content, "")

Case "comment"

m_ern = "{([^ trn}]+)}"

finish = m_ace(content, "")

Case Else finish = content

End Select

End Function

Public Sub output(ByVal Name)

If Not m_ts(Name) Then ShowError("0x13

Could Not Find Tag " & Name & "!")

e(finish(m_(Name)))

End Sub

End Class