js-options: per file methods

This commit is contained in:
Eric van der Vlist 2021-04-29 12:04:41 +02:00
parent b7bdb2ef27
commit 03794da2ba
2 changed files with 42 additions and 7 deletions

View File

@ -8,7 +8,13 @@ hello = function () {
var value = myOptions[key];
Packages.java.lang.System.out.println(key + ' ' + value);
}
options.setSystemId();
options.setSystemIdOption('Hello', 'aligator');
options.setSystemIdOption('See you later', 'World');
var myOptions = options.getSystemIdOptions();
for (var key in myOptions) {
var value = myOptions[key];
Packages.java.lang.System.out.println(key + ' ' + value);
}
Packages.java.lang.System.out.println('options.systemId: ' + options.systemId);
Packages.java.lang.System.out.println('options.systemIdDigest: ' + options.systemIdDigest);
}

View File

@ -17,7 +17,6 @@ Options = function (authorAccess, namespace) {
Options.SYSTEM = '__system__';
Options.NAMESPACES = '__namespaces__';
Options.SYSTEMIDS = '__systemIds__';
Options.prototype.getOption = function (key, defaultValue) {
this.optionsStorage.setOptionsDoctypePrefix(this.namespace);
@ -47,8 +46,17 @@ Options.prototype.getOptions = function () {
/*
* Per file extensions
*
* Setting a systemID creates a new namespace that concatenates the current namespace
* and the SHA1 of the document ID.
*
* Access to the options of this namespace is done through specific methods.
*
* The reverse mapping (SHA1 to system ID) is stored using the __systemIds__ namespace.
*
*/
Options.SYSTEMIDS = '__systemIds__';
Options.prototype.setSystemId = function (systemID) {
if (systemID === undefined) {
this.systemId = String(this.authorAccess.getDocumentController().getAuthorDocumentNode().getSystemID());
@ -64,5 +72,26 @@ Options.prototype.setSystemId = function(systemID) {
systemId: this.systemId
}
this.systemOptions.setOption(Options.SYSTEMIDS, JSON.stringify(systemIds));
this.systemIdOptions = new Options(this.authorAccess, this.namespace + '.' + this.systemIdDigest);
}
Options.prototype.setSystemIdOption = function (key, value) {
if (this.systemIdOptions === undefined) {
this.setSystemId();
}
this.systemIdOptions.setOption(key, value);
}
Options.prototype.getSystemIdOption = function (key, defaultValue) {
if (this.systemIdOptions === undefined) {
this.setSystemId();
}
return this.systemIdOptions.getOption(key, defaultValue);
}
Options.prototype.getSystemIdOptions = function () {
if (this.systemIdOptions === undefined) {
this.setSystemId();
}
return this.systemIdOptions.getOptions();
}