aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs237
1 files changed, 147 insertions, 90 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
index 5494549..d214eba 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs
@@ -45,6 +45,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
45 { 45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 #region old xml format
48 public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset) 49 public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset)
49 { 50 {
50 XmlDocument doc = new XmlDocument(); 51 XmlDocument doc = new XmlDocument();
@@ -98,11 +99,128 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
98 file.Close(); 99 file.Close();
99 } 100 }
100 101
101 public static string SaveGroupToXml2(SceneObjectGroup grp) 102 #endregion
103
104 #region XML2 serialization
105
106 // Called by archives (save oar)
107 public static string SaveGroupToXml2(SceneObjectGroup grp, Dictionary<string, object> options)
108 {
109 //return SceneObjectSerializer.ToXml2Format(grp);
110 using (MemoryStream mem = new MemoryStream())
111 {
112 using (XmlTextWriter writer = new XmlTextWriter(mem, System.Text.Encoding.UTF8))
113 {
114 SceneObjectSerializer.SOGToXml2(writer, grp, options);
115 writer.Flush();
116
117 using (StreamReader reader = new StreamReader(mem))
118 {
119 mem.Seek(0, SeekOrigin.Begin);
120 return reader.ReadToEnd();
121 }
122 }
123 }
124 }
125
126 // Called by scene serializer (save xml2)
127 public static void SavePrimsToXml2(Scene scene, string fileName)
128 {
129 EntityBase[] entityList = scene.GetEntities();
130 SavePrimListToXml2(entityList, fileName);
131 }
132
133 // Called by scene serializer (save xml2)
134 public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName)
135 {
136 m_log.InfoFormat(
137 "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}",
138 primName, scene.RegionInfo.RegionName, fileName);
139
140 EntityBase[] entityList = scene.GetEntities();
141 List<EntityBase> primList = new List<EntityBase>();
142
143 foreach (EntityBase ent in entityList)
144 {
145 if (ent is SceneObjectGroup)
146 {
147 if (ent.Name == primName)
148 {
149 primList.Add(ent);
150 }
151 }
152 }
153
154 SavePrimListToXml2(primList.ToArray(), fileName);
155 }
156
157 // Called by REST Application plugin
158 public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max)
102 { 159 {
103 return SceneObjectSerializer.ToXml2Format(grp); 160 EntityBase[] entityList = scene.GetEntities();
161 SavePrimListToXml2(entityList, stream, min, max);
104 } 162 }
105 163
164 // Called here only. Should be private?
165 public static void SavePrimListToXml2(EntityBase[] entityList, string fileName)
166 {
167 FileStream file = new FileStream(fileName, FileMode.Create);
168 try
169 {
170 StreamWriter stream = new StreamWriter(file);
171 try
172 {
173 SavePrimListToXml2(entityList, stream, Vector3.Zero, Vector3.Zero);
174 }
175 finally
176 {
177 stream.Close();
178 }
179 }
180 finally
181 {
182 file.Close();
183 }
184 }
185
186 // Called here only. Should be private?
187 public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max)
188 {
189 XmlTextWriter writer = new XmlTextWriter(stream);
190
191 int primCount = 0;
192 stream.WriteLine("<scene>\n");
193
194 foreach (EntityBase ent in entityList)
195 {
196 if (ent is SceneObjectGroup)
197 {
198 SceneObjectGroup g = (SceneObjectGroup)ent;
199 if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero))
200 {
201 Vector3 pos = g.RootPart.GetWorldPosition();
202 if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z)
203 continue;
204 if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z)
205 continue;
206 }
207
208 //stream.WriteLine(SceneObjectSerializer.ToXml2Format(g));
209 SceneObjectSerializer.SOGToXml2(writer, (SceneObjectGroup)ent, new Dictionary<string,object>());
210 stream.WriteLine();
211
212 primCount++;
213 }
214 }
215
216 stream.WriteLine("</scene>\n");
217 stream.Flush();
218 }
219
220 #endregion
221
222 #region XML2 deserialization
223
106 public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString) 224 public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
107 { 225 {
108 XmlDocument doc = new XmlDocument(); 226 XmlDocument doc = new XmlDocument();
@@ -124,14 +242,30 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
124 foreach (XmlNode aPrimNode in rootNode.ChildNodes) 242 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
125 { 243 {
126 // There is only ever one prim. This oddity should be removeable post 0.5.9 244 // There is only ever one prim. This oddity should be removeable post 0.5.9
127 return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml); 245 //return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml);
246 using (reader = new XmlTextReader(new StringReader(aPrimNode.OuterXml)))
247 {
248 SceneObjectGroup obj = new SceneObjectGroup();
249 if (SceneObjectSerializer.Xml2ToSOG(reader, obj))
250 return obj;
251
252 return null;
253 }
128 } 254 }
129 255
130 return null; 256 return null;
131 } 257 }
132 else 258 else
133 { 259 {
134 return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml); 260 //return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml);
261 using (reader = new XmlTextReader(new StringReader(rootNode.OuterXml)))
262 {
263 SceneObjectGroup obj = new SceneObjectGroup();
264 if (SceneObjectSerializer.Xml2ToSOG(reader, obj))
265 return obj;
266
267 return null;
268 }
135 } 269 }
136 } 270 }
137 271
@@ -193,96 +327,19 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
193 /// <returns>The scene object created. null if the scene object already existed</returns> 327 /// <returns>The scene object created. null if the scene object already existed</returns>
194 protected static SceneObjectGroup CreatePrimFromXml2(Scene scene, string xmlData) 328 protected static SceneObjectGroup CreatePrimFromXml2(Scene scene, string xmlData)
195 { 329 {
196 SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData); 330 //SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData);
197 331 using (XmlTextReader reader = new XmlTextReader(new StringReader(xmlData)))
198 if (scene.AddRestoredSceneObject(obj, true, false))
199 return obj;
200 else
201 return null;
202 }
203
204 public static void SavePrimsToXml2(Scene scene, string fileName)
205 {
206 EntityBase[] entityList = scene.GetEntities();
207 SavePrimListToXml2(entityList, fileName);
208 }
209
210 public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max)
211 {
212 EntityBase[] entityList = scene.GetEntities();
213 SavePrimListToXml2(entityList, stream, min, max);
214 }
215
216 public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName)
217 {
218 m_log.InfoFormat(
219 "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}",
220 primName, scene.RegionInfo.RegionName, fileName);
221
222 EntityBase[] entityList = scene.GetEntities();
223 List<EntityBase> primList = new List<EntityBase>();
224
225 foreach (EntityBase ent in entityList)
226 {
227 if (ent is SceneObjectGroup)
228 {
229 if (ent.Name == primName)
230 {
231 primList.Add(ent);
232 }
233 }
234 }
235
236 SavePrimListToXml2(primList.ToArray(), fileName);
237 }
238
239 public static void SavePrimListToXml2(EntityBase[] entityList, string fileName)
240 {
241 FileStream file = new FileStream(fileName, FileMode.Create);
242 try
243 { 332 {
244 StreamWriter stream = new StreamWriter(file); 333 SceneObjectGroup obj = new SceneObjectGroup();
245 try 334 SceneObjectSerializer.Xml2ToSOG(reader, obj);
246 {
247 SavePrimListToXml2(entityList, stream, Vector3.Zero, Vector3.Zero);
248 }
249 finally
250 {
251 stream.Close();
252 }
253 }
254 finally
255 {
256 file.Close();
257 }
258 }
259 335
260 public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) 336 if (scene.AddRestoredSceneObject(obj, true, false))
261 { 337 return obj;
262 int primCount = 0; 338 else
263 stream.WriteLine("<scene>\n"); 339 return null;
264
265 foreach (EntityBase ent in entityList)
266 {
267 if (ent is SceneObjectGroup)
268 {
269 SceneObjectGroup g = (SceneObjectGroup)ent;
270 if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero))
271 {
272 Vector3 pos = g.RootPart.GetWorldPosition();
273 if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z)
274 continue;
275 if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z)
276 continue;
277 }
278
279 stream.WriteLine(SceneObjectSerializer.ToXml2Format(g));
280 primCount++;
281 }
282 } 340 }
283 stream.WriteLine("</scene>\n");
284 stream.Flush();
285 } 341 }
286 342
343 #endregion
287 } 344 }
288} 345}