WPSExecute.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. * @requires OpenLayers/Format/XML.js
  7. * @requires OpenLayers/Format/OWSCommon/v1_1_0.js
  8. * @requires OpenLayers/Format/WCSGetCoverage.js
  9. * @requires OpenLayers/Format/WFST/v1_1_0.js
  10. */
  11. /**
  12. * Class: OpenLayers.Format.WPSExecute version 1.0.0
  13. *
  14. * Inherits from:
  15. * - <OpenLayers.Format.XML>
  16. */
  17. OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML,
  18. OpenLayers.Format.Filter.v1_1_0, {
  19. /**
  20. * Property: namespaces
  21. * {Object} Mapping of namespace aliases to namespace URIs.
  22. */
  23. namespaces: {
  24. ows: "http://www.opengis.net/ows/1.1",
  25. gml: "http://www.opengis.net/gml",
  26. wps: "http://www.opengis.net/wps/1.0.0",
  27. wfs: "http://www.opengis.net/wfs",
  28. ogc: "http://www.opengis.net/ogc",
  29. wcs: "http://www.opengis.net/wcs",
  30. xlink: "http://www.w3.org/1999/xlink",
  31. xsi: "http://www.w3.org/2001/XMLSchema-instance"
  32. },
  33. /**
  34. * Property: regExes
  35. * Compiled regular expressions for manipulating strings.
  36. */
  37. regExes: {
  38. trimSpace: (/^\s*|\s*$/g),
  39. removeSpace: (/\s*/g),
  40. splitSpace: (/\s+/),
  41. trimComma: (/\s*,\s*/g)
  42. },
  43. /**
  44. * Constant: VERSION
  45. * {String} 1.0.0
  46. */
  47. VERSION: "1.0.0",
  48. /**
  49. * Property: schemaLocation
  50. * {String} Schema location
  51. */
  52. schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd",
  53. schemaLocationAttr: function(options) {
  54. return undefined;
  55. },
  56. /**
  57. * Constructor: OpenLayers.Format.WPSExecute
  58. *
  59. * Parameters:
  60. * options - {Object} An optional object whose properties will be set on
  61. * this instance.
  62. */
  63. /**
  64. * Method: write
  65. *
  66. * Parameters:
  67. * options - {Object} Optional object.
  68. *
  69. * Returns:
  70. * {String} An WPS Execute request XML string.
  71. */
  72. write: function(options) {
  73. var doc;
  74. if (window.ActiveXObject) {
  75. doc = new ActiveXObject("Microsoft.XMLDOM");
  76. this.xmldom = doc;
  77. } else {
  78. doc = document.implementation.createDocument("", "", null);
  79. }
  80. var node = this.writeNode("wps:Execute", options, doc);
  81. this.setAttributeNS(
  82. node, this.namespaces.xsi,
  83. "xsi:schemaLocation", this.schemaLocation
  84. );
  85. return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
  86. },
  87. /**
  88. * APIMethod: read
  89. * Parse a WPS Execute and return an object with its information.
  90. *
  91. * Parameters:
  92. * data - {String} or {DOMElement} data to read/parse.
  93. *
  94. * Returns:
  95. * {Object}
  96. */
  97. read: function(data) {
  98. if(typeof data == "string") {
  99. data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
  100. }
  101. if(data && data.nodeType == 9) {
  102. data = data.documentElement;
  103. }
  104. var info = {};
  105. this.readNode(data, info);
  106. return info;
  107. },
  108. /**
  109. * Property: writers
  110. * As a compliment to the readers property, this structure contains public
  111. * writing functions grouped by namespace alias and named like the
  112. * node names they produce.
  113. */
  114. writers: {
  115. "wps": {
  116. "Execute": function(options) {
  117. var node = this.createElementNSPlus("wps:Execute", {
  118. attributes: {
  119. version: this.VERSION,
  120. service: 'WPS'
  121. }
  122. });
  123. this.writeNode("ows:Identifier", options.identifier, node);
  124. this.writeNode("wps:DataInputs", options.dataInputs, node);
  125. this.writeNode("wps:ResponseForm", options.responseForm, node);
  126. return node;
  127. },
  128. "ResponseForm": function(responseForm) {
  129. var node = this.createElementNSPlus("wps:ResponseForm", {});
  130. if (responseForm.rawDataOutput) {
  131. this.writeNode("wps:RawDataOutput", responseForm.rawDataOutput, node);
  132. }
  133. if (responseForm.responseDocument) {
  134. this.writeNode("wps:ResponseDocument", responseForm.responseDocument, node);
  135. }
  136. return node;
  137. },
  138. "ResponseDocument": function(responseDocument) {
  139. var node = this.createElementNSPlus("wps:ResponseDocument", {
  140. attributes: {
  141. storeExecuteResponse: responseDocument.storeExecuteResponse,
  142. lineage: responseDocument.lineage,
  143. status: responseDocument.status
  144. }
  145. });
  146. if (responseDocument.outputs) {
  147. for (var i = 0, len = responseDocument.outputs.length; i < len; i++) {
  148. this.writeNode("wps:Output", responseDocument.outputs[i], node);
  149. }
  150. }
  151. return node;
  152. },
  153. "Output": function(output) {
  154. var node = this.createElementNSPlus("wps:Output", {
  155. attributes: {
  156. asReference: output.asReference,
  157. mimeType: output.mimeType,
  158. encoding: output.encoding,
  159. schema: output.schema
  160. }
  161. });
  162. this.writeNode("ows:Identifier", output.identifier, node);
  163. this.writeNode("ows:Title", output.title, node);
  164. this.writeNode("ows:Abstract", output["abstract"], node);
  165. return node;
  166. },
  167. "RawDataOutput": function(rawDataOutput) {
  168. var node = this.createElementNSPlus("wps:RawDataOutput", {
  169. attributes: {
  170. mimeType: rawDataOutput.mimeType,
  171. encoding: rawDataOutput.encoding,
  172. schema: rawDataOutput.schema
  173. }
  174. });
  175. this.writeNode("ows:Identifier", rawDataOutput.identifier, node);
  176. return node;
  177. },
  178. "DataInputs": function(dataInputs) {
  179. var node = this.createElementNSPlus("wps:DataInputs", {});
  180. for (var i=0, ii=dataInputs.length; i<ii; ++i) {
  181. this.writeNode("wps:Input", dataInputs[i], node);
  182. }
  183. return node;
  184. },
  185. "Input": function(input) {
  186. var node = this.createElementNSPlus("wps:Input", {});
  187. this.writeNode("ows:Identifier", input.identifier, node);
  188. if (input.title) {
  189. this.writeNode("ows:Title", input.title, node);
  190. }
  191. if (input.data) {
  192. this.writeNode("wps:Data", input.data, node);
  193. }
  194. if (input.reference) {
  195. this.writeNode("wps:Reference", input.reference, node);
  196. }
  197. if (input.boundingBoxData) {
  198. this.writeNode("wps:BoundingBoxData", input.boundingBoxData, node);
  199. }
  200. return node;
  201. },
  202. "Data": function(data) {
  203. var node = this.createElementNSPlus("wps:Data", {});
  204. if (data.literalData) {
  205. this.writeNode("wps:LiteralData", data.literalData, node);
  206. } else if (data.complexData) {
  207. this.writeNode("wps:ComplexData", data.complexData, node);
  208. } else if (data.boundingBoxData) {
  209. this.writeNode("ows:BoundingBox", data.boundingBoxData, node);
  210. }
  211. return node;
  212. },
  213. "LiteralData": function(literalData) {
  214. var node = this.createElementNSPlus("wps:LiteralData", {
  215. attributes: {
  216. uom: literalData.uom
  217. },
  218. value: literalData.value
  219. });
  220. return node;
  221. },
  222. "ComplexData": function(complexData) {
  223. var node = this.createElementNSPlus("wps:ComplexData", {
  224. attributes: {
  225. mimeType: complexData.mimeType,
  226. encoding: complexData.encoding,
  227. schema: complexData.schema
  228. }
  229. });
  230. var data = complexData.value;
  231. if (typeof data === "string") {
  232. node.appendChild(
  233. this.getXMLDoc().createCDATASection(complexData.value)
  234. );
  235. } else {
  236. node.appendChild(data);
  237. }
  238. return node;
  239. },
  240. "Reference": function(reference) {
  241. var node = this.createElementNSPlus("wps:Reference", {
  242. attributes: {
  243. mimeType: reference.mimeType,
  244. "xlink:href": reference.href,
  245. method: reference.method,
  246. encoding: reference.encoding,
  247. schema: reference.schema
  248. }
  249. });
  250. if (reference.body) {
  251. this.writeNode("wps:Body", reference.body, node);
  252. }
  253. return node;
  254. },
  255. "BoundingBoxData": function(node, obj) {
  256. this.writers['ows']['BoundingBox'].apply(this, [node, obj, "wps:BoundingBoxData"]);
  257. },
  258. "Body": function(body) {
  259. var node = this.createElementNSPlus("wps:Body", {});
  260. if (body.wcs) {
  261. this.writeNode("wcs:GetCoverage", body.wcs, node);
  262. }
  263. else if (body.wfs) {
  264. // OpenLayers.Format.WFST expects these to be on the
  265. // instance and not in the options
  266. this.featureType = body.wfs.featureType;
  267. this.version = body.wfs.version;
  268. this.writeNode("wfs:GetFeature", body.wfs, node);
  269. } else {
  270. this.writeNode("wps:Execute", body, node);
  271. }
  272. return node;
  273. }
  274. },
  275. "wcs": OpenLayers.Format.WCSGetCoverage.prototype.writers.wcs,
  276. "wfs": OpenLayers.Format.WFST.v1_1_0.prototype.writers.wfs,
  277. "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers.ogc,
  278. "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows
  279. },
  280. /**
  281. * Property: readers
  282. * Contains public functions, grouped by namespace prefix, that will
  283. * be applied when a namespaced node is found matching the function
  284. * name. The function will be applied in the scope of this parser
  285. * with two arguments: the node being read and a context object passed
  286. * from the parent.
  287. */
  288. readers: {
  289. "wps": {
  290. "ExecuteResponse": function(node, obj) {
  291. obj.executeResponse = {
  292. lang: node.getAttribute("lang"),
  293. statusLocation: node.getAttribute("statusLocation"),
  294. serviceInstance: node.getAttribute("serviceInstance"),
  295. service: node.getAttribute("service")
  296. };
  297. this.readChildNodes(node, obj.executeResponse);
  298. },
  299. "Process":function(node,obj) {
  300. obj.process = {};
  301. this.readChildNodes(node, obj.process);
  302. },
  303. "Status":function(node,obj) {
  304. obj.status = {
  305. creationTime: node.getAttribute("creationTime")
  306. };
  307. this.readChildNodes(node, obj.status);
  308. },
  309. "ProcessSucceeded": function(node,obj) {
  310. obj.processSucceeded = true;
  311. },
  312. "ProcessOutputs": function(node, processDescription) {
  313. processDescription.processOutputs = [];
  314. this.readChildNodes(node, processDescription.processOutputs);
  315. },
  316. "Output": function(node, processOutputs) {
  317. var output = {};
  318. this.readChildNodes(node, output);
  319. processOutputs.push(output);
  320. },
  321. "Reference": function(node, output) {
  322. output.reference = {
  323. href: node.getAttribute("href"),
  324. mimeType: node.getAttribute("mimeType"),
  325. encoding: node.getAttribute("encoding"),
  326. schema: node.getAttribute("schema")
  327. };
  328. },
  329. "Data": function(node, output) {
  330. output.data = {};
  331. this.readChildNodes(node, output);
  332. },
  333. "LiteralData": function(node, output) {
  334. output.literalData = {
  335. dataType: node.getAttribute("dataType"),
  336. uom: node.getAttribute("uom"),
  337. value: this.getChildValue(node)
  338. };
  339. },
  340. "ComplexData": function(node, output) {
  341. output.complexData = {
  342. mimeType: node.getAttribute("mimeType"),
  343. schema: node.getAttribute("schema"),
  344. encoding: node.getAttribute("encoding"),
  345. value: ""
  346. };
  347. // try to get *some* value, ignore the empty text values
  348. if (this.isSimpleContent(node)) {
  349. var child;
  350. for(child=node.firstChild; child; child=child.nextSibling) {
  351. switch(child.nodeType) {
  352. case 3: // text node
  353. case 4: // cdata section
  354. output.complexData.value += child.nodeValue;
  355. }
  356. }
  357. }
  358. else {
  359. for(child=node.firstChild; child; child=child.nextSibling) {
  360. if (child.nodeType == 1) {
  361. output.complexData.value = child;
  362. }
  363. }
  364. }
  365. },
  366. "BoundingBox": function(node, output) {
  367. output.boundingBoxData = {
  368. dimensions: node.getAttribute("dimensions"),
  369. crs: node.getAttribute("crs")
  370. };
  371. this.readChildNodes(node, output.boundingBoxData);
  372. }
  373. },
  374. // TODO: we should add Exception parsing here
  375. "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
  376. },
  377. CLASS_NAME: "OpenLayers.Format.WPSExecute"
  378. });