[76] | 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 | */ |
---|
| 9 | |
---|
| 10 | if (!OpenLayers.Format.OWSCommon) { |
---|
| 11 | OpenLayers.Format.OWSCommon = {}; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | * Class: OpenLayers.Format.OWSCommon.v1 |
---|
| 16 | * Common readers and writers for OWSCommon v1.X formats |
---|
| 17 | */ |
---|
| 18 | OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, { |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * Property: regExes |
---|
| 22 | * Compiled regular expressions for manipulating strings. |
---|
| 23 | */ |
---|
| 24 | regExes: { |
---|
| 25 | trimSpace: (/^\s*|\s*$/g), |
---|
| 26 | removeSpace: (/\s*/g), |
---|
| 27 | splitSpace: (/\s+/), |
---|
| 28 | trimComma: (/\s*,\s*/g) |
---|
| 29 | }, |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * Property: readers |
---|
| 33 | * Contains public functions, grouped by namespace prefix, that will |
---|
| 34 | * be applied when a namespaced node is found matching the function |
---|
| 35 | * name. The function will be applied in the scope of this parser |
---|
| 36 | * with two arguments: the node being read and a context object passed |
---|
| 37 | * from the parent. |
---|
| 38 | */ |
---|
| 39 | readers: { |
---|
| 40 | "ows": { |
---|
| 41 | "ServiceIdentification": function(node, obj) { |
---|
| 42 | obj.serviceIdentification = {}; |
---|
| 43 | this.readChildNodes(node, obj.serviceIdentification); |
---|
| 44 | }, |
---|
| 45 | "Title": function(node, obj) { |
---|
| 46 | obj.title = this.getChildValue(node); |
---|
| 47 | }, |
---|
| 48 | "Abstract": function(node, serviceIdentification) { |
---|
| 49 | serviceIdentification["abstract"] = this.getChildValue(node); |
---|
| 50 | }, |
---|
| 51 | "Keywords": function(node, serviceIdentification) { |
---|
| 52 | serviceIdentification.keywords = {}; |
---|
| 53 | this.readChildNodes(node, serviceIdentification.keywords); |
---|
| 54 | }, |
---|
| 55 | "Keyword": function(node, keywords) { |
---|
| 56 | keywords[this.getChildValue(node)] = true; |
---|
| 57 | }, |
---|
| 58 | "ServiceType": function(node, serviceIdentification) { |
---|
| 59 | serviceIdentification.serviceType = { |
---|
| 60 | codeSpace: node.getAttribute('codeSpace'), |
---|
| 61 | value: this.getChildValue(node)}; |
---|
| 62 | }, |
---|
| 63 | "ServiceTypeVersion": function(node, serviceIdentification) { |
---|
| 64 | serviceIdentification.serviceTypeVersion = this.getChildValue(node); |
---|
| 65 | }, |
---|
| 66 | "Fees": function(node, serviceIdentification) { |
---|
| 67 | serviceIdentification.fees = this.getChildValue(node); |
---|
| 68 | }, |
---|
| 69 | "AccessConstraints": function(node, serviceIdentification) { |
---|
| 70 | serviceIdentification.accessConstraints = |
---|
| 71 | this.getChildValue(node); |
---|
| 72 | }, |
---|
| 73 | "ServiceProvider": function(node, obj) { |
---|
| 74 | obj.serviceProvider = {}; |
---|
| 75 | this.readChildNodes(node, obj.serviceProvider); |
---|
| 76 | }, |
---|
| 77 | "ProviderName": function(node, serviceProvider) { |
---|
| 78 | serviceProvider.providerName = this.getChildValue(node); |
---|
| 79 | }, |
---|
| 80 | "ProviderSite": function(node, serviceProvider) { |
---|
| 81 | serviceProvider.providerSite = this.getAttributeNS(node, |
---|
| 82 | this.namespaces.xlink, "href"); |
---|
| 83 | }, |
---|
| 84 | "ServiceContact": function(node, serviceProvider) { |
---|
| 85 | serviceProvider.serviceContact = {}; |
---|
| 86 | this.readChildNodes(node, serviceProvider.serviceContact); |
---|
| 87 | }, |
---|
| 88 | "IndividualName": function(node, serviceContact) { |
---|
| 89 | serviceContact.individualName = this.getChildValue(node); |
---|
| 90 | }, |
---|
| 91 | "PositionName": function(node, serviceContact) { |
---|
| 92 | serviceContact.positionName = this.getChildValue(node); |
---|
| 93 | }, |
---|
| 94 | "ContactInfo": function(node, serviceContact) { |
---|
| 95 | serviceContact.contactInfo = {}; |
---|
| 96 | this.readChildNodes(node, serviceContact.contactInfo); |
---|
| 97 | }, |
---|
| 98 | "Phone": function(node, contactInfo) { |
---|
| 99 | contactInfo.phone = {}; |
---|
| 100 | this.readChildNodes(node, contactInfo.phone); |
---|
| 101 | }, |
---|
| 102 | "Voice": function(node, phone) { |
---|
| 103 | phone.voice = this.getChildValue(node); |
---|
| 104 | }, |
---|
| 105 | "Address": function(node, contactInfo) { |
---|
| 106 | contactInfo.address = {}; |
---|
| 107 | this.readChildNodes(node, contactInfo.address); |
---|
| 108 | }, |
---|
| 109 | "DeliveryPoint": function(node, address) { |
---|
| 110 | address.deliveryPoint = this.getChildValue(node); |
---|
| 111 | }, |
---|
| 112 | "City": function(node, address) { |
---|
| 113 | address.city = this.getChildValue(node); |
---|
| 114 | }, |
---|
| 115 | "AdministrativeArea": function(node, address) { |
---|
| 116 | address.administrativeArea = this.getChildValue(node); |
---|
| 117 | }, |
---|
| 118 | "PostalCode": function(node, address) { |
---|
| 119 | address.postalCode = this.getChildValue(node); |
---|
| 120 | }, |
---|
| 121 | "Country": function(node, address) { |
---|
| 122 | address.country = this.getChildValue(node); |
---|
| 123 | }, |
---|
| 124 | "ElectronicMailAddress": function(node, address) { |
---|
| 125 | address.electronicMailAddress = this.getChildValue(node); |
---|
| 126 | }, |
---|
| 127 | "Role": function(node, serviceContact) { |
---|
| 128 | serviceContact.role = this.getChildValue(node); |
---|
| 129 | }, |
---|
| 130 | "OperationsMetadata": function(node, obj) { |
---|
| 131 | obj.operationsMetadata = {}; |
---|
| 132 | this.readChildNodes(node, obj.operationsMetadata); |
---|
| 133 | }, |
---|
| 134 | "Operation": function(node, operationsMetadata) { |
---|
| 135 | var name = node.getAttribute("name"); |
---|
| 136 | operationsMetadata[name] = {}; |
---|
| 137 | this.readChildNodes(node, operationsMetadata[name]); |
---|
| 138 | }, |
---|
| 139 | "DCP": function(node, operation) { |
---|
| 140 | operation.dcp = {}; |
---|
| 141 | this.readChildNodes(node, operation.dcp); |
---|
| 142 | }, |
---|
| 143 | "HTTP": function(node, dcp) { |
---|
| 144 | dcp.http = {}; |
---|
| 145 | this.readChildNodes(node, dcp.http); |
---|
| 146 | }, |
---|
| 147 | "Get": function(node, http) { |
---|
| 148 | http.get = this.getAttributeNS(node, |
---|
| 149 | this.namespaces.xlink, "href"); |
---|
| 150 | }, |
---|
| 151 | "Post": function(node, http) { |
---|
| 152 | http.post = this.getAttributeNS(node, |
---|
| 153 | this.namespaces.xlink, "href"); |
---|
| 154 | }, |
---|
| 155 | "Parameter": function(node, operation) { |
---|
| 156 | if (!operation.parameters) { |
---|
| 157 | operation.parameters = {}; |
---|
| 158 | } |
---|
| 159 | var name = node.getAttribute("name"); |
---|
| 160 | operation.parameters[name] = {}; |
---|
| 161 | this.readChildNodes(node, operation.parameters[name]); |
---|
| 162 | }, |
---|
| 163 | "Value": function(node, allowedValues) { |
---|
| 164 | allowedValues[this.getChildValue(node)] = true; |
---|
| 165 | }, |
---|
| 166 | "OutputFormat": function(node, obj) { |
---|
| 167 | obj.formats.push({value: this.getChildValue(node)}); |
---|
| 168 | this.readChildNodes(node, obj); |
---|
| 169 | }, |
---|
| 170 | "WGS84BoundingBox": function(node, obj) { |
---|
| 171 | var boundingBox = {}; |
---|
| 172 | boundingBox.crs = node.getAttribute("crs"); |
---|
| 173 | if (obj.BoundingBox) { |
---|
| 174 | obj.BoundingBox.push(boundingBox); |
---|
| 175 | } else { |
---|
| 176 | obj.projection = boundingBox.crs; |
---|
| 177 | boundingBox = obj; |
---|
| 178 | } |
---|
| 179 | this.readChildNodes(node, boundingBox); |
---|
| 180 | }, |
---|
| 181 | "BoundingBox": function(node, obj) { |
---|
| 182 | // FIXME: We consider that BoundingBox is the same as WGS84BoundingBox |
---|
| 183 | // LowerCorner = "min_x min_y" |
---|
| 184 | // UpperCorner = "max_x max_y" |
---|
| 185 | // It should normally depend on the projection |
---|
| 186 | this.readers['ows']['WGS84BoundingBox'].apply(this, [node, obj]); |
---|
| 187 | }, |
---|
| 188 | "LowerCorner": function(node, obj) { |
---|
| 189 | var str = this.getChildValue(node).replace( |
---|
| 190 | this.regExes.trimSpace, ""); |
---|
| 191 | str = str.replace(this.regExes.trimComma, ","); |
---|
| 192 | var pointList = str.split(this.regExes.splitSpace); |
---|
| 193 | obj.left = pointList[0]; |
---|
| 194 | obj.bottom = pointList[1]; |
---|
| 195 | }, |
---|
| 196 | "UpperCorner": function(node, obj) { |
---|
| 197 | var str = this.getChildValue(node).replace( |
---|
| 198 | this.regExes.trimSpace, ""); |
---|
| 199 | str = str.replace(this.regExes.trimComma, ","); |
---|
| 200 | var pointList = str.split(this.regExes.splitSpace); |
---|
| 201 | obj.right = pointList[0]; |
---|
| 202 | obj.top = pointList[1]; |
---|
| 203 | obj.bounds = new OpenLayers.Bounds(obj.left, obj.bottom, |
---|
| 204 | obj.right, obj.top); |
---|
| 205 | delete obj.left; |
---|
| 206 | delete obj.bottom; |
---|
| 207 | delete obj.right; |
---|
| 208 | delete obj.top; |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | }, |
---|
| 212 | |
---|
| 213 | /** |
---|
| 214 | * Property: writers |
---|
| 215 | * As a compliment to the readers property, this structure contains public |
---|
| 216 | * writing functions grouped by namespace alias and named like the |
---|
| 217 | * node names they produce. |
---|
| 218 | */ |
---|
| 219 | writers: { |
---|
| 220 | "ows": { |
---|
| 221 | "BoundingBox": function(options) { |
---|
| 222 | var node = this.createElementNSPlus("ows:BoundingBox", { |
---|
| 223 | attributes: { |
---|
| 224 | crs: options.projection |
---|
| 225 | } |
---|
| 226 | }); |
---|
| 227 | this.writeNode("ows:LowerCorner", options, node); |
---|
| 228 | this.writeNode("ows:UpperCorner", options, node); |
---|
| 229 | return node; |
---|
| 230 | }, |
---|
| 231 | "LowerCorner": function(options) { |
---|
| 232 | var node = this.createElementNSPlus("ows:LowerCorner", { |
---|
| 233 | value: options.bounds.left + " " + options.bounds.bottom }); |
---|
| 234 | return node; |
---|
| 235 | }, |
---|
| 236 | "UpperCorner": function(options) { |
---|
| 237 | var node = this.createElementNSPlus("ows:UpperCorner", { |
---|
| 238 | value: options.bounds.right + " " + options.bounds.top }); |
---|
| 239 | return node; |
---|
| 240 | }, |
---|
| 241 | "Title": function(title) { |
---|
| 242 | var node = this.createElementNSPlus("ows:Title", { |
---|
| 243 | value: title }); |
---|
| 244 | return node; |
---|
| 245 | }, |
---|
| 246 | "OutputFormat": function(format) { |
---|
| 247 | var node = this.createElementNSPlus("ows:OutputFormat", { |
---|
| 248 | value: format }); |
---|
| 249 | return node; |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | }, |
---|
| 253 | |
---|
| 254 | CLASS_NAME: "OpenLayers.Format.OWSCommon.v1" |
---|
| 255 | |
---|
| 256 | }); |
---|