diff --git a/src/util/Filter.js b/src/util/Filter.js index 8502dce0c..2bd1117fe 100644 --- a/src/util/Filter.js +++ b/src/util/Filter.js @@ -21,8 +21,6 @@ */ Ext.define('BasiGX.util.Filter', { - requires: 'BasiGX.util.SLD', - statics: { /** @@ -432,7 +430,4 @@ Ext.define('BasiGX.util.Filter', { return spatialFilter; } } -}, function() { - BasiGX.util.SLD - .setStaticJsonixReferences(BasiGX.util.Filter); }); diff --git a/src/util/Jsonix.js b/src/util/Jsonix.js new file mode 100644 index 000000000..37d9451cf --- /dev/null +++ b/src/util/Jsonix.js @@ -0,0 +1,80 @@ +/* Copyright (c) 2016-present terrestris GmbH & Co. KG + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +/** + * Common utility class containing static methods for determination, + * initialization and storing of Jsonix components. + * + * @class BasiGX.util.Jsonix + */ +Ext.define('BasiGX.util.Jsonix', { + inheritableStatics: { + jsonixContext: null, + marshaller: null, + unmarshaller: null, + possibleGlobals: [ + 'Jsonix', + 'Filter_1_0_0', + 'SLD_1_0_0', + 'SMIL_2_0', + 'SMIL_2_0_Language', + 'GML_2_1_2', + 'GML_3_1_1', + 'XLink_1_0', + 'WPS_1_0_0', + 'OWS_1_1_0', + 'WCS_1_1' + ], + /** + * Create instances of Jsonix classes and make them accessible as static + * properties. + * + */ + setStaticJsonixReferences: function() { + var staticMe = BasiGX.util.Jsonix; + var availableGlobals = []; + Ext.each(staticMe.possibleGlobals, function(possible) { + if (!(possible in window)) { + Ext.Logger.warn('Possible global variable "' + possible + '"' + + ' not found. This functionality will not be available!'); + } else { + availableGlobals.push(window[possible]); + } + }); + // create the objects… + var context = new Jsonix.Context( + availableGlobals, { + namespacePrefixes: { + 'http://www.opengis.net/sld': 'sld', + "http://www.opengis.net/ogc": "ogc", + "http://www.opengis.net/gml": "gml", + "http://www.w3.org/2001/XMLSchema-instance": "xsi", + "http://www.w3.org/1999/xlink": "xlink", + "http://www.opengis.net/ows/1.1": "ows", + "http://www.opengis.net/wps/1.0.0": "wps", + "http://www.opengis.net/wcs/1.1.1": "wcs" + } + }); + var marshaller = context.createMarshaller(); + var unmarshaller = context.createUnmarshaller(); + // … and store them in the static variables. + staticMe.jsonixContext = context; + staticMe.marshaller = marshaller; + staticMe.unmarshaller = unmarshaller; + } + } +}, function() { + BasiGX.util.Jsonix.setStaticJsonixReferences(); +}); diff --git a/src/util/SLD.js b/src/util/SLD.js index f35aa6e9d..713b67641 100644 --- a/src/util/SLD.js +++ b/src/util/SLD.js @@ -26,19 +26,10 @@ Ext.define('BasiGX.util.SLD', { requires: [ 'Ext.String', + 'BasiGX.util.Jsonix', 'BasiGX.util.Object' ], statics: { - jsonixContext: null, - marshaller: null, - unmarshaller: null, - neededGlobals: [ - 'Jsonix', - 'SLD_1_0_0', - 'Filter_1_0_0', - 'GML_2_1_2', - 'XLink_1_0' - ], DEFAULT_STROKE_OPACITY: '1', DEFAULT_STROKE_COLOR: '#000000', DEFAULT_STROKE_WIDTH: '1', @@ -66,49 +57,10 @@ Ext.define('BasiGX.util.SLD', { DEFAULT_LABEL_FOLLOW_LINE: 'false', /** - * Method cares about the inital setup and checks if Jsonix is - * configured correctly + * */ setStaticJsonixReferences: function() { - var staticMe = BasiGX.util.SLD; - var foundCnt = 0; - Ext.each(staticMe.neededGlobals, function(needed) { - if (needed in window) { - foundCnt += 1; - } else { - Ext.log.error('Required global variable "' + needed + '"' + - ' not found. Are Jsonix needed mappings loaded?'); - } - }); - if (foundCnt !== staticMe.neededGlobals.length) { - var msg = 'This function is not functional as its' + - ' requirements weren\'t met.'; - staticMe.toSldObject = function() { - Ext.log.error(msg); - }; - staticMe.toSldString = function() { - Ext.log.error(msg); - }; - return; - } - // create the objects… - var context = new Jsonix.Context([ - SLD_1_0_0, Filter_1_0_0, GML_2_1_2, XLink_1_0 - ], { - namespacePrefixes: { - 'http://www.opengis.net/sld': 'sld', - 'http://www.opengis.net/ogc': 'ogc', - 'http://www.opengis.net/gml': 'gml', - 'http://www.w3.org/2001/XMLSchema-instance': 'xsi', - 'http://www.w3.org/1999/xlink': 'xlink' - } - }); - var marshaller = context.createMarshaller(); - var unmarshaller = context.createUnmarshaller(); - // … and store them in the static variables. - staticMe.jsonixContext = context; - staticMe.marshaller = marshaller; - staticMe.unmarshaller = unmarshaller; + // empty stub to obtain backwards compatability }, /** @@ -120,7 +72,7 @@ Ext.define('BasiGX.util.SLD', { */ toSldObject: function(sldStr) { try { - return BasiGX.util.SLD.unmarshaller.unmarshalString(sldStr); + return BasiGX.util.Jsonix.unmarshaller.unmarshalString(sldStr); } catch (e) { Ext.log.warn('Could not unmarshal the SLD string!'); return null; @@ -135,7 +87,7 @@ Ext.define('BasiGX.util.SLD', { * @param {Object} sldObject The SLD object to transform. */ toSldString: function(sldObject) { - return BasiGX.util.SLD.marshaller.marshalString(sldObject); + return BasiGX.util.Jsonix.marshaller.marshalString(sldObject); }, /** @@ -280,7 +232,7 @@ Ext.define('BasiGX.util.SLD', { filterContent ); sldFilter.push( - BasiGX.util.SLD.marshaller.marshalString(sldFilterObj) + BasiGX.util.Jsonix.marshaller.marshalString(sldFilterObj) ); } }); @@ -814,6 +766,4 @@ Ext.define('BasiGX.util.SLD', { return sldObj; } } -}, function() { - BasiGX.util.SLD.setStaticJsonixReferences(); }); diff --git a/src/util/SldOpenlayersConverter.js b/src/util/SldOpenlayersConverter.js index 1c22d7711..d40fc58a8 100644 --- a/src/util/SldOpenlayersConverter.js +++ b/src/util/SldOpenlayersConverter.js @@ -19,68 +19,20 @@ * @class BasiGX.util.SldOpenlayersConverter */ Ext.define('BasiGX.util.SldOpenlayersConverter', { + requires: [ + 'BasiGX.util.Jsonix' + ], statics: { - jsonixContext: null, - marshaller: null, - unmarshaller: null, - neededGlobals: [ - 'Jsonix', - 'SLD_1_0_0', - 'Filter_1_0_0', - 'GML_2_1_2', - 'XLink_1_0' - ], DEFAULT_STROKE_OPACITY: 1, DEFAULT_STROKE_COLOR: '#000000', DEFAULT_STROKE_WIDTH: 0, - DEFAULT_FILL_OPACITY: 1, /** * */ setStaticJsonixReferences: function() { - var staticMe = BasiGX.util.SldOpenlayersConverter; - var foundCnt = 0; - Ext.each(staticMe.neededGlobals, function(needed) { - if (needed in window) { - foundCnt += 1; - } else { - Ext.log.error( - 'Required global variable \'' + needed + '\'' + - ' not found. Are Jsonix needed mappings loaded?' - ); - } - }); - if (foundCnt !== staticMe.neededGlobals.length) { - var msg = 'This function is not functional as its' + - ' requirements weren\'t met.'; - staticMe.toSldObject = function() { - Ext.log.error(msg); - }; - staticMe.toSldObject = function() { - Ext.log.error(msg); - }; - return; - } - // create the objects… - var context = new Jsonix.Context([ - SLD_1_0_0, Filter_1_0_0, GML_2_1_2, XLink_1_0 - ], { - namespacePrefixes: { - 'http://www.opengis.net/sld': 'sld', - 'http://www.opengis.net/ogc': 'ogc', - 'http://www.opengis.net/gml': 'gml', - 'http://www.w3.org/2001/XMLSchema-instance': 'xsi', - 'http://www.w3.org/1999/xlink': 'xlink' - } - }); - var marshaller = context.createMarshaller(); - var unmarshaller = context.createUnmarshaller(); - // … and store them in the static variables. - staticMe.jsonixContext = context; - staticMe.marshaller = marshaller; - staticMe.unmarshaller = unmarshaller; + // empty stub to obtain backwards compatability }, /** @@ -98,7 +50,7 @@ Ext.define('BasiGX.util.SldOpenlayersConverter', { */ toSldObject: function(sldStr) { try { - var util = BasiGX.util.SldOpenlayersConverter; + var util = BasiGX.util.Jsonix; return util.unmarshaller.unmarshalString( sldStr ); @@ -117,7 +69,7 @@ Ext.define('BasiGX.util.SldOpenlayersConverter', { delete sldObject.value.namedLayerOrUserLayer[0] .namedStyleOrUserStyle[0].isDefault; } - var util = BasiGX.util.SldOpenlayersConverter; + var util = BasiGX.util.Jsonix; return util.marshaller.marshalString(sldObject); }, @@ -1019,6 +971,4 @@ Ext.define('BasiGX.util.SldOpenlayersConverter', { } } -}, function() { - BasiGX.util.SldOpenlayersConverter.setStaticJsonixReferences(); }); diff --git a/src/util/WFS.js b/src/util/WFS.js index 7b7be8fe5..c1aac286c 100644 --- a/src/util/WFS.js +++ b/src/util/WFS.js @@ -23,7 +23,8 @@ Ext.define('BasiGX.util.WFS', { requires: [ 'BasiGX.util.CSRF', 'BasiGX.util.Url', - 'BasiGX.util.Filter' + 'BasiGX.util.Filter', + 'BasiGX.util.Jsonix' ], inheritableStatics: { @@ -556,8 +557,8 @@ Ext.define('BasiGX.util.WFS', { */ handleWfsExecuteException: function(response) { var staticMe = BasiGX.util.WFS; - var filterUtil = BasiGX.util.Filter; - var parsedXml = filterUtil.unmarshaller.unmarshalString(response); + var util = BasiGX.util.Jsonix; + var parsedXml = util.unmarshaller.unmarshalString(response); if (parsedXml && parsedXml.value && parsedXml.value.exception[0]) { var excReport = parsedXml.value.exception[0]; var excCode = excReport.exceptionCode;