From 33abbfced1540f0797c0dcfae0e076e4fec72115 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 10 Mar 2014 15:24:00 +0100 Subject: [PATCH] Add support for writing Native --- src/ol/format/wfsformat.js | 37 +++++++++++++++++-- .../spec/ol/format/wfs}/Native.xml | 0 test/spec/ol/format/wfsformat.test.js | 25 +++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1 => test/spec/ol/format/wfs}/Native.xml (100%) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 2e9718c748..ec1cf31e24 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -392,6 +392,26 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) { }; +/** + * @param {Node} node Node. + * @param {{vendorId: string, safeToIgnore: boolean, value: string}} + * nativeElement The native element. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.WFS.writeNative_ = function(node, nativeElement, objectStack) { + if (goog.isDef(nativeElement.vendorId)) { + node.setAttribute('vendorId', nativeElement.vendorId); + } + if (goog.isDef(nativeElement.safeToIgnore)) { + node.setAttribute('safeToIgnore', nativeElement.safeToIgnore); + } + if (goog.isDef(nativeElement.value)) { + ol.format.XSD.writeStringTextNode(node, nativeElement.value); + } +}; + + /** * @type {Object.>} * @private @@ -401,7 +421,8 @@ ol.format.WFS.TRANSACTION_SERIALIZERS_ = { 'Insert': ol.xml.makeChildAppender(ol.format.WFS.writeFeature_), 'Update': ol.xml.makeChildAppender(ol.format.WFS.writeUpdate_), 'Delete': ol.xml.makeChildAppender(ol.format.WFS.writeDelete_), - 'Property': ol.xml.makeChildAppender(ol.format.WFS.writeProperty_) + 'Property': ol.xml.makeChildAppender(ol.format.WFS.writeProperty_), + 'Native': ol.xml.makeChildAppender(ol.format.WFS.writeNative_) } }; @@ -558,6 +579,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { */ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, options) { + var objectStack = []; var node = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Transaction'); node.setAttribute('service', 'WFS'); @@ -574,21 +596,28 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, featureType: options.featureType}, ol.format.WFS.TRANSACTION_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('Insert'), inserts, - []); + objectStack); } if (goog.isDefAndNotNull(updates)) { ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS, featureType: options.featureType, featurePrefix: options.featurePrefix}, ol.format.WFS.TRANSACTION_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('Update'), updates, - []); + objectStack); } if (goog.isDefAndNotNull(deletes)) { ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS, featureType: options.featureType, featurePrefix: options.featurePrefix}, ol.format.WFS.TRANSACTION_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('Delete'), deletes, - []); + objectStack); + } + if (goog.isDef(options.nativeElements)) { + ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS, + featureType: options.featureType, featurePrefix: options.featurePrefix}, + ol.format.WFS.TRANSACTION_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('Native'), options.nativeElements, + objectStack); } return node; }; diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml b/test/spec/ol/format/wfs/Native.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml rename to test/spec/ol/format/wfs/Native.xml diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index d6e13ef40b..cd03aa504e 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -234,6 +234,31 @@ describe('ol.format.WFS', function() { }); + describe('when writing out a Transaction request', function() { + var text; + before(function(done) { + afterLoadText('spec/ol/format/wfs/Native.xml', function(xml) { + text = xml; + done(); + }); + }); + + it('handles writing out Native', function() { + var format = new ol.format.WFS(); + var serialized = format.writeTransaction(null, null, null, { + nativeElements: [{ + vendorId: 'ORACLE', + safeToIgnore: true, + value: 'ALTER SESSION ENABLE PARALLEL DML' + }, { + vendorId: 'ORACLE', + safeToIgnore: false, + value: 'Another native line goes here' + }] + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + }); });