aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
diff options
context:
space:
mode:
authorTeravus Ovares (Dan Olivares)2009-09-08 04:43:17 -0400
committerTeravus Ovares (Dan Olivares)2009-09-08 04:43:17 -0400
commitf0e2fd426b074ceb992124cf5eb2ebe8db5c04dd (patch)
treebea9234644b05887b4c7cc063d457b91610ed9dc /OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
parent* Fixes a 'take object from mega region' and rez it in a regular region.. ... (diff)
parentllRot2Euler() now returns angles -PI < angle < PI (diff)
downloadopensim-SC_OLD-f0e2fd426b074ceb992124cf5eb2ebe8db5c04dd.zip
opensim-SC_OLD-f0e2fd426b074ceb992124cf5eb2ebe8db5c04dd.tar.gz
opensim-SC_OLD-f0e2fd426b074ceb992124cf5eb2ebe8db5c04dd.tar.bz2
opensim-SC_OLD-f0e2fd426b074ceb992124cf5eb2ebe8db5c04dd.tar.xz
Merge branch 'master' of ssh://MyConnection/var/git/opensim
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs212
1 files changed, 212 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
new file mode 100644
index 0000000..2eeb637
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
@@ -0,0 +1,212 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Services.Interfaces;
33
34namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
35{
36 /// <summary>
37 /// Utility methods for inventory archiving
38 /// </summary>
39 public static class InventoryArchiveUtils
40 {
41 public static readonly string PATH_DELIMITER = "/";
42
43 /// <summary>
44 /// Find a folder given a PATH_DELIMITER delimited path starting from a user's root folder
45 /// </summary>
46 ///
47 /// This method does not handle paths that contain multiple delimitors
48 ///
49 /// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
50 /// XPath like expression
51 ///
52 /// FIXME: Delimitors which occur in names themselves are not currently escapable.
53 ///
54 /// <param name="inventoryService">
55 /// Inventory service to query
56 /// </param>
57 /// <param name="userId">
58 /// User id to search
59 /// </param>
60 /// <param name="path">
61 /// The path to the required folder.
62 /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
63 /// </param>
64 /// <returns>null if the folder is not found</returns>
65 public static InventoryFolderBase FindFolderByPath(
66 IInventoryService inventoryService, UUID userId, string path)
67 {
68 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
69
70 if (null == rootFolder)
71 return null;
72
73 return FindFolderByPath(inventoryService, rootFolder, path);
74 }
75
76 /// <summary>
77 /// Find a folder given a PATH_DELIMITER delimited path starting from this folder
78 /// </summary>
79 ///
80 /// This method does not handle paths that contain multiple delimitors
81 ///
82 /// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
83 /// XPath like expression
84 ///
85 /// FIXME: Delimitors which occur in names themselves are not currently escapable.
86 ///
87 /// <param name="inventoryService">
88 /// Inventory service to query
89 /// </param>
90 /// <param name="startFolder">
91 /// The folder from which the path starts
92 /// </param>
93 /// <param name="path">
94 /// The path to the required folder.
95 /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
96 /// </param>
97 /// <returns>null if the folder is not found</returns>
98 public static InventoryFolderBase FindFolderByPath(
99 IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
100 {
101 if (path == string.Empty)
102 return startFolder;
103
104 path = path.Trim();
105
106 if (path == PATH_DELIMITER)
107 return startFolder;
108
109 InventoryFolderBase foundFolder = null;
110
111 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
112 InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);
113
114 foreach (InventoryFolderBase folder in contents.Folders)
115 {
116 if (folder.Name == components[0])
117 {
118 if (components.Length > 1)
119 return FindFolderByPath(inventoryService, foundFolder, components[1]);
120 else
121 return folder;
122 }
123 }
124
125 // We didn't find a folder with the right name
126 return null;
127 }
128
129 /// <summary>
130 /// Find an item given a PATH_DELIMITOR delimited path starting from the user's root folder.
131 ///
132 /// This method does not handle paths that contain multiple delimitors
133 ///
134 /// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
135 /// XPath like expression
136 ///
137 /// FIXME: Delimitors which occur in names themselves are not currently escapable.
138 /// </summary>
139 ///
140 /// <param name="inventoryService">
141 /// Inventory service to query
142 /// </param>
143 /// <param name="userId">
144 /// The user to search
145 /// </param>
146 /// <param name="path">
147 /// The path to the required item.
148 /// </param>
149 /// <returns>null if the item is not found</returns>
150 public static InventoryItemBase FindItemByPath(
151 IInventoryService inventoryService, UUID userId, string path)
152 {
153 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
154
155 if (null == rootFolder)
156 return null;
157
158 return FindItemByPath(inventoryService, rootFolder, path);
159 }
160
161 /// <summary>
162 /// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
163 ///
164 /// This method does not handle paths that contain multiple delimitors
165 ///
166 /// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
167 /// XPath like expression
168 ///
169 /// FIXME: Delimitors which occur in names themselves are not currently escapable.
170 /// </summary>
171 ///
172 /// <param name="inventoryService">
173 /// Inventory service to query
174 /// </param>
175 /// <param name="startFolder">
176 /// The folder from which the path starts
177 /// </param>
178 /// <param name="path">
179 /// <param name="path">
180 /// The path to the required item.
181 /// </param>
182 /// <returns>null if the item is not found</returns>
183 public static InventoryItemBase FindItemByPath(
184 IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
185 {
186 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
187
188 if (components.Length == 1)
189 {
190 List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID);
191 foreach (InventoryItemBase item in items)
192 {
193 if (item.Name == components[0])
194 return item;
195 }
196 }
197 else
198 {
199 InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);
200
201 foreach (InventoryFolderBase folder in contents.Folders)
202 {
203 if (folder.Name == components[0])
204 return FindItemByPath(inventoryService, folder, components[1]);
205 }
206 }
207
208 // We didn't find an item or intermediate folder with the given name
209 return null;
210 }
211 }
212} \ No newline at end of file