2021-04-29 12:06:43 +00:00
# Options (Work in Progress)
2021-04-28 14:48:01 +00:00
This rambling shows how to add functionalities to the [OptionStorage ](https://www.oxygenxml.com/InstData/Editor/SDK/javadoc/ro/sync/ecss/extensions/api/OptionsStorage.html ) mechanism.
2021-04-28 13:12:30 +00:00
2021-04-29 12:06:43 +00:00
## Principle
The idea is to add metadata to be able to do some kind of introspection and cleanup the options store when/if needed.
## Usage [hello.js](hello.js)
Instanciation (with a namespace set to 'hello':
```javascript
var options = new Options(authorAccess, 'hello');
```
Setting options:
```javascript
var options = new Options(authorAccess, 'hello');
```
These values can then be retrieved using options.getOption(key, defaultValue) but also as an object:
```javascript
// Retrieve and display these options
var myOptions = options.getOptions();
for (var key in myOptions) {
var value = myOptions[key];
Packages.java.lang.System.out.println(key + ' ' + value);
}
```
Options can also be "per file" using methods containing the "SystemId" keyword in their names:
```javascript
// Do the same with file specific options
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);
}
```
By default, the systemId is the current file system Id but it could be set up to any other file using the setSystemId() method.
Internally, "per file" properties are stored in a namespace which is the concatenation of the options namespace and the SHA1 of the systemId
(such as "hello.1D4E43D67658FA9C7F17B230DB629D9DE3FA8001").
2021-04-28 13:12:30 +00:00
## Installation
## See also
More details on these hacks:
* [debugger ](../js-debugger )
* [inclusion ](../js-include )
# Framework
This directory includes the Oxygen sample framework on which ou can test these techniques but they should work on any framework.