From b7bdb2ef27e9bc59a1e360c9bd51147e9b03bbe6 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Thu, 29 Apr 2021 11:32:07 +0200 Subject: [PATCH] js-options: setSystemId method --- oxygen/js-options/hello.js | 3 +++ oxygen/js-options/options.js | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/oxygen/js-options/hello.js b/oxygen/js-options/hello.js index fe69e43..1558e92 100644 --- a/oxygen/js-options/hello.js +++ b/oxygen/js-options/hello.js @@ -8,4 +8,7 @@ hello = function () { var value = myOptions[key]; Packages.java.lang.System.out.println(key + ' ' + value); } + options.setSystemId(); + 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 diff --git a/oxygen/js-options/options.js b/oxygen/js-options/options.js index 59e276f..63706cf 100644 --- a/oxygen/js-options/options.js +++ b/oxygen/js-options/options.js @@ -6,16 +6,18 @@ Options = function (authorAccess, namespace) { this.namespace = namespace; this.authorAccess = authorAccess; this.optionsStorage = this.authorAccess.getOptionsStorage(); + // Consider namespaces as a SYSTEM option if (namespace != Options.SYSTEM) { - var systemOptions = new Options(authorAccess, Options.SYSTEM); - var namespaces = JSON.parse(systemOptions.getOption(Options.NAMESPACES, '{}')); + this.systemOptions = new Options(authorAccess, Options.SYSTEM); + var namespaces = JSON.parse(this.systemOptions.getOption(Options.NAMESPACES, '{}')); namespaces[this.namespace] = (new Date()).toISOString(); - systemOptions.setOption(Options.NAMESPACES, JSON.stringify(namespaces)) + 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); @@ -49,9 +51,18 @@ Options.prototype.getOptions = function () { Options.prototype.setSystemId = function(systemID) { if (systemID === undefined) { - this.systemID = this.authorAccess.getDocumentController().getAuthorDocumentNode().getSystemID(); + this.systemId = String(this.authorAccess.getDocumentController().getAuthorDocumentNode().getSystemID()); } else { - this.systemID = systemID; + this.systemId = String(systemID); } + var md = java.security.MessageDigest.getInstance("SHA-1"); + 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] = { + date: (new Date()).toISOString(), + systemId: this.systemId + } + this.systemOptions.setOption(Options.SYSTEMIDS, JSON.stringify(systemIds)); }