asp下生成目录树结构的类

关于生成目录树结构的类

本程序有两文件test.asp 和tree.asp 还有一些图标文件

1。test.asp 调用类生成树 代码如下

<%@ language=vbscript %> 
 
 
<% 

'======================================== 
' building a tree programatically 
'======================================== 
' this approach would be best suited for building 
' dynamic trees using for..next loops and such. 

set mytree2 = new tree 
mytree2.top = 10 
mytree2.left = 10 
mytree2.expandimage = "plus.gif" 
mytree2.collapseimage = "minus.gif" 
mytree2.leafimage = "webpage.gif" 

' notice the indentation used to reprensent the hierarchy 
set node1 = mytree2.createchild("script") 
set subnode1 = node1.createchild("server") 
set secsubnode1 = subnode1.createchild("html") 
secsubnode1.createchild "asp" 
secsubnode1.createchild "php" 
secsubnode1.createchild "jsp" 

set subnode2 = node1.createchild("os") 
subnode2.createchild "winnt" 
subnode2.createchild "win2000" 

set node2 = mytree2.createchild("desktop") 
node2.createchild "area code lookup" 
node2.createchild "arin based whois search" 
node2.createchild "world time zone map" 

mytree2.draw() 

set mytree2 = nothing 

%> 

 
 

2。tree.asp 类的定义 代码如下

<% 
'****************************************************** 
' author: jacob gilley 
' email: avis7@airmail.net 
' my terms: you can use this control in anyway you see fit 
' cause i have no means to enforce any guidelines 
' or bs that most developers think they can get 
' you to agree to by spouting out words like 
' "intellectual property" and "the code gods". 
' - viva la microsoft! 
'****************************************************** 

dim gbltreenodecount:gbltreenodecount = 1 

class treenode 

public value 
public expandimage 
public collapseimage 
public leafimage 
public expanded 
private mszname 
private mcolchildren 
private mbchildreninitialized 

public property get childcount() 
childcount = mcolchildren.count 
end property 

private sub class_initialize() 
mszname = "node" & cstr(gbltreenodecount) 
gbltreenodecount = gbltreenodecount + 1 

mbchildreninitialized = false 
expanded = false 
end sub 

private sub class_terminate() 
if mbchildreninitialized and isobject(mcolchildren) then 
mcolchildren.removeall() 
set mcolchildren = nothing 
end if 
end sub 

private sub initchildlist() 
set mcolchildren = server.createobject("scripting.dictionary") 
mbchildreninitialized = true 
end sub 

private sub loadstate() 
if request(mszname) = "1" or request("togglenode") = mszname then 
expanded = true 
end if 
end sub 

public function createchild(szvalue) 

if not mbchildreninitialized then initchildlist() 

set createchild = new treenode 
createchild.value = szvalue 
createchild.expandimage = expandimage 
createchild.collapseimage = collapseimage 
createchild.leafimage = leafimage 

mcolchildren.add mcolchildren.count + 1, createchild 

end function 

public sub draw() 

loadstate() 

response.write "" & vbcrlf 
response.write "" & vbcrlf 
response.write "" & vbcrlf 

if expanded then 
response.write "" & vbcrlf 

if mbchildreninitialized then 
response.write "" & vbcrlf 
response.write "" & vbcrlf 
response.write "" & vbcrlf 
end if 
end if 

response.write "
" & vbcrlf if expanded then response.write "" & vbcrlf elseif not mbchildreninitialized then response.write "" & vbcrlf else response.write "" & vbcrlf end if response.write " " & value & "
" & vbcrlf for each childnode in mcolchildren.items childnode.draw() next response.write "
" & vbcrlf end sub end class class tree public top public left public expandimage public collapseimage public leafimage private mszposition private mcolchildren public property let absolute(bdata) if bdata then mszposition = "absolute" else mszposition = "relative" end property public property get absolute() absolute = cbool(mszposition = "absolute") end property private sub class_initialize() set mcolchildren = server.createobject("scripting.dictionary") mntop = 0 mnleft = 0 mszposition = "absolute" end sub private sub class_terminate() mcolchildren.removeall() set mcolchildren = nothing end sub public function createchild(szvalue) set createchild = new treenode createchild.value = szvalue createchild.expandimage = expandimage createchild.collapseimage = collapseimage createchild.leafimage = leafimage mcolchildren.add mcolchildren.count + 1, createchild end function public sub loadtemplate(szfilename) dim objworkingnode dim colnodestack dim fsobj, tsobj dim szline dim ncurrdepth, nnextdepth set colnodestack = server.createobject("scripting.dictionary") set fsobj = createobject("scripting.filesystemobject") set tsobj = fsobj.opentextfile(szfilename, 1) ncurrdepth = 0 while not tsobj.atendofline nnextdepth = 1 szline = tsobj.readline() if ncurrdepth = 0 then set objworkingnode = createchild(trim(szline)) ncurrdepth = 1 else while mid(szline,nnextdepth,1) = vbtab or mid(szline,nnextdepth,1) = " " nnextdepth = nnextdepth + 1 wend if nnextdepth > 1 then szline = trim(mid(szline,nnextdepth)) if szline <> "" then if nnextdepth > ncurrdepth then if colnodestack.exists(ncurrdepth) then set colnodestack.item(ncurrdepth) = objworkingnode else colnodestack.add ncurrdepth, objworkingnode end if set objworkingnode = objworkingnode.createchild(szline) ncurrdepth = ncurrdepth + 1 elseif nnextdepth <= ncurrdepth then if nnextdepth > 1 then nnextdepth = nnextdepth - 1 while not colnodestack.exists(nnextdepth) and nnextdepth > 1 nnextdepth = nnextdepth - 1 wend set objworkingnode = colnodestack.item(nnextdepth) set objworkingnode = objworkingnode.createchild(szline) nnextdepth = nnextdepth + 1 else set objworkingnode = createchild(szline) end if ncurrdepth = nnextdepth end if end if end if wend tsobj.close() set tsobj = nothing set fsobj = nothing colnodestack.removeall() set colnodestack = nothing end sub public sub draw() addclientscript() response.write "
" & vbcrlf response.write "" & vbcrlf response.write "" & vbcrlf response.write "" & vbcrlf response.write "
" & vbcrlf for each childnode in mcolchildren.items childnode.draw() next response.write "
" & vbcrlf response.write "" & vbcrlf response.write "" & vbcrlf response.write "
" & vbcrlf end sub private sub addclientscript() %> function expandnode(sznodename) { if(document.layers != null) { document.treectrl.document.treectrlfrm.togglenode.value = sznodename; document.treectrl.document.treectrlfrm.submit(); } else { document.all["treectrlfrm"].togglenode.value = sznodename; document.all["treectrlfrm"].submit(); } } function collapsenode(sznodename) { if(document.layers != null) { document.treectrl.document.treectrlfrm.elements[sznodename].value = -1; document.treectrl.document.treectrlfrm.submit(); } else { document.treectrlfrm.elements[sznodename].value = -1; document.treectrlfrm.submit(); } } <% end sub end class %>
相关文章