From: miker Date: Wed, 1 Jun 2005 20:14:49 +0000 (+0000) Subject: first stab at an XSLT to convert the xml fieldmapper config into a pile of javascript X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=913348883fc7120be3ce4fda53c237703c3761db;p=working%2FOpenSRF.git first stab at an XSLT to convert the xml fieldmapper config into a pile of javascript git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@313 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/examples/fieldmapper2javascript.xsl b/examples/fieldmapper2javascript.xsl new file mode 100644 index 0000000..ec18e7a --- /dev/null +++ b/examples/fieldmapper2javascript.xsl @@ -0,0 +1,266 @@ + + + + + + +// support functions + +var IE = false; +var unit_test = false; + +function instanceOf(object, constructorFunction) { + if(!IE) { + while (object != null) { + if (object == constructorFunction.prototype) + return true; + object = object.__proto__; + } + } else { + while(object != null) { + if( object instanceof constructorFunction ) + return true; + object = object.__proto__; + } + } + return false; +} + +// Top level superclass +function Fieldmapper(array) { + this.array = []; + if(array) { + if (array.constructor == Array) { + this.array = array; + } else if ( instanceOf( array, String ) || instanceOf( array, Number ) ) { + + var obj = null; + if (this.cacheable) { + try { + obj = this.baseClass.obj_cache[this.classname][array]; + } catch (E) {}; + } + + if (!obj) { + obj = user_request( + 'open-ils.proxy', + 'open-ils.proxy.proxy', + [ + mw.G.auth_ses[0], + 'open-ils.storage', + 'open-ils.storage.direct.' + this.db_type + '.retrieve', + array + ] + )[0]; + + if (this.cacheable) { + if (this.baseClass.obj_cache[this.classname] == null) + this.baseClass.obj_cache[this.classname] = {}; + + this.baseClass.obj_cache[this.classname][obj.id()] = obj; + } + } + this.array = obj.array; + + } else { + throw new FieldmapperException( "Attempt to build fieldmapper object with something wierd"); + } + } +} +Fieldmapper.prototype.baseClass = Fieldmapper; +Fieldmapper.prototype.obj_cache = {}; + +Fieldmapper.prototype.clone = function() { + var obj = new this.constructor(); + + for( var i in this.array ) { + var thing = this.array[i]; + if(thing == null) continue; + + if( thing._isfieldmapper ) { + obj.array[i] = thing.clone(); + } else { + + if(instanceOf(thing, Array)) { + obj.array[i] = new Array(); + + for( var j in thing ) { + + if( thing[j]._isfieldmapper ) + obj.array[i][j] = thing[j].clone(); + else + obj.array[i][j] = thing[j]; + } + } else { + obj.array[i] = thing; + } + } + } + return obj; +} + +function FieldmapperException(message) { + this.message = message; +} + +FieldmapperException.toString = function() { + return "FieldmapperException: " + this.message + "\n"; + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// accessor for : +.prototype. = function () { + + var _pos = .last_real_field + ; + + if (!instanceOf(this.array[_pos], Array)) { + this.array[_pos] = []; + + if (this.array[_pos].length == 0) { + /* get the real thing. + * search where .() + * equals this.(); + */ + } + + return this.array[_pos]; +} + + + + + + + + + +// Class definition for "" + +function (array) { + + if (!instanceOf(this, )) + return new (array); + + this.baseClass.call(this,array); + this.classname = ""; + this._isfieldmapper = true; + this.uber = .baseClass.prototype; +} + +.prototype = new Fieldmapper(); +.prototype.constructor = ; +.baseClass = Fieldmapper; +.prototype.cachable = true; +.prototype.fields = []; +.last_real_field = 2; + + +.prototype.db_type = ""; + +.prototype.isnew = function(new_value) { + if(arguments.length == 1) { this.array[0] = new_value; } + return this.array[0]; +} + +.prototype.ischanged = function(new_value) { + if(arguments.length == 1) { this.array[1] = new_value; } + return this.array[1]; +} + +.prototype.isdeleted = function(new_value) { + if(arguments.length == 1) { this.array[2] = new_value; } + return this.array[2]; +} + + + + + + + + + + + + + + +// Accessor/mutator for .: +.last_real_field++; +.prototype.fields.push(""); +.prototype. = function (new_value) { + + + + + + if(arguments.length == 1) { this.array[] = new_value; } + var val = this.array[]; + + if (!instanceOf(this.array[], )) { + if (this.array[] != null) { + this.array[] = new (val); + } + } + + return this.array[]; + + + + if(arguments.length == 1) { this.array[] = new_value; } + return this.array[]; + + +} + + + +