diff --git a/oxygen/js-options/hello.js b/oxygen/js-options/hello.js index 492777d..494789d 100644 --- a/oxygen/js-options/hello.js +++ b/oxygen/js-options/hello.js @@ -3,7 +3,7 @@ hello = function () { // Instanciation var options = new Options(authorAccess, 'hello', 10); - +/* // Set up a couple of options options.setOption('Hello', 'World'); options.setOption('See you later', 'aligator'); @@ -28,4 +28,4 @@ hello = function () { // Display some file specific properties Packages.java.lang.System.out.println('options.systemId: ' + options.systemId); Packages.java.lang.System.out.println('options.systemIdDigest: ' + options.systemIdDigest); -} \ No newline at end of file +*/} \ No newline at end of file diff --git a/oxygen/js-options/options.js b/oxygen/js-options/options.js index 3c8b814..23aa1a2 100644 --- a/oxygen/js-options/options.js +++ b/oxygen/js-options/options.js @@ -2,7 +2,7 @@ * Main features */ -Options = function (authorAccess, namespace, lifetime) { +Options = function (authorAccess, namespace, lifetime, __system__) { this.namespace = namespace; this.authorAccess = authorAccess; this.optionsStorage = this.authorAccess.getOptionsStorage(); @@ -10,10 +10,11 @@ Options = function (authorAccess, namespace, lifetime) { this.expiration = Options.getExpiration(lifetime); // Consider namespaces as a SYSTEM option - if (namespace != Options.SYSTEM) { - this.systemOptions = new Options(authorAccess, Options.SYSTEM); + if ( __system__ !== true ) { + this.systemOptions = new Options(authorAccess, Options.SYSTEM, null, true); var namespaces = JSON.parse(this.systemOptions.getOption(Options.NAMESPACES, '{}')); namespaces[ this.namespace] = this.expiration; + Packages.java.lang.System.out.println('Namespaces update for ' + this.namespace ); this.systemOptions.setOption(Options.NAMESPACES, JSON.stringify(namespaces)); this.__cleanup__(); } @@ -49,7 +50,7 @@ Options.prototype.setOption = function (key, value) { this.optionsStorage.setOption(key, value); } -Options.prototype.getOptionsKeys = function () { +Options.prototype.getOptionKeys = function () { this.optionsStorage.setOptionsDoctypePrefix(Options.SYSTEM); return JSON.parse(this.optionsStorage.getOption(this.namespace, '{}')); } @@ -57,7 +58,7 @@ Options.prototype.getOptionsKeys = function () { Options.prototype.getOptions = function () { var results = { }; - var options = this.getOptionsKeys(); + var options = this.getOptionKeys(); for (var key in options) { results[key] = this.getOption(key, ''); } @@ -155,12 +156,20 @@ Options.prototype.__cleanup__ = function () { Packages.java.lang.System.out.println('Time to clean !'); var namespaces = JSON.parse(this.systemOptions.getOption(Options.NAMESPACES, '{}')); for (var name in namespaces) { - this.__cleanupNamespace__(name, namespaces[name], currentDate); + this.__cleanupNamespace__(name, namespaces[name], currentDate); // TODO: return value to say if the NS needsto be deleted } } } } Options.prototype.__cleanupNamespace__ = function (name, expiration, currentDate) { - Packages.java.lang.System.out.println('Cleanup for ' + name) + Packages.java.lang.System.out.println('Cleanup for namespace ' + name + ' / ' + expiration); + var options = new Options(this.authorAccess, name, undefined, true); + var nsOptions = options.getOptionKeys(); + for (var key in nsOptions) { + var value = nsOptions[key]; + Packages.java.lang.System.out.println(' Cleanup for option ' + key + ' / ' + value); + } + + }