js-options: per file methods
This commit is contained in:
parent
b7bdb2ef27
commit
03794da2ba
|
@ -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);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Main features
|
||||
*/
|
||||
|
||||
|
@ -10,14 +10,13 @@ Options = function (authorAccess, namespace) {
|
|||
if (namespace != Options.SYSTEM) {
|
||||
this.systemOptions = new Options(authorAccess, Options.SYSTEM);
|
||||
var namespaces = JSON.parse(this.systemOptions.getOption(Options.NAMESPACES, '{}'));
|
||||
namespaces[this.namespace] = (new Date()).toISOString();
|
||||
namespaces[ this.namespace] = (new Date()).toISOString();
|
||||
this.systemOptions.setOption(Options.NAMESPACES, JSON.stringify(namespaces))
|
||||
}
|
||||
}
|
||||
|
||||
Options.SYSTEM = '__system__';
|
||||
Options.NAMESPACES = '__namespaces__';
|
||||
Options.SYSTEMIDS = '__systemIds__';
|
||||
|
||||
Options.prototype.getOption = function (key, defaultValue) {
|
||||
this.optionsStorage.setOptionsDoctypePrefix(this.namespace);
|
||||
|
@ -44,12 +43,21 @@ Options.prototype.getOptions = function () {
|
|||
return results;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* 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.prototype.setSystemId = function(systemID) {
|
||||
Options.SYSTEMIDS = '__systemIds__';
|
||||
|
||||
Options.prototype.setSystemId = function (systemID) {
|
||||
if (systemID === undefined) {
|
||||
this.systemId = String(this.authorAccess.getDocumentController().getAuthorDocumentNode().getSystemID());
|
||||
} else {
|
||||
|
@ -59,10 +67,31 @@ Options.prototype.setSystemId = function(systemID) {
|
|||
var digestBytes = md.digest(java.lang.String(this.systemId).getBytes(java.nio.charset.Charset.forName("UTF-8")));
|
||||
this.systemIdDigest = javax.xml.bind.DatatypeConverter.printHexBinary(digestBytes);
|
||||
var systemIds = JSON.parse(this.systemOptions.getOption(Options.SYSTEMIDS, '{}'));
|
||||
systemIds[this.systemIdDigest] = {
|
||||
systemIds[ this.systemIdDigest] = {
|
||||
date: (new Date()).toISOString(),
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue