From 3376b82501000692d6dac24b051af738cdaf2737 Mon Sep 17 00:00:00 2001 From: MW Date: Thu, 24 May 2007 12:16:50 +0000 Subject: Some more code refactoring, plus a restructuring of the directories so that the Grid servers can be a separate solution to the region server. --- .../OpenSim.GenericConfig/Xml/XmlConfig.cs | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Common-Source/OpenSim.GenericConfig/Xml/XmlConfig.cs (limited to 'Common-Source/OpenSim.GenericConfig/Xml/XmlConfig.cs') diff --git a/Common-Source/OpenSim.GenericConfig/Xml/XmlConfig.cs b/Common-Source/OpenSim.GenericConfig/Xml/XmlConfig.cs new file mode 100644 index 0000000..62e3cbf --- /dev/null +++ b/Common-Source/OpenSim.GenericConfig/Xml/XmlConfig.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using OpenSim.Framework.Interfaces; + +namespace OpenSim.GenericConfig +{ + public class XmlConfig : IGenericConfig + { + private XmlDocument doc; + private XmlNode rootNode; + private XmlNode configNode; + private string fileName; + private bool createdFile = false; + + public XmlConfig(string filename) + { + fileName = filename; + } + + public void LoadData() + { + doc = new XmlDocument(); + try + { + if (System.IO.File.Exists(fileName)) + { + XmlTextReader reader = new XmlTextReader(fileName); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + } + else + { + createdFile = true; + rootNode = doc.CreateNode(XmlNodeType.Element, "Root", ""); + doc.AppendChild(rootNode); + configNode = doc.CreateNode(XmlNodeType.Element, "Config", ""); + rootNode.AppendChild(configNode); + } + + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return; + } + try + { + rootNode = doc.FirstChild; + if (rootNode.Name != "Root") + throw new Exception("Error: Invalid .xml File. Missing "); + + configNode = rootNode.FirstChild; + if (configNode.Name != "Config") + throw new Exception("Error: Invalid .xml File. first child should be "); + + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + if (createdFile) + { + this.Commit(); + } + } + + public string GetAttribute(string attributeName) + { + string result = ""; + if (configNode.Attributes[attributeName] != null) + { + result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value; + } + return result; + } + + public bool SetAttribute(string attributeName, string attributeValue) + { + if (configNode.Attributes[attributeName] != null) + { + ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value = attributeValue; + } + else + { + XmlAttribute attri; + attri = doc.CreateAttribute(attributeName); + attri.Value = attributeValue; + configNode.Attributes.Append(attri); + } + return true; + } + + public void Commit() + { + doc.Save(fileName); + } + + public void Close() + { + configNode = null; + rootNode = null; + doc = null; + } + + } +} -- cgit v1.1