<% class classFileSystemTree dim m_xmlTree dim m_path dim m_maxDepth dim m_maxLength dim m_transform dim m_prePath dim m_fileExclusions dim m_fileTypes dim m_includeDetails dim m_includeLocalPath public sub class_initialize() configure "config.xml" end sub public sub configure(configurationPath) dim configuration set configuration = getXml(configurationPath) url = cStr( getConfiguration(configuration, "path", "/") ) maxDepth = cInt( getConfiguration(configuration, "maxPath", -1) ) maxLength = cInt( getConfiguration(configuration, "maxLength", -1) ) transform = cStr( getConfiguration(configuration, "transform", "xhtml.xsl") ) prePath = cStr( getConfiguration(configuration, "prePath", "") ) fileExclusions = cStr( getConfiguration(configuration, "fileExclusions", "file_exclusions.xml") ) fileTypes = cStr( getConfiguration(configuration, "fileTypes", "file_types.xml") ) includeDetails = cBool( getConfiguration(configuration, "includeDetails", false) ) includeLocalPath = cBool( getConfiguration(configuration, "includeLocalPath", false) ) end sub public function getTree set getTree = m_xmlTree end function public property let includeDetails(parIncludeDetails) m_includeDetails = parIncludeDetails end property public property let includeLocalPath(parIncludeLocalPath) m_includeLocalPath = parIncludeLocalPath end property public property let fileTypes(parFileTypes) m_fileTypes = server.mapPath(parFileTypes) end property public property let fileExclusions(parFileExclusions) m_fileExclusions = server.mapPath(parFileExclusions) end property public property let url(parUrl) m_path = server.mapPath(parUrl) end property public property let prePath(parPrePath) m_prePath = parPrePath if right(m_prepath, 1) = "/" then m_prepath = left( m_prepath, len(m_prepath) - 1 ) end if end property public property let transform(parUrl) m_transform = server.mapPath(parUrl) end property public property let maxDepth(parMaxDepth) m_maxDepth = parMaxDepth end property public property let maxLength(parMaxLength) m_maxLength = parMaxLength end property public sub create set m_xmlTree = getFileSystemTree(m_path) end sub public function getXhtml dim xslXhtml dim transformation set xslXhtml = getXml(m_transform) transformation = m_xmlTree.transformNode(xslXhtml) getXhtml = transformation end function ' private: private function getFileSystemTree(url) dim xmlSystem dim xhtmlTree dim fileSystem dim xmlTree dim depth dim topFolder dim xmlFileExclusions dim xmlFileTypes set xmlFileExclusions = getXml(m_fileExclusions) set xmlFileTypes = getXml(m_fileTypes) set xmlSystem = server.createObject("Microsoft.XMLDOM") xmlSystem.async = false set fileSystem = server.createObject("Scripting.FileSystemObject") set topFolder = fileSystem.getFolder(m_path) set xmlSystem.documentElement = getSystemTree(topFolder, fileSystem, _ xmlSystem, depth, xmlFileExclusions, xmlFileTypes) set getFileSystemTree = xmlSystem end function private function getSystemTree(thisFolder, fileSystem, xmlSystem, depth, xmlFileExclusions, xmlFileTypes) dim xmlFolder dim xmlSubFolder dim xmlSubFile dim subFolders dim subFolder dim subSystem dim thisLength dim relativePath set subFolders = thisFolder.subFolders set xmlFolder = xmlSystem.createElement("folder") xmlFolder.setAttribute "name", thisFolder.name if m_includeDetails then xmlFolder.setAttribute "dateCreated", _ formatDateTime(thisFolder.dateCreated, vbShortDate) xmlFolder.setAttribute "dateLastModified", _ formatDateTime(thisFolder.dateLastModified, vbShortDate) xmlFolder.setAttribute "dateLastAccessed", _ formatDateTime(thisFolder.dateLastAccessed, vbShortDate) end if if m_includeLocalPath then xmlFolder.setAttribute "localPath", thisFolder.path end if relativePath = getRelativePath(thisFolder.path) xmlFolder.setAttribute "path", m_prePath & relativePath thisLength = 0 depth = depth + 1 if cLng(depth) <= cLng(m_maxDepth) or cLng(m_maxDepth) = -1 then thisLength = thisLength + 1 if thisLength <= m_maxLength or m_maxLength = -1 then for each subFolder in subFolders if not folderExcluded(subFolder, xmlFileExclusions) then xmlFolder.appendChild getSystemTree(subFolder, fileSystem, xmlSystem, _ depth, xmlFileExclusions, xmlFileTypes) end if next appendSubFiles thisFolder, xmlFolder, thisLength, xmlSystem, _ relativePath, xmlFileExclusions, xmlFileTypes end if end if set getSystemTree = xmlFolder end function private sub appendSubFiles(thisFolder, xmlFolder, thisLength, xmlSystem, relativePath, xmlFileExclusions, xmlFileTypes) dim subFiles dim subFile dim xmlSubFile dim extension dim fileSize set subFiles = thisFolder.files for each subFile in subFiles extension = getExtension(subFile) if not fileExcluded(subFile, extension, xmlFileExclusions) then thisLength = thisLength + 1 if thisLength <= m_maxLength or m_maxLength = -1 then set xmlSubFile = xmlSystem.createElement("file") xmlSubFile.setAttribute "name", subFile.name xmlSubFile.setAttribute "path", m_prePath & _ relativePath & "/" & subFile.name fileSize = subFile.size \ 1024 if cLng(fileSize) = 0 then fileSize = 1 xmlSubFile.setAttribute "sizeKB", cStr(fileSize) if m_includeDetails then xmlSubFile.setAttribute "dateCreated", _ formatDateTime(subFile.dateCreated, vbShortDate) xmlSubFile.setAttribute "dateLastAccessed", _ formatDateTime(subFile.dateLastAccessed, vbShortDate) end if if m_includeLocalPath then xmlSubFile.setAttribute "localPath", subFile.path end if xmlSubFile.setAttribute "dateLastModified", _ formatDateTime(subFile.dateLastModified, vbShortDate) xmlSubFile.setAttribute "type", getFileType(xmlFileTypes, extension) xmlFolder.appendChild xmlSubFile end if end if next end sub private function getFileType(xmlFileTypes, extension) dim fileTypeNode dim xPath dim fileType fileType = "" xPath = "file/extension[@value = '" & extension & "']" set fileTypeNode = xmlFileTypes.documentElement.selectSingleNode(xPath) if fileTypeNode is nothing then fileType = "default" else fileType = fileTypeNode.parentNode.getAttribute("type") end if getFileType = cStr(fileType) end function private function folderExcluded(thisFolder, xmlFileExclusions) dim xPath dim exclusion dim isExcluded xPath = "folder[@name = '" & thisFolder.name & "']" set exclusion = xmlFileExclusions.documentElement.selectSingleNode(xPath) isExcluded = not(exclusion is nothing) folderExcluded = cBool(isExcluded) end function private function fileExcluded(thisFile, extension, xmlFileExclusions) dim xPath dim exclusion dim isExcluded dim fileName fileName = thisFile.name xPath = "file[@extension = '" & extension & "']" set exclusion = xmlFileExclusions.documentElement.selectSingleNode(xPath) isExcluded = not(exclusion is nothing) if not isExcluded then xPath = "file[@name = '" & fileName & "']" set exclusion = xmlFileExclusions.documentElement.selectSingleNode(xPath) isExcluded = not(exclusion is nothing) end if fileExcluded = cBool(isExcluded) end function private function getExtension(fileName) dim extension dim dotPosition dim letter dim i extension = "" dotPosition = 0 for i = 1 to len(fileName) - 1 letter = mid(fileName, i, 1) if letter = "." then dotPosition = i end if next if dotPosition > 0 then extension = mid(fileName, dotPosition + 1) end if getExtension = cStr(extension) end function private function getRelativePath(absolutePath) dim relativePath dim absoluteLength absoluteLength = len(m_path) + 1 relativePath = mid(absolutePath, absoluteLength) relativePath = replace(relativePath, "\", "/") getRelativePath = cStr(relativePath) end function private function getXhtmlTree(xmlSystem) dim xhtmlTree set xhtmlTree = m_xmlTree set getXhtmlTree = xhtmlTree end function private function getConfiguration(configuration, nodeName, defaultValue) dim configurationValue dim thisNode dim text set thisNode = configuration.documentElement.selectSingleNode(nodeName) if thisNode is nothing then configurationValue = defaultValue else text = thisNode.text if trim(text) <> "" then configurationValue = text else configurationValue = defaultValue end if end if getConfiguration = configurationValue end function end class %>