1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
2 | * full list of contributors). Published under the Clear BSD license. |
---|
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
4 | * full text of the license. */ |
---|
5 | |
---|
6 | /** |
---|
7 | * @requires OpenLayers/Format/XML.js |
---|
8 | * @requires OpenLayers/Format/CSWGetDomain.js |
---|
9 | */ |
---|
10 | |
---|
11 | /** |
---|
12 | * Class: OpenLayers.Format.CSWGetDomain.v2_0_2 |
---|
13 | * A format for creating CSWGetDomain v2.0.2 transactions. |
---|
14 | * Create a new instance with the |
---|
15 | * <OpenLayers.Format.CSWGetDomain.v2_0_2> constructor. |
---|
16 | * |
---|
17 | * Inherits from: |
---|
18 | * - <OpenLayers.Format.XML> |
---|
19 | */ |
---|
20 | OpenLayers.Format.CSWGetDomain.v2_0_2 = OpenLayers.Class(OpenLayers.Format.XML, { |
---|
21 | |
---|
22 | /** |
---|
23 | * Property: namespaces |
---|
24 | * {Object} Mapping of namespace aliases to namespace URIs. |
---|
25 | */ |
---|
26 | namespaces: { |
---|
27 | xlink: "http://www.w3.org/1999/xlink", |
---|
28 | xsi: "http://www.w3.org/2001/XMLSchema-instance", |
---|
29 | csw: "http://www.opengis.net/cat/csw/2.0.2" |
---|
30 | }, |
---|
31 | |
---|
32 | /** |
---|
33 | * Property: defaultPrefix |
---|
34 | * {String} The default prefix (used by Format.XML). |
---|
35 | */ |
---|
36 | defaultPrefix: "csw", |
---|
37 | |
---|
38 | /** |
---|
39 | * Property: version |
---|
40 | * {String} CSW version number. |
---|
41 | */ |
---|
42 | version: "2.0.2", |
---|
43 | |
---|
44 | /** |
---|
45 | * Property: schemaLocation |
---|
46 | * {String} http://www.opengis.net/cat/csw/2.0.2 |
---|
47 | * http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd |
---|
48 | */ |
---|
49 | schemaLocation: "http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd", |
---|
50 | |
---|
51 | /** |
---|
52 | * APIProperty: PropertyName |
---|
53 | * {String} Value of the csw:PropertyName element, used when |
---|
54 | * writing a GetDomain document. |
---|
55 | */ |
---|
56 | PropertyName: null, |
---|
57 | |
---|
58 | /** |
---|
59 | * APIProperty: ParameterName |
---|
60 | * {String} Value of the csw:ParameterName element, used when |
---|
61 | * writing a GetDomain document. |
---|
62 | */ |
---|
63 | ParameterName: null, |
---|
64 | |
---|
65 | /** |
---|
66 | * Constructor: OpenLayers.Format.CSWGetDomain.v2_0_2 |
---|
67 | * A class for parsing and generating CSWGetDomain v2.0.2 transactions. |
---|
68 | * |
---|
69 | * Parameters: |
---|
70 | * options - {Object} Optional object whose properties will be set on the |
---|
71 | * instance. |
---|
72 | * |
---|
73 | * Valid options properties: |
---|
74 | * - PropertyName |
---|
75 | * - ParameterName |
---|
76 | */ |
---|
77 | initialize: function(options) { |
---|
78 | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); |
---|
79 | }, |
---|
80 | |
---|
81 | /** |
---|
82 | * APIMethod: read |
---|
83 | * Parse the response from a GetDomain request. |
---|
84 | */ |
---|
85 | read: function(data) { |
---|
86 | if(typeof data == "string") { |
---|
87 | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
---|
88 | } |
---|
89 | if(data && data.nodeType == 9) { |
---|
90 | data = data.documentElement; |
---|
91 | } |
---|
92 | var obj = {}; |
---|
93 | this.readNode(data, obj); |
---|
94 | return obj; |
---|
95 | }, |
---|
96 | |
---|
97 | /** |
---|
98 | * Property: readers |
---|
99 | * Contains public functions, grouped by namespace prefix, that will |
---|
100 | * be applied when a namespaced node is found matching the function |
---|
101 | * name. The function will be applied in the scope of this parser |
---|
102 | * with two arguments: the node being read and a context object passed |
---|
103 | * from the parent. |
---|
104 | */ |
---|
105 | readers: { |
---|
106 | "csw": { |
---|
107 | "GetDomainResponse": function(node, obj) { |
---|
108 | this.readChildNodes(node, obj); |
---|
109 | }, |
---|
110 | "DomainValues": function(node, obj) { |
---|
111 | if (!(obj.DomainValues instanceof Array)) { |
---|
112 | obj.DomainValues = []; |
---|
113 | } |
---|
114 | var attrs = node.attributes; |
---|
115 | var domainValue = {}; |
---|
116 | for(var i=0, len=attrs.length; i<len; ++i) { |
---|
117 | domainValue[attrs[i].name] = attrs[i].nodeValue; |
---|
118 | } |
---|
119 | this.readChildNodes(node, domainValue); |
---|
120 | obj.DomainValues.push(domainValue); |
---|
121 | }, |
---|
122 | "PropertyName": function(node, obj) { |
---|
123 | obj.PropertyName = this.getChildValue(node); |
---|
124 | }, |
---|
125 | "ParameterName": function(node, obj) { |
---|
126 | obj.ParameterName = this.getChildValue(node); |
---|
127 | }, |
---|
128 | "ListOfValues": function(node, obj) { |
---|
129 | if (!(obj.ListOfValues instanceof Array)) { |
---|
130 | obj.ListOfValues = []; |
---|
131 | } |
---|
132 | this.readChildNodes(node, obj.ListOfValues); |
---|
133 | }, |
---|
134 | "Value": function(node, obj) { |
---|
135 | var attrs = node.attributes; |
---|
136 | var value = {} |
---|
137 | for(var i=0, len=attrs.length; i<len; ++i) { |
---|
138 | value[attrs[i].name] = attrs[i].nodeValue; |
---|
139 | } |
---|
140 | value.value = this.getChildValue(node); |
---|
141 | obj.push({Value: value}); |
---|
142 | }, |
---|
143 | "ConceptualScheme": function(node, obj) { |
---|
144 | obj.ConceptualScheme = {}; |
---|
145 | this.readChildNodes(node, obj.ConceptualScheme); |
---|
146 | }, |
---|
147 | "Name": function(node, obj) { |
---|
148 | obj.Name = this.getChildValue(node); |
---|
149 | }, |
---|
150 | "Document": function(node, obj) { |
---|
151 | obj.Document = this.getChildValue(node); |
---|
152 | }, |
---|
153 | "Authority": function(node, obj) { |
---|
154 | obj.Authority = this.getChildValue(node); |
---|
155 | }, |
---|
156 | "RangeOfValues": function(node, obj) { |
---|
157 | obj.RangeOfValues = {}; |
---|
158 | this.readChildNodes(node, obj.RangeOfValues); |
---|
159 | }, |
---|
160 | "MinValue": function(node, obj) { |
---|
161 | var attrs = node.attributes; |
---|
162 | var value = {} |
---|
163 | for(var i=0, len=attrs.length; i<len; ++i) { |
---|
164 | value[attrs[i].name] = attrs[i].nodeValue; |
---|
165 | } |
---|
166 | value.value = this.getChildValue(node); |
---|
167 | obj.MinValue = value; |
---|
168 | }, |
---|
169 | "MaxValue": function(node, obj) { |
---|
170 | var attrs = node.attributes; |
---|
171 | var value = {} |
---|
172 | for(var i=0, len=attrs.length; i<len; ++i) { |
---|
173 | value[attrs[i].name] = attrs[i].nodeValue; |
---|
174 | } |
---|
175 | value.value = this.getChildValue(node); |
---|
176 | obj.MaxValue = value; |
---|
177 | } |
---|
178 | } |
---|
179 | }, |
---|
180 | |
---|
181 | /** |
---|
182 | * APIMethod: write |
---|
183 | * Given an configuration js object, write a CSWGetDomain request. |
---|
184 | * |
---|
185 | * Parameters: |
---|
186 | * options - {Object} A object mapping the request. |
---|
187 | * |
---|
188 | * Returns: |
---|
189 | * {String} A serialized CSWGetDomain request. |
---|
190 | */ |
---|
191 | write: function(options) { |
---|
192 | var node = this.writeNode("csw:GetDomain", options); |
---|
193 | return OpenLayers.Format.XML.prototype.write.apply(this, [node]); |
---|
194 | }, |
---|
195 | |
---|
196 | /** |
---|
197 | * Property: writers |
---|
198 | * As a compliment to the readers property, this structure contains public |
---|
199 | * writing functions grouped by namespace alias and named like the |
---|
200 | * node names they produce. |
---|
201 | */ |
---|
202 | writers: { |
---|
203 | "csw": { |
---|
204 | "GetDomain": function(options) { |
---|
205 | var node = this.createElementNSPlus("csw:GetDomain", { |
---|
206 | attributes: { |
---|
207 | service: "CSW", |
---|
208 | version: this.version |
---|
209 | } |
---|
210 | }); |
---|
211 | if (options.PropertyName || this.PropertyName) { |
---|
212 | this.writeNode( |
---|
213 | "csw:PropertyName", |
---|
214 | options.PropertyName || this.PropertyName, |
---|
215 | node |
---|
216 | ); |
---|
217 | } else if (options.ParameterName || this.ParameterName) { |
---|
218 | this.writeNode( |
---|
219 | "csw:ParameterName", |
---|
220 | options.ParameterName || this.ParameterName, |
---|
221 | node |
---|
222 | ); |
---|
223 | } |
---|
224 | this.readChildNodes(node, options); |
---|
225 | return node; |
---|
226 | }, |
---|
227 | "PropertyName": function(value) { |
---|
228 | var node = this.createElementNSPlus("csw:PropertyName", { |
---|
229 | value: value |
---|
230 | }); |
---|
231 | return node; |
---|
232 | }, |
---|
233 | "ParameterName": function(value) { |
---|
234 | var node = this.createElementNSPlus("csw:ParameterName", { |
---|
235 | value: value |
---|
236 | }); |
---|
237 | return node; |
---|
238 | } |
---|
239 | } |
---|
240 | }, |
---|
241 | |
---|
242 | CLASS_NAME: "OpenLayers.Format.CSWGetDomain.v2_0_2" |
---|
243 | }); |
---|