add formats for WPS GetCapabilities, WPS DescribeProcess and WPS Execute, thanks ahocevar for the great rework on the patch, r=ahocevar, see #3307)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12124 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2011-06-22 09:54:35 +00:00
parent 39d9715853
commit 1aa76f6de6
12 changed files with 1386 additions and 1 deletions

View File

@@ -232,6 +232,9 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
delete obj.bottom;
delete obj.right;
delete obj.top;
},
"Language": function(node, obj) {
obj.language = this.getChildValue(node);
}
}
},
@@ -264,11 +267,21 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
value: options.bounds.right + " " + options.bounds.top });
return node;
},
"Identifier": function(identifier) {
var node = this.createElementNSPlus("ows:Identifier", {
value: identifier });
return node;
},
"Title": function(title) {
var node = this.createElementNSPlus("ows:Title", {
value: title });
return node;
},
"Abstract": function(abstractValue) {
var node = this.createElementNSPlus("ows:Abstract", {
value: abstractValue });
return node;
},
"OutputFormat": function(format) {
var node = this.createElementNSPlus("ows:OutputFormat", {
value: format });

View File

@@ -47,6 +47,9 @@ OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommo
"AnyValue": function(node, parameter) {
parameter.anyValue = true;
},
"DataType": function(node, parameter) {
parameter.dataType = this.getChildValue(node);
},
"Range": function(node, allowedValues) {
allowedValues.range = {};
this.readChildNodes(node, allowedValues.range);
@@ -65,7 +68,46 @@ OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommo
}
}, OpenLayers.Format.OWSCommon.v1.prototype.readers["ows"])
},
/**
* Property: writers
* As a compliment to the readers property, this structure contains public
* writing functions grouped by namespace alias and named like the
* node names they produce.
*/
writers: {
"ows": OpenLayers.Util.applyDefaults({
"Range": function(range) {
var node = this.createElementNSPlus("ows:Range", {
attributes: {
'ows:rangeClosure': range.closure
}
});
this.writeNode("ows:MinimumValue", range.minValue, node);
this.writeNode("ows:MaximumValue", range.maxValue, node);
return node;
},
"MinimumValue": function(minValue) {
var node = this.createElementNSPlus("ows:MinimumValue", {
value: minValue
});
return node;
},
"MaximumValue": function(maxValue) {
var node = this.createElementNSPlus("ows:MaximumValue", {
value: maxValue
});
return node;
},
"Value": function(value) {
var node = this.createElementNSPlus("ows:Value", {
value: value
});
return node;
}
}, OpenLayers.Format.OWSCommon.v1.prototype.writers["ows"])
},
CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_1_0"
});

View File

@@ -0,0 +1,79 @@
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
*/
/**
* Class: OpenLayers.Format.WPSCapabilities
* Read WPS Capabilities.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.WPSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* APIProperty: defaultVersion
* {String} Version number to assume if none found. Default is "1.0.0".
*/
defaultVersion: "1.0.0",
/**
* APIProperty: version
* {String} Specify a version string if one is known.
*/
version: null,
/**
* Property: parser
* {<OpenLayers.Format>} A cached versioned format used for reading.
*/
parser: null,
/**
* Constructor: OpenLayers.Format.WPSCapabilities
* Create a new parser for WPS Capabilities.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
/**
* APIMethod: read
* Read capabilities data from a string, and return information about
* the service.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Info about the WPS
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
var root = data.documentElement;
var version = this.version || root.getAttribute("version") || this.defaultVersion;
if(!this.parser || this.parser.version !== version) {
var constr = OpenLayers.Format.WPSCapabilities[
"v" + version.replace(/\./g, "_")
];
if(!constr) {
throw "Can't find a WPS capabilities parser for version " + version;
}
var parser = new constr(this.options);
}
var capabilities = parser.read(data);
capabilities.version = version;
return capabilities;
},
CLASS_NAME: "OpenLayers.Format.WPSCapabilities"
});

View File

@@ -0,0 +1,119 @@
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/WPSCapabilities.js
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
*/
/**
* Class: OpenLayers.Format.WPSCapabilities.v1_0_0
* Read WPS Capabilities version 1.0.0.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.WPSCapabilities.v1_0_0 = OpenLayers.Class(
OpenLayers.Format.XML, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows/1.1",
wps: "http://www.opengis.net/wps/1.0.0",
xlink: "http://www.w3.org/1999/xlink"
},
/**
* Property: regExes
* Compiled regular expressions for manipulating strings.
*/
regExes: {
trimSpace: (/^\s*|\s*$/g),
removeSpace: (/\s*/g),
splitSpace: (/\s+/),
trimComma: (/\s*,\s*/g)
},
/**
* Constructor: OpenLayers.Format.WPSCapabilities.v1_0_0
* Create a new parser for WPS capabilities version 1.0.0.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: read
* Read capabilities data from a string, and return info about the WPS.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Information about the WPS service.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {};
this.readNode(data, capabilities);
return capabilities;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"wps": {
"Capabilities": function(node, obj) {
this.readChildNodes(node, obj);
},
"ProcessOfferings": function(node, obj) {
obj.processOfferings = {};
this.readChildNodes(node, obj.processOfferings);
},
"Process": function(node, processOfferings) {
var processVersion = this.getAttributeNS(node, this.namespaces.wps, "processVersion");
var process = {processVersion: processVersion};
this.readChildNodes(node, process);
processOfferings[process.identifier] = process;
},
"Languages": function(node, obj) {
obj.languages = [];
this.readChildNodes(node, obj.languages);
},
"Default": function(node, languages) {
var language = {isDefault: true};
this.readChildNodes(node, language);
languages.push(language);
},
"Supported": function(node, languages) {
var language = {};
this.readChildNodes(node, language);
languages.push(language);
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.WPSCapabilities.v1_0_0"
});

View File

@@ -0,0 +1,180 @@
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
*/
/**
* Class: OpenLayers.Format.WPSDescribeProcess
* Read WPS DescribeProcess responses.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.WPSDescribeProcess = OpenLayers.Class(
OpenLayers.Format.XML, {
/**
* Constant: VERSION
* {String} 1.0.0
*/
VERSION: "1.0.0",
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
wps: "http://www.opengis.net/wps/1.0.0",
ows: "http://www.opengis.net/ows/1.1",
xsi: "http://www.w3.org/2001/XMLSchema-instance"
},
/**
* Property: schemaLocation
* {String} Schema location
*/
schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd",
/**
* Property: defaultPrefix
*/
defaultPrefix: "wps",
/**
* Property: regExes
* Compiled regular expressions for manipulating strings.
*/
regExes: {
trimSpace: (/^\s*|\s*$/g),
removeSpace: (/\s*/g),
splitSpace: (/\s+/),
trimComma: (/\s*,\s*/g)
},
/**
* Constructor: OpenLayers.Format.WPSDescribeProcess
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
/**
* APIMethod: read
* Parse a WPS DescribeProcess and return an object with its information.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object}
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var info = {};
this.readNode(data, info);
return info;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"wps": {
"ProcessDescriptions": function(node, obj) {
obj.processDescriptions = {};
this.readChildNodes(node, obj.processDescriptions);
},
"ProcessDescription": function(node, processDescriptions) {
var processVersion = this.getAttributeNS(node, this.namespaces.wps, "processVersion");
var processDescription = {
processVersion: processVersion,
statusSupported: (node.getAttribute("statusSupported") === "true"),
storeSupported: (node.getAttribute("storeSupported") === "true")
};
this.readChildNodes(node, processDescription);
processDescriptions[processDescription.identifier] = processDescription;
},
"DataInputs": function(node, processDescription) {
processDescription.dataInputs = [];
this.readChildNodes(node, processDescription.dataInputs);
},
"ProcessOutputs": function(node, processDescription) {
processDescription.processOutputs = [];
this.readChildNodes(node, processDescription.processOutputs);
},
"Output": function(node, processOutputs) {
var output = {};
this.readChildNodes(node, output);
processOutputs.push(output);
},
"ComplexOutput": function(node, output) {
output.complexOutput = {};
this.readChildNodes(node, output.complexOutput);
},
"Input": function(node, dataInputs) {
var input = {
maxOccurs: parseInt(node.getAttribute("maxOccurs")),
minOccurs: parseInt(node.getAttribute("minOccurs"))
};
this.readChildNodes(node, input);
dataInputs.push(input);
},
"BoundingBoxData": function(node, input) {
input.boundingBoxData = {};
this.readChildNodes(node, input.boundingBoxData);
},
"CRS": function(node, obj) {
if (!obj.CRSs) {
obj.CRSs = {};
}
obj.CRSs[this.getChildValue(node)] = true;
},
"LiteralData": function(node, input) {
input.literalData = {};
this.readChildNodes(node, input.literalData);
},
"ComplexData": function(node, input) {
input.complexData = {};
this.readChildNodes(node, input.complexData);
},
"Default": function(node, complexData) {
complexData["default"] = {};
this.readChildNodes(node, complexData["default"]);
},
"Supported": function(node, complexData) {
complexData["supported"] = {};
this.readChildNodes(node, complexData["supported"]);
},
"Format": function(node, obj) {
var format = {};
this.readChildNodes(node, format);
if (!obj.formats) {
obj.formats = {};
}
obj.formats[format.mimeType] = true;
},
"MimeType": function(node, format) {
format.mimeType = this.getChildValue(node);
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.WPSDescribeProcess"
});

View File

@@ -0,0 +1,243 @@
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
*/
/**
* Class: OpenLayers.Format.WPSExecute version 1.0.0
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows/1.1",
gml: "http://www.opengis.net/gml",
wps: "http://www.opengis.net/wps/1.0.0",
wfs: "http://www.opengis.net/wfs",
ogc: "http://www.opengis.net/ogc",
wcs: "http://www.opengis.net/wcs/1.1.1",
xlink: "http://www.w3.org/1999/xlink",
xsi: "http://www.w3.org/2001/XMLSchema-instance"
},
/**
* Property: regExes
* Compiled regular expressions for manipulating strings.
*/
regExes: {
trimSpace: (/^\s*|\s*$/g),
removeSpace: (/\s*/g),
splitSpace: (/\s+/),
trimComma: (/\s*,\s*/g)
},
/**
* Constant: VERSION
* {String} 1.0.0
*/
VERSION: "1.0.0",
/**
* Property: schemaLocation
* {String} Schema location
*/
schemaLocation: "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd",
schemaLocationAttr: function(options) {
return undefined;
},
/**
* Constructor: OpenLayers.Format.WPSExecute
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
/**
* Method: write
*
* Parameters:
* options - {Object} Optional object.
*
* Returns:
* {String} An WPS Execute request XML string.
*/
write: function(options) {
var doc;
if (window.ActiveXObject) {
doc = new ActiveXObject("Microsoft.XMLDOM");
this.xmldom = doc;
} else {
doc = document.implementation.createDocument("", "", null);
}
var node = this.writeNode("wps:Execute", options, doc);
this.setAttributeNS(
node, this.namespaces.xsi,
"xsi:schemaLocation", this.schemaLocation
);
return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
},
/**
* Property: writers
* As a compliment to the readers property, this structure contains public
* writing functions grouped by namespace alias and named like the
* node names they produce.
*/
writers: {
"wps": {
"Execute": function(options) {
var node = this.createElementNSPlus("wps:Execute", {
attributes: {
version: this.VERSION,
service: 'WPS'
}
});
this.writeNode("ows:Identifier", options.identifier, node);
this.writeNode("wps:DataInputs", options.dataInputs, node);
this.writeNode("wps:ResponseForm", options.responseForm, node);
return node;
},
"ResponseForm": function(responseForm) {
var node = this.createElementNSPlus("wps:ResponseForm", {});
if (responseForm.rawDataOutput) {
this.writeNode("wps:RawDataOutput", responseForm.rawDataOutput, node);
}
if (responseForm.responseDocument) {
this.writeNode("wps:ResponseDocument", responseForm.responseDocument, node);
}
return node;
},
"ResponseDocument": function(responseDocument) {
var node = this.createElementNSPlus("wps:ResponseDocument", {
attributes: {
storeExecuteResponse: responseDocument.storeExecuteResponse,
lineage: responseDocument.lineage,
status: responseDocument.status
}
});
if (responseDocument.output) {
this.writeNode("wps:Output", responseDocument.output, node);
}
return node;
},
"Output": function(output) {
var node = this.createElementNSPlus("wps:Output", {
attributes: {
asReference: output.asReference
}
});
this.writeNode("ows:Identifier", output.identifier, node);
this.writeNode("ows:Title", output.title, node);
this.writeNode("ows:Abstract", output["abstract"], node);
return node;
},
"RawDataOutput": function(rawDataOutput) {
var node = this.createElementNSPlus("wps:RawDataOutput", {
attributes: {
mimeType: rawDataOutput.mimeType
}
});
this.writeNode("ows:Identifier", rawDataOutput.identifier, node);
return node;
},
"DataInputs": function(dataInputs) {
var node = this.createElementNSPlus("wps:DataInputs", {});
for (var i=0, ii=dataInputs.length; i<ii; ++i) {
this.writeNode("wps:Input", dataInputs[i], node);
}
return node;
},
"Input": function(input) {
var node = this.createElementNSPlus("wps:Input", {});
this.writeNode("ows:Identifier", input.identifier, node);
if (input.title) {
this.writeNode("ows:Title", input.title, node);
}
if (input.data) {
this.writeNode("wps:Data", input.data, node);
}
if (input.reference) {
this.writeNode("wps:Reference", input.reference, node);
}
return node;
},
"Data": function(data) {
var node = this.createElementNSPlus("wps:Data", {});
if (data.literalData) {
this.writeNode("wps:LiteralData", data.literalData, node);
} else if (data.complexData) {
this.writeNode("wps:ComplexData", data.complexData, node);
}
return node;
},
"LiteralData": function(literalData) {
var node = this.createElementNSPlus("wps:LiteralData", {
attributes: {
uom: literalData.uom
},
value: literalData.value
});
return node;
},
"ComplexData": function(complexData) {
var node = this.createElementNSPlus("wps:ComplexData", {
attributes: {
mimeType: complexData.mimeType,
encoding: complexData.encoding,
schema: complexData.schema
}
});
node.appendChild(
this.getXMLDoc().createCDATASection(complexData.value)
);
return node;
},
"Reference": function(reference) {
var node = this.createElementNSPlus("wps:Reference", {
attributes: {
mimeType: reference.mimeType,
"xlink:href": reference.href,
method: reference.method,
encoding: reference.encoding,
schema: reference.schema
}
});
if (reference.body) {
this.writeNode("wps:Body", reference.body, node);
}
return node;
},
"Body": function(body) {
var node = this.createElementNSPlus("wps:Body", {});
if (body.wfs) {
// OpenLayers.Format.WFST expects these to be on the
// instance and not in the options
this.featureType = body.wfs.featureType;
this.version = body.wfs.version;
this.writeNode("wfs:GetFeature", body.wfs, node);
} else {
this.writeNode("wps:Execute", body, node);
}
return node;
}
},
"wfs": OpenLayers.Format.WFST.v1_1_0.prototype.writers.wfs,
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows
},
CLASS_NAME: "OpenLayers.Format.WPSExecute"
});