Skip to content

Commit

Permalink
Introduce Jsonix util
Browse files Browse the repository at this point in the history
  • Loading branch information
buehner committed Apr 16, 2019
1 parent 016f8a8 commit 9c4905e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 120 deletions.
5 changes: 0 additions & 5 deletions src/util/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
Ext.define('BasiGX.util.Filter', {

requires: 'BasiGX.util.SLD',

statics: {

/**
Expand Down Expand Up @@ -432,7 +430,4 @@ Ext.define('BasiGX.util.Filter', {
return spatialFilter;
}
}
}, function() {
BasiGX.util.SLD
.setStaticJsonixReferences(BasiGX.util.Filter);
});
80 changes: 80 additions & 0 deletions src/util/Jsonix.js
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
/**
* 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();
});
62 changes: 6 additions & 56 deletions src/util/SLD.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
},

/**
Expand All @@ -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;
Expand All @@ -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);
},

/**
Expand Down Expand Up @@ -280,7 +232,7 @@ Ext.define('BasiGX.util.SLD', {
filterContent
);
sldFilter.push(
BasiGX.util.SLD.marshaller.marshalString(sldFilterObj)
BasiGX.util.Jsonix.marshaller.marshalString(sldFilterObj)
);
}
});
Expand Down Expand Up @@ -814,6 +766,4 @@ Ext.define('BasiGX.util.SLD', {
return sldObj;
}
}
}, function() {
BasiGX.util.SLD.setStaticJsonixReferences();
});
62 changes: 6 additions & 56 deletions src/util/SldOpenlayersConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},

/**
Expand All @@ -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
);
Expand All @@ -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);
},

Expand Down Expand Up @@ -1019,6 +971,4 @@ Ext.define('BasiGX.util.SldOpenlayersConverter', {
}

}
}, function() {
BasiGX.util.SldOpenlayersConverter.setStaticJsonixReferences();
});
7 changes: 4 additions & 3 deletions src/util/WFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9c4905e

Please sign in to comment.