diff options
author | Adam Frisby | 2007-07-11 08:02:47 +0000 |
---|---|---|
committer | Adam Frisby | 2007-07-11 08:02:47 +0000 |
commit | 5c7ffdde0b9642a42e8f5987e06eb01220ff7776 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /Common/XmlRpcCS/XmlRpcDeserializer.cs | |
parent | Who would have known that the only way of specifying utf-8 without preamble, ... (diff) | |
download | opensim-SC-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.zip opensim-SC-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.gz opensim-SC-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.bz2 opensim-SC-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.xz |
* Wiping trunk in prep for Sugilite
Diffstat (limited to 'Common/XmlRpcCS/XmlRpcDeserializer.cs')
-rw-r--r-- | Common/XmlRpcCS/XmlRpcDeserializer.cs | 222 |
1 files changed, 0 insertions, 222 deletions
diff --git a/Common/XmlRpcCS/XmlRpcDeserializer.cs b/Common/XmlRpcCS/XmlRpcDeserializer.cs deleted file mode 100644 index bffda57..0000000 --- a/Common/XmlRpcCS/XmlRpcDeserializer.cs +++ /dev/null | |||
@@ -1,222 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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 | */ | ||
28 | namespace Nwc.XmlRpc | ||
29 | { | ||
30 | using System; | ||
31 | using System.Collections; | ||
32 | using System.IO; | ||
33 | using System.Xml; | ||
34 | using System.Globalization; | ||
35 | |||
36 | /// <summary>Parser context, we maintain contexts in a stack to avoiding recursion. </summary> | ||
37 | struct Context | ||
38 | { | ||
39 | public String Name; | ||
40 | public Object Container; | ||
41 | } | ||
42 | |||
43 | /// <summary>Basic XML-RPC data deserializer.</summary> | ||
44 | /// <remarks>Uses <c>XmlTextReader</c> to parse the XML data. This level of the class | ||
45 | /// only handles the tokens common to both Requests and Responses. This class is not useful in and of itself | ||
46 | /// but is designed to be subclassed.</remarks> | ||
47 | public class XmlRpcDeserializer : XmlRpcXmlTokens | ||
48 | { | ||
49 | private static DateTimeFormatInfo _dateFormat = new DateTimeFormatInfo(); | ||
50 | |||
51 | private Object _container; | ||
52 | private Stack _containerStack; | ||
53 | |||
54 | /// <summary>Protected reference to last text.</summary> | ||
55 | protected String _text; | ||
56 | /// <summary>Protected reference to last deserialized value.</summary> | ||
57 | protected Object _value; | ||
58 | /// <summary>Protected reference to last name field.</summary> | ||
59 | protected String _name; | ||
60 | |||
61 | |||
62 | /// <summary>Basic constructor.</summary> | ||
63 | public XmlRpcDeserializer() | ||
64 | { | ||
65 | Reset(); | ||
66 | _dateFormat.FullDateTimePattern = ISO_DATETIME; | ||
67 | } | ||
68 | |||
69 | /// <summary>Static method that parses XML data into a response using the Singleton.</summary> | ||
70 | /// <param name="xmlData"><c>StreamReader</c> containing an XML-RPC response.</param> | ||
71 | /// <returns><c>Object</c> object resulting from the deserialization.</returns> | ||
72 | virtual public Object Deserialize(TextReader xmlData) | ||
73 | { | ||
74 | return null; | ||
75 | } | ||
76 | |||
77 | /// <summary>Protected method to parse a node in an XML-RPC XML stream.</summary> | ||
78 | /// <remarks>Method deals with elements common to all XML-RPC data, subclasses of | ||
79 | /// this object deal with request/response spefic elements.</remarks> | ||
80 | /// <param name="reader"><c>XmlTextReader</c> of the in progress parsing data stream.</param> | ||
81 | protected void DeserializeNode(XmlTextReader reader) | ||
82 | { | ||
83 | switch (reader.NodeType) | ||
84 | { | ||
85 | case XmlNodeType.Element: | ||
86 | if (Logger.Delegate != null) | ||
87 | Logger.WriteEntry("START " + reader.Name, LogLevel.Information); | ||
88 | switch (reader.Name) | ||
89 | { | ||
90 | case VALUE: | ||
91 | _value = null; | ||
92 | _text = null; | ||
93 | break; | ||
94 | case STRUCT: | ||
95 | PushContext(); | ||
96 | _container = new Hashtable(); | ||
97 | break; | ||
98 | case ARRAY: | ||
99 | PushContext(); | ||
100 | _container = new ArrayList(); | ||
101 | break; | ||
102 | } | ||
103 | break; | ||
104 | case XmlNodeType.EndElement: | ||
105 | if (Logger.Delegate != null) | ||
106 | Logger.WriteEntry("END " + reader.Name, LogLevel.Information); | ||
107 | switch (reader.Name) | ||
108 | { | ||
109 | case BASE64: | ||
110 | _value = Convert.FromBase64String(_text); | ||
111 | break; | ||
112 | case BOOLEAN: | ||
113 | int val = Int16.Parse(_text); | ||
114 | if (val == 0) | ||
115 | _value = false; | ||
116 | else if (val == 1) | ||
117 | _value = true; | ||
118 | break; | ||
119 | case STRING: | ||
120 | _value = _text; | ||
121 | break; | ||
122 | case DOUBLE: | ||
123 | _value = Double.Parse(_text); | ||
124 | break; | ||
125 | case INT: | ||
126 | case ALT_INT: | ||
127 | _value = Int32.Parse(_text); | ||
128 | break; | ||
129 | case DATETIME: | ||
130 | #if __MONO__ | ||
131 | _value = DateParse(_text); | ||
132 | #else | ||
133 | _value = DateTime.ParseExact(_text, "F", _dateFormat); | ||
134 | #endif | ||
135 | break; | ||
136 | case NAME: | ||
137 | _name = _text; | ||
138 | break; | ||
139 | case VALUE: | ||
140 | if (_value == null) | ||
141 | _value = _text; // some kits don't use <string> tag, they just do <value> | ||
142 | |||
143 | if ((_container != null) && (_container is IList)) // in an array? If so add value to it. | ||
144 | ((IList)_container).Add(_value); | ||
145 | break; | ||
146 | case MEMBER: | ||
147 | if ((_container != null) && (_container is IDictionary)) // in an struct? If so add value to it. | ||
148 | ((IDictionary)_container).Add(_name, _value); | ||
149 | break; | ||
150 | case ARRAY: | ||
151 | case STRUCT: | ||
152 | _value = _container; | ||
153 | PopContext(); | ||
154 | break; | ||
155 | } | ||
156 | break; | ||
157 | case XmlNodeType.Text: | ||
158 | if (Logger.Delegate != null) | ||
159 | Logger.WriteEntry("Text " + reader.Value, LogLevel.Information); | ||
160 | _text = reader.Value; | ||
161 | break; | ||
162 | default: | ||
163 | break; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary>Static method that parses XML in a <c>String</c> into a | ||
168 | /// request using the Singleton.</summary> | ||
169 | /// <param name="xmlData"><c>String</c> containing an XML-RPC request.</param> | ||
170 | /// <returns><c>XmlRpcRequest</c> object resulting from the parse.</returns> | ||
171 | public Object Deserialize(String xmlData) | ||
172 | { | ||
173 | StringReader sr = new StringReader(xmlData); | ||
174 | return Deserialize(sr); | ||
175 | } | ||
176 | |||
177 | /// <summary>Pop a Context of the stack, an Array or Struct has closed.</summary> | ||
178 | private void PopContext() | ||
179 | { | ||
180 | Context c = (Context)_containerStack.Pop(); | ||
181 | _container = c.Container; | ||
182 | _name = c.Name; | ||
183 | } | ||
184 | |||
185 | /// <summary>Push a Context on the stack, an Array or Struct has opened.</summary> | ||
186 | private void PushContext() | ||
187 | { | ||
188 | Context context; | ||
189 | |||
190 | context.Container = _container; | ||
191 | context.Name = _name; | ||
192 | |||
193 | _containerStack.Push(context); | ||
194 | } | ||
195 | |||
196 | /// <summary>Reset the internal state of the deserializer.</summary> | ||
197 | protected void Reset() | ||
198 | { | ||
199 | _text = null; | ||
200 | _value = null; | ||
201 | _name = null; | ||
202 | _container = null; | ||
203 | _containerStack = new Stack(); | ||
204 | } | ||
205 | |||
206 | #if __MONO__ | ||
207 | private DateTime DateParse(String str) | ||
208 | { | ||
209 | int year = Int32.Parse(str.Substring(0,4)); | ||
210 | int month = Int32.Parse(str.Substring(4,2)); | ||
211 | int day = Int32.Parse(str.Substring(6,2)); | ||
212 | int hour = Int32.Parse(str.Substring(9,2)); | ||
213 | int min = Int32.Parse(str.Substring(12,2)); | ||
214 | int sec = Int32.Parse(str.Substring(15,2)); | ||
215 | return new DateTime(year,month,day,hour,min,sec); | ||
216 | } | ||
217 | #endif | ||
218 | |||
219 | } | ||
220 | } | ||
221 | |||
222 | |||