aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs
diff options
context:
space:
mode:
authorSean Dague2007-07-16 15:40:11 +0000
committerSean Dague2007-07-16 15:40:11 +0000
commit2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch)
treee3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs
parent*Trunk compiles now (diff)
downloadopensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip
opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz
opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2
opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz
changed to native line ending encoding
Diffstat (limited to 'OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs')
-rw-r--r--OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs244
1 files changed, 122 insertions, 122 deletions
diff --git a/OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs b/OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs
index 7fa085d..2ed8d28 100644
--- a/OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs
+++ b/OpenSim/Framework/GenericConfig/Xml/XmlConfig.cs
@@ -1,122 +1,122 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Xml; 30using System.Xml;
31using OpenSim.Framework.Interfaces; 31using OpenSim.Framework.Interfaces;
32 32
33namespace OpenSim.GenericConfig 33namespace OpenSim.GenericConfig
34{ 34{
35 public class XmlConfig : IGenericConfig 35 public class XmlConfig : IGenericConfig
36 { 36 {
37 private XmlDocument doc; 37 private XmlDocument doc;
38 private XmlNode rootNode; 38 private XmlNode rootNode;
39 private XmlNode configNode; 39 private XmlNode configNode;
40 private string fileName; 40 private string fileName;
41 private bool createdFile = false; 41 private bool createdFile = false;
42 42
43 public XmlConfig(string filename) 43 public XmlConfig(string filename)
44 { 44 {
45 fileName = filename; 45 fileName = filename;
46 } 46 }
47 47
48 public void LoadData() 48 public void LoadData()
49 { 49 {
50 doc = new XmlDocument(); 50 doc = new XmlDocument();
51 51
52 if (File.Exists(fileName)) 52 if (File.Exists(fileName))
53 { 53 {
54 XmlTextReader reader = new XmlTextReader(fileName); 54 XmlTextReader reader = new XmlTextReader(fileName);
55 reader.WhitespaceHandling = WhitespaceHandling.None; 55 reader.WhitespaceHandling = WhitespaceHandling.None;
56 doc.Load(reader); 56 doc.Load(reader);
57 reader.Close(); 57 reader.Close();
58 } 58 }
59 else 59 else
60 { 60 {
61 createdFile = true; 61 createdFile = true;
62 rootNode = doc.CreateNode(XmlNodeType.Element, "Root", ""); 62 rootNode = doc.CreateNode(XmlNodeType.Element, "Root", "");
63 doc.AppendChild(rootNode); 63 doc.AppendChild(rootNode);
64 configNode = doc.CreateNode(XmlNodeType.Element, "Config", ""); 64 configNode = doc.CreateNode(XmlNodeType.Element, "Config", "");
65 rootNode.AppendChild(configNode); 65 rootNode.AppendChild(configNode);
66 } 66 }
67 67
68 68
69 rootNode = doc.FirstChild; 69 rootNode = doc.FirstChild;
70 if (rootNode.Name != "Root") 70 if (rootNode.Name != "Root")
71 throw new Exception("Error: Invalid .xml File. Missing <Root>"); 71 throw new Exception("Error: Invalid .xml File. Missing <Root>");
72 72
73 configNode = rootNode.FirstChild; 73 configNode = rootNode.FirstChild;
74 if (configNode.Name != "Config") 74 if (configNode.Name != "Config")
75 throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>"); 75 throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>");
76 76
77 if (createdFile) 77 if (createdFile)
78 { 78 {
79 this.Commit(); 79 this.Commit();
80 } 80 }
81 } 81 }
82 82
83 public string GetAttribute(string attributeName) 83 public string GetAttribute(string attributeName)
84 { 84 {
85 string result = ""; 85 string result = "";
86 if (configNode.Attributes[attributeName] != null) 86 if (configNode.Attributes[attributeName] != null)
87 { 87 {
88 result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value; 88 result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value;
89 } 89 }
90 return result; 90 return result;
91 } 91 }
92 92
93 public bool SetAttribute(string attributeName, string attributeValue) 93 public bool SetAttribute(string attributeName, string attributeValue)
94 { 94 {
95 if (configNode.Attributes[attributeName] != null) 95 if (configNode.Attributes[attributeName] != null)
96 { 96 {
97 ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value = attributeValue; 97 ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value = attributeValue;
98 } 98 }
99 else 99 else
100 { 100 {
101 XmlAttribute attri; 101 XmlAttribute attri;
102 attri = doc.CreateAttribute(attributeName); 102 attri = doc.CreateAttribute(attributeName);
103 attri.Value = attributeValue; 103 attri.Value = attributeValue;
104 configNode.Attributes.Append(attri); 104 configNode.Attributes.Append(attri);
105 } 105 }
106 return true; 106 return true;
107 } 107 }
108 108
109 public void Commit() 109 public void Commit()
110 { 110 {
111 doc.Save(fileName); 111 doc.Save(fileName);
112 } 112 }
113 113
114 public void Close() 114 public void Close()
115 { 115 {
116 configNode = null; 116 configNode = null;
117 rootNode = null; 117 rootNode = null;
118 doc = null; 118 doc = null;
119 } 119 }
120 120
121 } 121 }
122} 122}