Don't store private constants into ol/format/WFS

This commit is contained in:
Frederic Junod
2018-02-14 11:11:01 +01:00
parent 1953d41d0d
commit 308dc412aa
+68 -82
View File
@@ -16,6 +16,53 @@ import {createElementNS, isDocument, isNode, makeArrayPusher, makeChildAppender,
makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode, makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode,
pushParseAndPop, pushSerializeAndPop, setAttributeNS} from '../xml.js'; pushParseAndPop, pushSerializeAndPop, setAttributeNS} from '../xml.js';
/**
* @type {string}
*/
const FEATURE_PREFIX = 'feature';
/**
* @type {string}
*/
const XMLNS = 'http://www.w3.org/2000/xmlns/';
/**
* @type {string}
*/
const OGCNS = 'http://www.opengis.net/ogc';
/**
* @type {string}
*/
const WFSNS = 'http://www.opengis.net/wfs';
/**
* @type {string}
*/
const FESNS = 'http://www.opengis.net/fes';
/**
* @type {Object.<string, string>}
*/
const SCHEMA_LOCATIONS = {
'1.1.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
'1.0.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'
};
/**
* @const
* @type {string}
*/
const DEFAULT_VERSION = '1.1.0';
/** /**
* @classdesc * @classdesc
* Feature format for reading and writing data in the WFS format. * Feature format for reading and writing data in the WFS format.
@@ -56,8 +103,7 @@ const WFS = function(opt_options) {
* @type {string} * @type {string}
*/ */
this.schemaLocation_ = options.schemaLocation ? this.schemaLocation_ = options.schemaLocation ?
options.schemaLocation : options.schemaLocation : SCHEMA_LOCATIONS[DEFAULT_VERSION];
WFS.SCHEMA_LOCATIONS[WFS.DEFAULT_VERSION];
XMLFeature.call(this); XMLFeature.call(this);
}; };
@@ -65,60 +111,6 @@ const WFS = function(opt_options) {
inherits(WFS, XMLFeature); inherits(WFS, XMLFeature);
/**
* @const
* @type {string}
*/
WFS.FEATURE_PREFIX = 'feature';
/**
* @const
* @type {string}
*/
WFS.XMLNS = 'http://www.w3.org/2000/xmlns/';
/**
* @const
* @type {string}
*/
WFS.OGCNS = 'http://www.opengis.net/ogc';
/**
* @const
* @type {string}
*/
WFS.WFSNS = 'http://www.opengis.net/wfs';
/**
* @const
* @type {string}
*/
WFS.FESNS = 'http://www.opengis.net/fes';
/**
* @const
* @type {Object.<string, string>}
*/
WFS.SCHEMA_LOCATIONS = {
'1.1.0': 'http://www.opengis.net/wfs ' +
'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
'1.0.0': 'http://www.opengis.net/wfs ' +
'http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'
};
/**
* @const
* @type {string}
*/
WFS.DEFAULT_VERSION = '1.1.0';
/** /**
* @return {Array.<string>|string|undefined} featureType * @return {Array.<string>|string|undefined} featureType
*/ */
@@ -405,8 +397,8 @@ function writeFeature(node, feature, objectStack) {
* @param {Array.<*>} objectStack Node stack. * @param {Array.<*>} objectStack Node stack.
*/ */
function writeOgcFidFilter(node, fid, objectStack) { function writeOgcFidFilter(node, fid, objectStack) {
const filter = createElementNS(WFS.OGCNS, 'Filter'); const filter = createElementNS(OGCNS, 'Filter');
const child = createElementNS(WFS.OGCNS, 'FeatureId'); const child = createElementNS(OGCNS, 'FeatureId');
filter.appendChild(child); filter.appendChild(child);
child.setAttribute('fid', fid); child.setAttribute('fid', fid);
node.appendChild(filter); node.appendChild(filter);
@@ -419,8 +411,7 @@ function writeOgcFidFilter(node, fid, objectStack) {
* @returns {string} The value of the typeName property. * @returns {string} The value of the typeName property.
*/ */
function getTypeName(featurePrefix, featureType) { function getTypeName(featurePrefix, featureType) {
featurePrefix = featurePrefix ? featurePrefix : featurePrefix = featurePrefix ? featurePrefix : FEATURE_PREFIX;
WFS.FEATURE_PREFIX;
const prefix = featurePrefix + ':'; const prefix = featurePrefix + ':';
// The featureType already contains the prefix. // The featureType already contains the prefix.
if (featureType.indexOf(prefix) === 0) { if (featureType.indexOf(prefix) === 0) {
@@ -444,8 +435,7 @@ function writeDelete(node, feature, objectStack) {
const featureNS = context['featureNS']; const featureNS = context['featureNS'];
const typeName = getTypeName(featurePrefix, featureType); const typeName = getTypeName(featurePrefix, featureType);
node.setAttribute('typeName', typeName); node.setAttribute('typeName', typeName);
setAttributeNS(node, WFS.XMLNS, 'xmlns:' + featurePrefix, setAttributeNS(node, XMLNS, 'xmlns:' + featurePrefix, featureNS);
featureNS);
const fid = feature.getId(); const fid = feature.getId();
if (fid !== undefined) { if (fid !== undefined) {
writeOgcFidFilter(node, fid, objectStack); writeOgcFidFilter(node, fid, objectStack);
@@ -481,8 +471,7 @@ function writeUpdate(node, feature, objectStack) {
const typeName = getTypeName(featurePrefix, featureType); const typeName = getTypeName(featurePrefix, featureType);
const geometryName = feature.getGeometryName(); const geometryName = feature.getGeometryName();
node.setAttribute('typeName', typeName); node.setAttribute('typeName', typeName);
setAttributeNS(node, WFS.XMLNS, 'xmlns:' + featurePrefix, setAttributeNS(node, XMLNS, 'xmlns:' + featurePrefix, featureNS);
featureNS);
const fid = feature.getId(); const fid = feature.getId();
if (fid !== undefined) { if (fid !== undefined) {
const keys = feature.getKeys(); const keys = feature.getKeys();
@@ -514,13 +503,13 @@ function writeUpdate(node, feature, objectStack) {
* @param {Array.<*>} objectStack Node stack. * @param {Array.<*>} objectStack Node stack.
*/ */
function writeProperty(node, pair, objectStack) { function writeProperty(node, pair, objectStack) {
const name = createElementNS(WFS.WFSNS, 'Name'); const name = createElementNS(WFSNS, 'Name');
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
const gmlVersion = context['gmlVersion']; const gmlVersion = context['gmlVersion'];
node.appendChild(name); node.appendChild(name);
XSD.writeStringTextNode(name, pair.name); XSD.writeStringTextNode(name, pair.name);
if (pair.value !== undefined && pair.value !== null) { if (pair.value !== undefined && pair.value !== null) {
const value = createElementNS(WFS.WFSNS, 'Value'); const value = createElementNS(WFSNS, 'Value');
node.appendChild(value); node.appendChild(value);
if (pair.value instanceof Geometry) { if (pair.value instanceof Geometry) {
if (gmlVersion === 2) { if (gmlVersion === 2) {
@@ -608,8 +597,7 @@ function writeQuery(node, featureType, objectStack) {
node.setAttribute('srsName', srsName); node.setAttribute('srsName', srsName);
} }
if (featureNS) { if (featureNS) {
setAttributeNS(node, WFS.XMLNS, 'xmlns:' + featurePrefix, setAttributeNS(node, XMLNS, 'xmlns:' + featurePrefix, featureNS);
featureNS);
} }
const item = /** @type {ol.XmlNodeStackItem} */ (assign({}, context)); const item = /** @type {ol.XmlNodeStackItem} */ (assign({}, context));
item.node = node; item.node = node;
@@ -619,7 +607,7 @@ function writeQuery(node, featureType, objectStack) {
objectStack); objectStack);
const filter = context['filter']; const filter = context['filter'];
if (filter) { if (filter) {
const child = createElementNS(WFS.OGCNS, 'Filter'); const child = createElementNS(OGCNS, 'Filter');
node.appendChild(child); node.appendChild(child);
writeFilterCondition(child, filter, objectStack); writeFilterCondition(child, filter, objectStack);
} }
@@ -704,7 +692,7 @@ function writeWithinFilter(node, filter, objectStack) {
*/ */
function writeDuringFilter(node, filter, objectStack) { function writeDuringFilter(node, filter, objectStack) {
const valueReference = createElementNS(WFS.FESNS, 'ValueReference'); const valueReference = createElementNS(FESNS, 'ValueReference');
XSD.writeStringTextNode(valueReference, filter.propertyName); XSD.writeStringTextNode(valueReference, filter.propertyName);
node.appendChild(valueReference); node.appendChild(valueReference);
@@ -789,11 +777,11 @@ function writeIsNullFilter(node, filter, objectStack) {
function writeIsBetweenFilter(node, filter, objectStack) { function writeIsBetweenFilter(node, filter, objectStack) {
writeOgcPropertyName(node, filter.propertyName); writeOgcPropertyName(node, filter.propertyName);
const lowerBoundary = createElementNS(WFS.OGCNS, 'LowerBoundary'); const lowerBoundary = createElementNS(OGCNS, 'LowerBoundary');
node.appendChild(lowerBoundary); node.appendChild(lowerBoundary);
writeOgcLiteral(lowerBoundary, '' + filter.lowerBoundary); writeOgcLiteral(lowerBoundary, '' + filter.lowerBoundary);
const upperBoundary = createElementNS(WFS.OGCNS, 'UpperBoundary'); const upperBoundary = createElementNS(OGCNS, 'UpperBoundary');
node.appendChild(upperBoundary); node.appendChild(upperBoundary);
writeOgcLiteral(upperBoundary, '' + filter.upperBoundary); writeOgcLiteral(upperBoundary, '' + filter.upperBoundary);
} }
@@ -822,7 +810,7 @@ function writeIsLikeFilter(node, filter, objectStack) {
* @param {string} value Value. * @param {string} value Value.
*/ */
function writeOgcExpression(tagName, node, value) { function writeOgcExpression(tagName, node, value) {
const property = createElementNS(WFS.OGCNS, tagName); const property = createElementNS(OGCNS, tagName);
XSD.writeStringTextNode(property, value); XSD.writeStringTextNode(property, value);
node.appendChild(property); node.appendChild(property);
} }
@@ -868,7 +856,7 @@ function writeTimeInstant(node, time) {
* @api * @api
*/ */
WFS.writeFilter = function(filter) { WFS.writeFilter = function(filter) {
const child = createElementNS(WFS.OGCNS, 'Filter'); const child = createElementNS(OGCNS, 'Filter');
writeFilterCondition(child, filter, []); writeFilterCondition(child, filter, []);
return child; return child;
}; };
@@ -898,7 +886,7 @@ function writeGetFeature(node, featureTypes, objectStack) {
* @api * @api
*/ */
WFS.prototype.writeGetFeature = function(options) { WFS.prototype.writeGetFeature = function(options) {
const node = createElementNS(WFS.WFSNS, 'GetFeature'); const node = createElementNS(WFSNS, 'GetFeature');
node.setAttribute('service', 'WFS'); node.setAttribute('service', 'WFS');
node.setAttribute('version', '1.1.0'); node.setAttribute('version', '1.1.0');
let filter; let filter;
@@ -964,12 +952,10 @@ WFS.prototype.writeGetFeature = function(options) {
* @return {Node} Result. * @return {Node} Result.
* @api * @api
*/ */
WFS.prototype.writeTransaction = function(inserts, updates, deletes, WFS.prototype.writeTransaction = function(inserts, updates, deletes, options) {
options) {
const objectStack = []; const objectStack = [];
const node = createElementNS(WFS.WFSNS, 'Transaction'); const node = createElementNS(WFSNS, 'Transaction');
const version = options.version ? const version = options.version ? options.version : DEFAULT_VERSION;
options.version : WFS.DEFAULT_VERSION;
const gmlVersion = version === '1.0.0' ? 2 : 3; const gmlVersion = version === '1.0.0' ? 2 : 3;
node.setAttribute('service', 'WFS'); node.setAttribute('service', 'WFS');
node.setAttribute('version', version); node.setAttribute('version', version);
@@ -982,10 +968,10 @@ WFS.prototype.writeTransaction = function(inserts, updates, deletes,
node.setAttribute('handle', options.handle); node.setAttribute('handle', options.handle);
} }
} }
const schemaLocation = WFS.SCHEMA_LOCATIONS[version]; const schemaLocation = SCHEMA_LOCATIONS[version];
setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation', schemaLocation); 'xsi:schemaLocation', schemaLocation);
const featurePrefix = options.featurePrefix ? options.featurePrefix : WFS.FEATURE_PREFIX; const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX;
if (inserts) { if (inserts) {
obj = {node: node, 'featureNS': options.featureNS, obj = {node: node, 'featureNS': options.featureNS,
'featureType': options.featureType, 'featurePrefix': featurePrefix, 'featureType': options.featureType, 'featurePrefix': featurePrefix,