Project

General

Profile

Download (8.03 KB) Statistics
| Branch: | Tag: | Revision:
1
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
2
 * full list of contributors). Published under the 2-clause BSD license.
3
 * See license.txt in the OpenLayers distribution or repository 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

    
78
    /**
79
     * APIMethod: read
80
     * Parse the response from a GetDomain request.
81
     */
82
    read: function(data) {
83
        if(typeof data == "string") { 
84
            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
85
        }
86
        if(data && data.nodeType == 9) {
87
            data = data.documentElement;
88
        }
89
        var obj = {};
90
        this.readNode(data, obj);
91
        return obj;
92
    },
93
    
94
    /**
95
     * Property: readers
96
     * Contains public functions, grouped by namespace prefix, that will
97
     *     be applied when a namespaced node is found matching the function
98
     *     name.  The function will be applied in the scope of this parser
99
     *     with two arguments: the node being read and a context object passed
100
     *     from the parent.
101
     */
102
    readers: {
103
        "csw": {
104
            "GetDomainResponse": function(node, obj) {
105
                this.readChildNodes(node, obj);
106
            },
107
            "DomainValues": function(node, obj) {
108
                if (!(OpenLayers.Util.isArray(obj.DomainValues))) {
109
                    obj.DomainValues = [];
110
                }
111
                var attrs = node.attributes;
112
                var domainValue = {};
113
                for(var i=0, len=attrs.length; i<len; ++i) {
114
                    domainValue[attrs[i].name] = attrs[i].nodeValue;
115
                }
116
                this.readChildNodes(node, domainValue);
117
                obj.DomainValues.push(domainValue);
118
            },
119
            "PropertyName": function(node, obj) {
120
                obj.PropertyName = this.getChildValue(node);
121
            },
122
            "ParameterName": function(node, obj) {
123
                obj.ParameterName = this.getChildValue(node);
124
            },
125
            "ListOfValues": function(node, obj) {
126
                if (!(OpenLayers.Util.isArray(obj.ListOfValues))) {
127
                    obj.ListOfValues = [];
128
                }
129
                this.readChildNodes(node, obj.ListOfValues);
130
            },
131
            "Value": function(node, obj) {
132
                var attrs = node.attributes;
133
                var value = {};
134
                for(var i=0, len=attrs.length; i<len; ++i) {
135
                    value[attrs[i].name] = attrs[i].nodeValue;
136
                }
137
                value.value = this.getChildValue(node);
138
                obj.push({Value: value});
139
            },
140
            "ConceptualScheme": function(node, obj) {
141
                obj.ConceptualScheme = {};
142
                this.readChildNodes(node, obj.ConceptualScheme);
143
            },
144
            "Name": function(node, obj) {
145
                obj.Name = this.getChildValue(node);
146
            },
147
            "Document": function(node, obj) {
148
                obj.Document = this.getChildValue(node);
149
            },
150
            "Authority": function(node, obj) {
151
                obj.Authority = this.getChildValue(node);
152
            },
153
            "RangeOfValues": function(node, obj) {
154
                obj.RangeOfValues = {};
155
                this.readChildNodes(node, obj.RangeOfValues);
156
            },
157
            "MinValue": function(node, obj) {
158
                var attrs = node.attributes;
159
                var value = {};
160
                for(var i=0, len=attrs.length; i<len; ++i) {
161
                    value[attrs[i].name] = attrs[i].nodeValue;
162
                }
163
                value.value = this.getChildValue(node);
164
                obj.MinValue = value;
165
            },
166
            "MaxValue": function(node, obj) {
167
                var attrs = node.attributes;
168
                var value = {};
169
                for(var i=0, len=attrs.length; i<len; ++i) {
170
                    value[attrs[i].name] = attrs[i].nodeValue;
171
                }
172
                value.value = this.getChildValue(node);
173
                obj.MaxValue = value;
174
            }
175
        }
176
    },
177
    
178
    /**
179
     * APIMethod: write
180
     * Given an configuration js object, write a CSWGetDomain request. 
181
     *
182
     * Parameters:
183
     * options - {Object} A object mapping the request.
184
     *
185
     * Returns:
186
     * {String} A serialized CSWGetDomain request.
187
     */
188
    write: function(options) {
189
        var node = this.writeNode("csw:GetDomain", options);
190
        return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
191
    },
192

    
193
    /**
194
     * Property: writers
195
     * As a compliment to the readers property, this structure contains public
196
     *     writing functions grouped by namespace alias and named like the
197
     *     node names they produce.
198
     */
199
    writers: {
200
        "csw": {
201
            "GetDomain": function(options) {
202
                var node = this.createElementNSPlus("csw:GetDomain", {
203
                    attributes: {
204
                        service: "CSW",
205
                        version: this.version
206
                    }
207
                });
208
                if (options.PropertyName || this.PropertyName) {
209
                    this.writeNode(
210
                        "csw:PropertyName",
211
                        options.PropertyName || this.PropertyName,
212
                        node
213
                    );
214
                } else if (options.ParameterName || this.ParameterName) {
215
                    this.writeNode(
216
                        "csw:ParameterName",
217
                        options.ParameterName || this.ParameterName,
218
                        node
219
                    );
220
                }
221
                this.readChildNodes(node, options);
222
                return node;
223
            },
224
            "PropertyName": function(value) {
225
                var node = this.createElementNSPlus("csw:PropertyName", {
226
                    value: value
227
                });
228
                return node;
229
            },
230
            "ParameterName": function(value) {
231
                var node = this.createElementNSPlus("csw:ParameterName", {
232
                    value: value
233
                });
234
                return node;
235
            }
236
        }
237
    },
238
   
239
    CLASS_NAME: "OpenLayers.Format.CSWGetDomain.v2_0_2" 
240
});
    (1-1/1)