Added changes to Format/WPS*: BoundingBox for DescribeProcess, multiple outputs for Execute as well as Format.WPS.readers

This commit is contained in:
Jachym Cepicky
2012-06-12 22:48:48 +02:00
parent 3a5abf552a
commit ff06ab64c6
4 changed files with 172 additions and 15 deletions
@@ -127,6 +127,10 @@ OpenLayers.Format.WPSDescribeProcess = OpenLayers.Class(
output.complexOutput = {}; output.complexOutput = {};
this.readChildNodes(node, output.complexOutput); this.readChildNodes(node, output.complexOutput);
}, },
"LiteralOutput": function(node, output) {
output.literalOutput = {};
this.readChildNodes(node, output.literalOutput);
},
"Input": function(node, dataInputs) { "Input": function(node, dataInputs) {
var input = { var input = {
maxOccurs: parseInt(node.getAttribute("maxOccurs")), maxOccurs: parseInt(node.getAttribute("maxOccurs")),
+136 -4
View File
@@ -93,6 +93,28 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
return OpenLayers.Format.XML.prototype.write.apply(this, [node]); return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
}, },
/**
* APIMethod: read
* Parse a WPS Execute 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: writers * Property: writers
* As a compliment to the readers property, this structure contains public * As a compliment to the readers property, this structure contains public
@@ -131,15 +153,20 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
status: responseDocument.status status: responseDocument.status
} }
}); });
if (responseDocument.output) { if (responseDocument.outputs) {
this.writeNode("wps:Output", responseDocument.output, node); for (var i = 0, len = responseDocument.outputs.length; i < len; i++) {
this.writeNode("wps:Output", responseDocument.outputs[i], node);
}
} }
return node; return node;
}, },
"Output": function(output) { "Output": function(output) {
var node = this.createElementNSPlus("wps:Output", { var node = this.createElementNSPlus("wps:Output", {
attributes: { attributes: {
asReference: output.asReference asReference: output.asReference,
mimeType: output.mimeType,
encoding: output.encoding,
schema: output.schema
} }
}); });
this.writeNode("ows:Identifier", output.identifier, node); this.writeNode("ows:Identifier", output.identifier, node);
@@ -150,7 +177,9 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
"RawDataOutput": function(rawDataOutput) { "RawDataOutput": function(rawDataOutput) {
var node = this.createElementNSPlus("wps:RawDataOutput", { var node = this.createElementNSPlus("wps:RawDataOutput", {
attributes: { attributes: {
mimeType: rawDataOutput.mimeType mimeType: rawDataOutput.mimeType,
encoding: rawDataOutput.encoding,
schema: rawDataOutput.schema
} }
}); });
this.writeNode("ows:Identifier", rawDataOutput.identifier, node); this.writeNode("ows:Identifier", rawDataOutput.identifier, node);
@@ -186,6 +215,8 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
this.writeNode("wps:LiteralData", data.literalData, node); this.writeNode("wps:LiteralData", data.literalData, node);
} else if (data.complexData) { } else if (data.complexData) {
this.writeNode("wps:ComplexData", data.complexData, node); this.writeNode("wps:ComplexData", data.complexData, node);
} else if (data.boundingBoxData) {
this.writeNode("ows:BoundingBox", data.boundingBoxData, node);
} }
return node; return node;
}, },
@@ -257,6 +288,107 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers.ows
}, },
/**
* 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": {
"ExecuteResponse": function(node, obj) {
obj.executeResponse = {
lang: node.getAttribute("lang"),
statusLocation: node.getAttribute("statusLocation"),
serviceInstance: node.getAttribute("serviceInstance"),
service: node.getAttribute("service")
};
this.readChildNodes(node, obj.executeResponse);
},
"Process":function(node,obj) {
obj.process = {};
this.readChildNodes(node, obj.process);
},
"Status":function(node,obj) {
obj.status = {
creationTime: node.getAttribute("creationTime")
};
this.readChildNodes(node, obj.status);
},
"ProcessSucceeded": function(node,obj) {
obj.processSucceeded = true;
},
"ProcessOutputs": function(node, processDescription) {
processDescription.processOutputs = [];
this.readChildNodes(node, processDescription.processOutputs);
},
"Output": function(node, processOutputs) {
var output = {};
this.readChildNodes(node, output);
processOutputs.push(output);
},
"Reference": function(node, output) {
output.reference = {
href: node.getAttribute("href"),
mimeType: node.getAttribute("mimeType"),
encoding: node.getAttribute("encoding"),
schema: node.getAttribute("schema")
};
},
"Data": function(node, output) {
output.data = {};
this.readChildNodes(node, output);
},
"LiteralData": function(node, output) {
output.literalData = {
dataType: node.getAttribute("dataType"),
uom: node.getAttribute("uom"),
value: this.getChildValue(node)
};
},
"ComplexData": function(node, output) {
output.complexData = {
mimeType: node.getAttribute("mimeType"),
schema: node.getAttribute("schema"),
encoding: node.getAttribute("encoding"),
value: ""
};
// try to get *some* value, ignore the empty text values
if (this.isSimpleContent(node)) {
for(var child=node.firstChild; child; child=child.nextSibling) {
switch(child.nodeType) {
case 3: // text node
case 4: // cdata section
output.complexData.value += child.nodeValue;
}
}
}
else {
for(var child=node.firstChild; child; child=child.nextSibling) {
if (child.nodeType == 1) {
output.complexData.value = child;
}
}
}
},
"BoundingBox": function(node, output) {
output.boundingBoxData = {
dimensions: node.getAttribute("dimensions"),
crs: node.getAttribute("crs")
};
this.readChildNodes(node, output.boundingBoxData);
}
},
// TODO: we should add Exception parsing here
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.WPSExecute" CLASS_NAME: "OpenLayers.Format.WPSExecute"
}); });
+11 -1
View File
@@ -4,7 +4,7 @@
<script type="text/javascript"> <script type="text/javascript">
function test_read_WPSDescribeProcess(t) { function test_read_WPSDescribeProcess(t) {
t.plan(16); t.plan(17);
var parser = new OpenLayers.Format.WPSDescribeProcess(); var parser = new OpenLayers.Format.WPSDescribeProcess();
var text = var text =
@@ -109,6 +109,13 @@
' </Supported>' + ' </Supported>' +
' </ComplexOutput>' + ' </ComplexOutput>' +
' </Output>' + ' </Output>' +
' <Output>' +
' <ows:Identifier>literal</ows:Identifier>' +
' <ows:Title>literal output</ows:Title>' +
' <LiteralOutput>' +
' <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#integer">integer</ows:DataType>'+
' </LiteralOutput>' +
' </Output>' +
' </ProcessOutputs>' + ' </ProcessOutputs>' +
' </ProcessDescription>' + ' </ProcessDescription>' +
'</wps:ProcessDescriptions>'; '</wps:ProcessDescriptions>';
@@ -135,6 +142,9 @@
t.eq(result.complexOutput["supported"].formats["text/xml; subtype=gml/3.1.1"], true, "processOutputs supported format read correctly [1/2]"); t.eq(result.complexOutput["supported"].formats["text/xml; subtype=gml/3.1.1"], true, "processOutputs supported format read correctly [1/2]");
t.eq(result.complexOutput["supported"].formats["application/wkt"], true, "processOutputs supported format read correctly [1/2]"); t.eq(result.complexOutput["supported"].formats["application/wkt"], true, "processOutputs supported format read correctly [1/2]");
var literalresult = buffer.processOutputs[1];
t.eq(literalresult.literalOutput.dataType, "integer", "processOutputs supported data type read corectly");
text = '<?xml version="1.0" encoding="UTF-8"?>' + text = '<?xml version="1.0" encoding="UTF-8"?>' +
'<wps:ProcessDescriptions service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0"' + '<wps:ProcessDescriptions service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en"' + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en"' +
+21 -10
View File
@@ -309,12 +309,12 @@
responseForm: { responseForm: {
responseDocument: { responseDocument: {
storeExecuteResponse: true, storeExecuteResponse: true,
output: { outputs: [{
asReference: true, asReference: true,
identifier: 'BufferedPolygon', identifier: 'BufferedPolygon',
title: 'Area serviced by playground.', title: 'Area serviced by playground.',
'abstract': 'Area within which most users of this playground will live.' 'abstract': 'Area within which most users of this playground will live.'
} }]
} }
} }
}); });
@@ -349,6 +349,11 @@
' <ows:Title>Area serviced by playground.</ows:Title>' + ' <ows:Title>Area serviced by playground.</ows:Title>' +
' <ows:Abstract>Area within which most users of this playground will live.</ows:Abstract>' + ' <ows:Abstract>Area within which most users of this playground will live.</ows:Abstract>' +
' </wps:Output>' + ' </wps:Output>' +
' <wps:Output>' +
' <ows:Identifier>literal</ows:Identifier>' +
' <ows:Title/>' +
' <ows:Abstract/>' +
' </wps:Output>' +
' </wps:ResponseDocument>' + ' </wps:ResponseDocument>' +
' </wps:ResponseForm>' + ' </wps:ResponseForm>' +
'</wps:Execute>'; '</wps:Execute>';
@@ -381,15 +386,21 @@
storeExecuteResponse: true, storeExecuteResponse: true,
lineage: true, lineage: true,
status: true, status: true,
output: { outputs: [
asReference: true, {
identifier: 'BufferedPolygon', asReference: true,
title: 'Area serviced by playground.', identifier: 'BufferedPolygon',
'abstract': 'Area within which most users of this playground will live.' title: 'Area serviced by playground.',
} 'abstract': 'Area within which most users of this playground will live.'
},
{
identifier: 'literal'
}
]
} }
} }
}); });
console.log(result);
t.xml_eq(result, expected, "WPS Execute written out correctly"); t.xml_eq(result, expected, "WPS Execute written out correctly");
} }
@@ -461,12 +472,12 @@
responseForm: { responseForm: {
responseDocument: { responseDocument: {
storeExecuteResponse: true, storeExecuteResponse: true,
output: { outputs: [{
asReference: true, asReference: true,
identifier: 'BufferedPolygon', identifier: 'BufferedPolygon',
title: 'Area serviced by playground.', title: 'Area serviced by playground.',
'abstract': 'Area within which most users of this playground will live.' 'abstract': 'Area within which most users of this playground will live.'
} }]
} }
} }
}); });