All About Editor Variables
In various places in the Oxygen XML Editor application there is support for expanding variables. These variables/macros usually take the form ${variableName} and are expanded by the application dynamically when necessary. A list with all supported editor variables can be found in the user's manual: https://www.oxygenxml.com/doc/ug-editor/topics/editor-variables.html. I will enumerate below all major contexts in which using such editor variables may prove useful:
Transformation Scenarios
- XML with XSLT based transformation scenario types
- If you edit such a scenario and go to the Output tab you can
specify the Save as field to use editor variables
like this
${cfd}/${cfn}.html
which will get expanded to use the current XML document folder and file name but with a different extension when the output of the transformation gets saved on disk. You can also use editor variables like ${date()} to save the output file name using the current date:${cfd}/${cfn}-${date(yyyy-MM-dd)}.html
.
- ANT based transformation scenario types
- In the Parameters tab you can add new parameters which will be passed to the ANT build file. Values for such parameters can also contain editor variables. You can add for example a parameter called currentXMLDocument with value ${pd}/specificFileName.xml if you want a path to a specific XML file in the current XML project to be passed to the ANT build file as a variable. Again you can use ${ask()} editor variable which will end up requesting the value from the end user when the transformation is started.
- DITA Open Toolkit transformation scenario types
- DITA Open Toolkit transformation scenarios are based on ANT so the
previous tips apply. In addition you can use the ${rootMapFile}
related editor variables which gets expanded to the current root map.
For example in the Filters tab I can specify the reference to the
DITAVAL file like this:
${rootMapDir}/filter.ditaval
to refer to the filter relative to the folder where the current root map is published.
New File Templates
You can create your own new file templates and have them use when the Oxygen XML Editor File->New dialog wizard is used to create new documents: Sharing New Custom File Templates for a Specific Vocabulary.
<topic id="topic_${id}">
<title>${caret}</title>
<prolog>
<author>${ask('Author Name?', generic, 'default')}</author>
</prolog>
<body>
<p></p>
</body>
</topic>
makes
use of multiple editor variables:- The ${id} editor variable expands to an unique short ID value containing alphanumerical characters. You can also use the ${uuid} editor variable to generate a truly unique but longer ID value.
- The ${caret} editor variable marks the position where the caret will be placed after the XML document created from the new file template is initially opened.
- The ${ask} editor variable will ask the end user to provide the name of the author and will get expanded in the XML content. You can also use ${answer} editor variables to use the same answer to the ${ask} editor variable in multiple places.
Code Templates
- You can use the ${selection} editor variable to surround the current
selected content in the main editing area inside the code
template:
<em>${selection}</em>
- The ${caret} editor variable allows you to precisely choose a place
for the caret after the code template is
inserted:
In the example above the caret will be placed after the inserted element when the code template is chosen.<ph keyref="oxygen"/>${caret}
- The ${ask} editor variable will trigger the application to ask for a
value to insert in a particular place of the code
template:
In the example above when the code template is chosen, the end user will need to choose the reason in a dialog showing a combo box of possible choices and the chosen reason will be expanded in the code template before being inserted in the XML content.<problem reason="${ask('Reason?', radio, ('lost':'lost';'illegible':'illegible';'omitted':'omitted';), 'lost')}"/>
Custom Author Actions
Oxygen XML Editor framework configurations allow defining custom actions for the Author visual editing mode and then contributing these actions to framework-specific toolbars and menus. An example of implementing such a custom action can be found here: Implementing a Custom Author Action to Split a Table.
In some of the default operations that you can use in a custom Author action (for example in the InsertFragmentOperation) you can use editor variables.
External Tools
You can run external command line scripts from Oxygen XML Editor by configuring external tools in the Preferences page. The defined external tools allow using editor variables like ${pd} to access the current project folder and the editor variables will be automatically expanded before the external tool is invoked.
Custom Editor Variables
You can define your custom editor variables in the application Custom Editor Variables preferences page. A custom editor variable can contain as values other editor variables and can be used in all places where a predefined editor variable is.
You can use Oxygen XML Editor's API to provide custom editor variables and their expanded values using custom Java or Javascript code. For example this plugin adds support for a new ${clipboard} editor variable.