From a62b906a7b77340c61c4d3b084c3d950cf5172ba Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 31 Jul 2008 17:32:13 +0000 Subject: * allow inventory folders to be located by path * first pass method impl --- .../Communications/Cache/InventoryFolderImpl.cs | 58 +++++++++++++++++++--- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs') diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index 0fbc427..b1fdf76 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using libsecondlife; //using System.Reflection; @@ -36,12 +37,22 @@ namespace OpenSim.Framework.Communications.Cache public class InventoryFolderImpl : InventoryFolderBase { //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public static readonly string PATH_DELIMITER = "/"; - // Fields + /// + /// Items that are contained in this folder + /// public Dictionary Items = new Dictionary(); + + /// + /// Child folders that are contained in this folder + /// public Dictionary SubFolders = new Dictionary(); - // Accessors + /// + /// The number of child folders + /// public int SubFoldersCount { get { return SubFolders.Count; } @@ -177,9 +188,7 @@ namespace OpenSim.Framework.Communications.Cache public InventoryFolderImpl FindFolder(LLUUID folderID) { if (folderID == ID) - { return this; - } lock (SubFolders) { @@ -188,14 +197,51 @@ namespace OpenSim.Framework.Communications.Cache InventoryFolderImpl returnFolder = folder.FindFolder(folderID); if (returnFolder != null) - { return returnFolder; - } } } return null; } + + /// + /// Find a folder given a PATH_DELIMITOR delimited path. + /// + /// This method does not handle paths that contain multiple delimitors + /// + /// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some + /// XPath like expression + /// + /// FIXME: Delimitors which occur in names themselves are not currently escapable. + /// + /// + /// The path to the required folder. It this is empty then this folder itself is returned. + /// If a folder for the given path is not found, then null is returned. + /// + /// + public InventoryFolderImpl FindFolderByPath(string path) + { + if (path == string.Empty) + return this; + + int delimitorIndex = path.IndexOf(PATH_DELIMITER); + string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); + + lock (SubFolders) + { + foreach (InventoryFolderImpl folder in SubFolders.Values) + { + if (folder.Name == components[0]) + if (components.Length > 1) + return folder.FindFolderByPath(components[1]); + else + return folder; + } + } + + // We didn't find a folder with the given name + return null; + } /// /// Return the list of child items in this folder -- cgit v1.1