<%
' ********************************************************************
' Copyright (C) 2001 Microsoft Corporation. All rights reserved.
'
'	IMPORTANT.  Please read the legal.txt file, located in the
'	"<CMS Install Directory>\Server\httpexec\WBC\Internals"
'	directory, governing the use of this internal file."
' ********************************************************************

' ********************************************************************
' File:		/NR/System/WBC/Internals/ServerControls/CNCTreeDom_FSO.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Responsible for Displaying Content Management Server hierarchy tree
'
' Implement INCTreeDom Interface:
'	- Function GetRootObject()
'	- Function GetObjectByID( strID )
'	- Function GetObjectID( pObject )
'	- Function GetObjectDisplayName( pObject )
'	- Function ShouldRecurseContainer( pChild )
'	- Function GetChildrenContainerCol( pObject )
'	- Function GetChildrenLeafCol( pObject )
' Public Interface of CNCTreeDom_FSO
'	- Property RootObjectDisplayName [read/write]
'
' Public Interface of CNCTreeDom_NRChannels
'	- Sub SetRootObject( pObject )
' ********************************************************************

Const FSO_BASEOBJ_IDENTIFIER = "FSOBase"
Const FSO_ROOTOBJECT_DISPLAYNAME = "File System"
Const FSO_OBJTYPE_UNKNOWN = 0
Const FSO_OBJTYPE_FSOBASE = 1
Const FSO_OBJTYPE_DRIVE = 2
Const FSO_OBJTYPE_FOLDER = 3
Const FSO_OBJTYPE_FILE = 4


Class CNCTreeDom_FSO
	' -- Class Internal variables
	Private m_pFSO
	Private m_pRootObject

	' -- Allows caller to override the Root level display name
	Public RootObjectDisplayName

	' ---- [Private] Class standard Class_Initialize()
	Private Sub Class_Initialize()
		Set m_pFSO = Server.CreateObject("Scripting.FileSystemObject")

		Set m_pRootObject = m_pFSO
		RootObjectDisplayName = FSO_ROOTOBJECT_DISPLAYNAME
	End Sub

	' -------------------------------------------------------------------------
	'
	'	[Public] This sub allows the client of this class to supply a
	'			virtual root object to override the default tree root.
	'
	' -------------------------------------------------------------------------
	Public Sub SetRootObject( pObject )
		Set m_pRootObject = pObject
	End Sub

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::GetRootObject()
	'	This function is called by the CNCTreeControl to query for the root
	'	object of the tree hierarchy.
	'
	'	@return - the root object of the Tree
	'
	' -------------------------------------------------------------------------
	Public Function GetRootObject()
		Set GetRootObject = m_pRootObject
	End Function

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::GetObjectByID( strID )
	'	This function is called by the CNCTreeControl to search for an object
	'	given an ID.
	'
	'	@strID [in] - the ID that identifies the object in the hierarchy
	'
	'	@return - the object in the hierarchy identified by the ID
	'
	' -------------------------------------------------------------------------
	Public Function GetObjectByID( strID )
		' initialize it to Nothing in case strID does not identify a valid object
		Set GetObjectByID = Nothing

		If (strID = FSO_BASEOBJ_IDENTIFIER) Then
			Set GetObjectByID = m_pFSO
		Else
			If (InStr( strID, "\" ) <= 0) Then
				' it should be a Drive
				If m_pFSO.DriveExists(strID) Then
					Set GetObjectByID = m_pFSO.GetDrive( strID )
				End If
			Else
				' it should be a Folder
				If m_pFSO.FolderExists(strID) Then
					Set GetObjectByID = m_pFSO.GetFolder( strID )
				End If
			End If
		End If
	End Function

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::GetObjectID( pObject )
	'	This function is called by the CNCTreeControl to ask for the ID
	'	of an object
	'
	'	@pObject [in] - the object whose ID is to be returned
	'
	'	@return - the ID of the object
	'
	' -------------------------------------------------------------------------
	Public Function GetObjectID( pObject )
		If (pObject Is m_pFSO) Then
			GetObjectID = FSO_BASEOBJ_IDENTIFIER
		Else
			GetObjectID = pObject.Path
		End If
	End Function

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::GetObjectDisplayName( pObject )
	'	This function is called by the CNCTreeControl to ask for the display
	'	name of an object
	'
	'	@pObject [in] - the object whose display name is to be returned
	'
	'	@return - the display name of the object
	'
	' -------------------------------------------------------------------------
	Public Function GetObjectDisplayName( pObject )
		If (m_pFSO Is pObject) Then
			GetObjectDisplayName = RootObjectDisplayName
		Else
			If (GetFSOObjType(pObject) = FSO_OBJTYPE_DRIVE) Then
				GetObjectDisplayName = "[" & pObject.DriveLetter & ":]"
			Else
				GetObjectDisplayName = pObject.Name
			End If
		End If
	End Function

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::ShouldRecurseIntoContainer( pParent, pChild )
	'	This function is called by the CNCTreeControl to give this TreeDOM
	'	class a chance to filter out some Containers when rendering the tree.
	'
	'	@pParent [in] - the parent of pChild
	'
	'	@pChild [in] - the child container object which is in question as to
	'				whether the CNCTreeControl should recurse into.
	'
	'	@return - a Boolean which indicates to the CNCTreeControl whether it
	'				should recurse into the child container
	'
	' -------------------------------------------------------------------------
	Public Function ShouldRecurseIntoContainer( pParent, pChild )
		If (GetFSOObjType(pChild) = FSO_OBJTYPE_DRIVE) Then
			If (pChild.DriveType = 2) Then
				ShouldRecurseIntoContainer = True
				Exit Function
			Else
				ShouldRecurseIntoContainer = False
				Exit Function
			End If
		End If

		ShouldRecurseIntoContainer = True
	End Function

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::GetChildrenContainerCol( pObject )
	'	This function is called by the CNCTreeControl to retrieve the container
	'	children collection of a certain object.
	'
	'	@pObject [in] - the container object whose container children
	'				collection is to be returned.
	'
	'	@return - the childern container collection of pObject
	'
	' -------------------------------------------------------------------------
	Public Function GetChildrenContainerCol( pObject )
		If (pObject Is m_pFSO) Then
			Set GetChildrenContainerCol = pObject.Drives
		Else
			' avoid the RootFolder
			If (GetFSOObjType(pObject) = FSO_OBJTYPE_DRIVE) Then
				Set GetChildrenContainerCol = pObject.RootFolder.SubFolders
			Else
				Set GetChildrenContainerCol = pObject.SubFolders
			End If
		End If
	End Function

	' -------------------------------------------------------------------------
	'
	'	INCTreeDom::GetChildrenLeafCol( pObject )
	'	This function is called by the CNCTreeControl to retrieve the leaf
	'	children collection of a certain object.
	'
	'	@pObject [in] - the container object whose container children
	'				collection is to be returned.
	'
	'	@return - the childern container collection of pObject
	'
	' -------------------------------------------------------------------------
	Public Function GetChildrenLeafCol( pObject )
		If (pObject Is m_pFSO) Then
			Set GetChildrenLeafCol = Nothing
		Else
			' avoid the RootFolder
			If (GetFSOObjType(pObject) = FSO_OBJTYPE_DRIVE) Then
				Set GetChildrenLeafCol = pObject.RootFolder.Files
			Else
				Set GetChildrenLeafCol = pObject.Files
			End If
		End If
	End Function

	' ---- [Private] Return the whether the object is FSO, a Drive, a Folder, or a File
	Private Function GetFSOObjType( pObject )
		GetFSOObjType = FSO_OBJTYPE_UNKNOWN
		If (m_pFSO Is pObject) Then
			GetFSOObjType = FSO_OBJTYPE_FSOBASE
		Else
			If (InStr( pObject.Path, "\" ) > 0) Then
				GetFSOObjType = FSO_OBJTYPE_FOLDER
			Else
				GetFSOObjType = FSO_OBJTYPE_DRIVE
			End If

		End If
	End Function

End Class

%>