${expand(...)} editor variable
Are you missing a feature? Request its implementation here.
-
- Posts: 34
- Joined: Thu Nov 12, 2020 12:24 pm
${expand(...)} editor variable
Hi,
right now, oXygen allows to set user-defined editor variables in a
global or project-specific scope, e.g. ${myvar}. And it throws an
exception, when trying to access an editor variable, that was not
initialized (set). It would be cool, to have an editor variable (or a
function) that would try to get a variable by name and if that
variable was not initialized, a default value would be
returned. Having such a variable (or function) would greatly leverage
framework writing, because it would enable us to write parametrizable
author actions, thus more generic frameworks.
The thing I have in mind would be something like,
and would expand to the value of the variable called VARIABLE_NAME if
that variable is present, and to DEFAULT, if that variable is not
present.
An alternative improvement would be, to enable shipping variable
initialization along with a framework, while also allowing to override
such variables by setting them again (be it in a global or
project-specific way).
Could you imagine, adding such a feature? Or are there simple
alternatives?
Regards,
Chris
right now, oXygen allows to set user-defined editor variables in a
global or project-specific scope, e.g. ${myvar}. And it throws an
exception, when trying to access an editor variable, that was not
initialized (set). It would be cool, to have an editor variable (or a
function) that would try to get a variable by name and if that
variable was not initialized, a default value would be
returned. Having such a variable (or function) would greatly leverage
framework writing, because it would enable us to write parametrizable
author actions, thus more generic frameworks.
The thing I have in mind would be something like,
Code: Select all
${expand(VARIABLE_NAME, DEFAULT)}
that variable is present, and to DEFAULT, if that variable is not
present.
An alternative improvement would be, to enable shipping variable
initialization along with a framework, while also allowing to override
such variables by setting them again (be it in a global or
project-specific way).
Could you imagine, adding such a feature? Or are there simple
alternatives?
Regards,
Chris
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: ${expand(...)} editor variable
Hi Chris,
I added an internal issue to consider such an expand with fallback function:
EXM-49470 Editor variable function which provides a fallback if variable not defined
One thing which can be done is to use our API to provide your own editor variables expansion mechanism from a plugin.
For example this sample plugin for Oxygen provides a ${clipboard} editor variable expansion code via Javascript:
https://github.com/oxygenxml/wsaccess-j ... rVariables
Regards,
Radu
I added an internal issue to consider such an expand with fallback function:
EXM-49470 Editor variable function which provides a fallback if variable not defined
One thing which can be done is to use our API to provide your own editor variables expansion mechanism from a plugin.
For example this sample plugin for Oxygen provides a ${clipboard} editor variable expansion code via Javascript:
https://github.com/oxygenxml/wsaccess-j ... rVariables
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 34
- Joined: Thu Nov 12, 2020 12:24 pm
Re: ${expand(...)} editor variable
Hi Radu,
thanks for this hint! After few days now, I got used to reading oXygen's Java API.
I found, that I can use code like this for trying to access editor variables in custom author mode actions:
If the ${myvar} custom editor variable has not been initialized, it's name is returned by expandEditorVariables(). That's a bit weird (null or an Exception would be cleaner) but it works.
BTW: I do not use an custom EditorVariablesResolver, because the variable names are dynamically concatenated of prefixes and context read in the edited file.
Regrads,
Chris
thanks for this hint! After few days now, I got used to reading oXygen's Java API.
I found, that I can use code like this for trying to access editor variables in custom author mode actions:
Code: Select all
public class MyCustomOperation
implements AuthorOperation {
/* ... */
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws AuthorOperationException, IllegalArgumentException {
/* ... */
UtilAccess utilAccess = authorAccess.getUtilAccess();
String myvar = utilAccess.expandEditorVariables("${myvar}", null);
/* ... */
}
}
BTW: I do not use an custom EditorVariablesResolver, because the variable names are dynamically concatenated of prefixes and context read in the edited file.
Regrads,
Chris
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: ${expand(...)} editor variable
Hi Chris,
Right. The "expandEditorVariables" method can also be called on any string like "abc${someVar1}def${someVar2}" and it's not feasible for it to return null if it cannot resolve a single variable, it just leaves the variable as it is because it may not be an Oxygen editor variable at all, it may be some user defined string literal which looks like an editor variable.
Regards,
Radu
Right. The "expandEditorVariables" method can also be called on any string like "abc${someVar1}def${someVar2}" and it's not feasible for it to return null if it cannot resolve a single variable, it just leaves the variable as it is because it may not be an Oxygen editor variable at all, it may be some user defined string literal which looks like an editor variable.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service