ASP template Class Code

Source: Internet
Author: User

Class Template





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 ("Scripting.Dictionary")


Set m_blocklist = CreateObject ("Scripting.Dictionary")


Set m_regexp = New RegExp


m_regexp.ignorecase = True


M_regexp.global = 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 = Server.CreateObject ("ADODB.stream")


Streamobject.type = 1


Streamobject.mode = 3


Streamobject.open


streamobject.position = 0


streamobject.loadfromfile Filename


streamobject.position = 0


Streamobject.type = 2


Streamobject.charset = Chartype


loadfile = Streamobject.readtext ()


If loadfile = "" Then showerror ("0x11<br>could not Load the File" & M_filename & "!")


End Function





Private Sub showerror (ByVal msg)


m_lasterror = msg


Response.Write "<span style=" "font-size:12px;color:red" ">error ID:" & msg & "</span>"


If m_haltonerr Then response.end


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_blocklist.add 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_regexp.pattern = "<!--s+begin" & Blocktag & S+--> ([SS.] *) <!--s+end "& Blocktag &" S+--> "


If not m_blocklist.exists (parent) Then ShowError ("0x12<br>undefined block Tag" & Parent & "!")


Set matches = M_regexp.execute (M_blocklist.item (Parent))


for each Match in matches


M_blocklist.add Blocktag, match.submatches (0)


M_blocklist.item (parent) = Replace (M_blocklist.item (parent), Match.value, "{" & 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_valuelist.exists (Name) Then


If AppEnd Then m_valuelist.item (name) = M_valuelist.item (name) & Val _


Else m_valuelist.item (Name) = Val


Else


m_valuelist.add Name, Value


End If


End Sub





Public Sub Unset_var (ByVal Name)


If m_valuelist.exists (name) Then m_valuelist.remove (name)


End Sub





Private Function instancevalue (ByVal blocktag)


Dim keys, I


Instancevalue = M_blocklist.item (Blocktag)


keys = M_valuelist.keys


for i=0 to M_valuelist.count-1


Instancevalue = Replace (Instancevalue, "{" & Keys (i) & "}", M_valuelist.item (keys (i))


Next


End Function





Public Sub Parse (ByVal Name, ByVal Blocktag, ByVal AppEnd)


If not m_blocklist.exists (blocktag) Then ShowError ("0x12<br>undefined block Tag" & Parent & "!")


If m_valuelist.exists (Name) Then


If AppEnd Then m_valuelist.item (name) = M_valuelist.item (name) & Instancevalue (Blocktag) _


Else m_valuelist.item (Name) = Instancevalue (Blocktag)


Else


M_valuelist.add Name, Instancevalue (Blocktag)


End If


End Sub





Private Function Finish (ByVal content)


Select Case M_unknowns


case "Keep" finish = content


case "Remove"


M_regexp.pattern = "{[^ trn}]+}"


finish = m_regexp.replace (content, "")


case "comment"


M_regexp.pattern = "{([^ trn}]+)}"


finish = m_regexp.replace (content, "<!--Template Variable $ Undefined-->")


case Else finish = content


End Select


End Function





public Sub output (ByVal Name)


If not m_valuelist.exists (name) Then showerror ("0x13<br>could Don't find Tag" & Name & "!")


Response.Write (M_valuelist.item (Name))


End Sub


End Class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.