Adding xsl-transformation to custom framework
Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Adding xsl-transformation to custom framework
Hi,
I've created a custom framewirk with xsd and css to edit some configuration files in Web Author (currently 21.1).
Since the format is not exactly what we need, I'd like to create an xslt transformation. For now the result will just need to be displayed or (even better) copied to the clipboard, so we can paste it into the target system.
Could you give me some hints for how to achieve this? Creating a transformation scenario (As I woul din th desktop version), extend my custom framework or do I need to implement a plugin with java?
Thanks and regards,
Patrik
I've created a custom framewirk with xsd and css to edit some configuration files in Web Author (currently 21.1).
Since the format is not exactly what we need, I'd like to create an xslt transformation. For now the result will just need to be displayed or (even better) copied to the clipboard, so we can paste it into the target system.
Could you give me some hints for how to achieve this? Creating a transformation scenario (As I woul din th desktop version), extend my custom framework or do I need to implement a plugin with java?
Thanks and regards,
Patrik
-
- Posts: 495
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Adding xsl-transformation to custom framework
Post by cristi_talau »
Hello,
You need to implement a plugin for this functionality. You can use as a starting point this sample plugin that runs an XSLT script and prints the result in the browser console.
Best,
Cristian
You need to implement a plugin for this functionality. You can use as a starting point this sample plugin that runs an XSLT script and prints the result in the browser console.
Best,
Cristian
Re: Adding xsl-transformation to custom framework
Hi Christian,
thanks for the hint. So what I achievd so far is:
I created a file web/framework.js in my framework. But actually I don't even know if my code is actually being executed.
I tried to just create some logging output:
But I could not find the text anywhere in the logs folder.
Could you please give me some advice on how to start some kind of interaction with my source code?
Thanks and regards,
Patrik
thanks for the hint. So what I achievd so far is:
- setting up my local webauthor
- creating a custom framework with xsd and css
- compiling my own plugin as java code based on you sample web-author-xslt-report
- add it as plugin to my web author
I created a file web/framework.js in my framework. But actually I don't even know if my code is actually being executed.
I tried to just create some logging output:
Code: Select all
goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
console.log('Patrik-Test1');
});
Could you please give me some advice on how to start some kind of interaction with my source code?
Thanks and regards,
Patrik
Re: Adding xsl-transformation to custom framework
I realized that the javascript code is executed in the browser - not the server. And after opening the browser console I also found my logging output. So for now I have no further questions...
Regards,
Patrik
Regards,
Patrik
Re: Adding xsl-transformation to custom framework
Hi again,
I managed to transform the document and display it in a dialog to the user.
Now I'd like to add two checks before the transformation:
Thanks and regards,
Patrik
I managed to transform the document and display it in a dialog to the user.
Now I'd like to add two checks before the transformation:
- Ensure the current document is not modified (i.e. the changes were commited)
I tried to call editorAccess.isModified() in the java code but this does not work. I get this error:
And I was also surprised that the error text being passed to my callback after completing ActionsManager.invokeOperation() is null when I threw an exception. How can I signal my javascript code that the java operation failed?Calling isModified() is not supported while a "compound edit" is in progress. - Ensure the current document is valid.
I've added an xsd with embedded schematron checks to the document type and the validations works fine. I just want to check the result.
Thanks and regards,
Patrik
-
- Posts: 495
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Adding xsl-transformation to custom framework
Post by cristi_talau »
Hello,
To check if a document is modified, you can use either the JS API: editor.isDirty [1] or, if you use the Java API inside an AuthorOperation you need to make it implement the AuthorOperationWithCustomUndoBehavior and call the .isModified() method.
Regarding the validation status, I created a small plugin that blocks saving a document if not valid. Maybe it can give you some inspiration: https://github.com/oxygenxml/web-author ... if-invalid .
Best,
Cristian
[1] https://www.oxygenxml.com/maven/com/oxy ... ml#isDirty
To check if a document is modified, you can use either the JS API: editor.isDirty [1] or, if you use the Java API inside an AuthorOperation you need to make it implement the AuthorOperationWithCustomUndoBehavior and call the .isModified() method.
Regarding the validation status, I created a small plugin that blocks saving a document if not valid. Maybe it can give you some inspiration: https://github.com/oxygenxml/web-author ... if-invalid .
Best,
Cristian
[1] https://www.oxygenxml.com/maven/com/oxy ... ml#isDirty
Re: Adding xsl-transformation to custom framework
Hi Christian,
thanks for the hints. Adding a check for isDirty() was indeed very simple.
But I still struggle with the validation status:
Using the plugin you suggested seemed to have no effect when commiting the file to an on-premise git repository. I'd assume that the commit would trigger the same listeners as saving a file, right?
I'm sure the file is read because I get error messages when writing bad code. But I could not get any output:
I also failed to check for the validation status within my javascript for the custom action. I'm aware of having access to sync.api.Editor and sync.api.Workspace. But in the documentation I could not find any way to access the AuthorDocumentModel from there.
I'd appreciate some more guidance.
Thanks and regards,
Patrik
thanks for the hints. Adding a check for isDirty() was indeed very simple.
But I still struggle with the validation status:
Using the plugin you suggested seemed to have no effect when commiting the file to an on-premise git repository. I'd assume that the commit would trigger the same listeners as saving a file, right?
I'm sure the file is read because I get error messages when writing bad code. But I could not get any output:
Code: Select all
editorAboutToBeSavedVeto: function () {
console.log("editorAboutToBeSavedVeto");
workspaceAccess.showErrorMessage("editorAboutToBeSavedVeto");
}
I'd appreciate some more guidance.
Thanks and regards,
Patrik
-
- Posts: 495
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Adding xsl-transformation to custom framework
Post by cristi_talau »
Hello,
The Commit action for Git is different from the "Save". To add some code before it you can use the following JS code:
Best,
Cristian
The Commit action for Git is different from the "Save". To add some code before it you can use the following JS code:
Code: Select all
goog.events.listenOnce(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
var editor = e.editor;
goog.events.listenOnce(e.editor, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
var commitAction = editor.getActionsManager().getActionById('Git/Commit');
var oldActionPerformed = commitAction.actionPerformed;
commitAction.actionPefrormed = function(callback) {
// ... YOUR CODE HERE
oldActionPerformed.call(commitAction, callback);
};
});
});
Cristian
Re: Adding xsl-transformation to custom framework
Hi Christian,
thanks, but it still doesn't work. I added this code to my framework.js:
In the console I ensured that sync.api.Workspace.EventType.EDITOR_LOADED and sync.api.Workspace.EventType.ACTIONS_LOADED were triggered.
But on commit I get no additional output on the console - so my code wasn't executed.
And even if it was executed I still don't know how to access the AuthorDocumentModel .
Regards,
Patrik
thanks, but it still doesn't work. I added this code to my framework.js:
Code: Select all
goog.events.listenOnce(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
console.log("sync.api.Workspace.EventType.EDITOR_LOADED");
var editor = e.editor;
goog.events.listenOnce(e.editor, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
console.log("sync.api.Workspace.EventType.ACTIONS_LOADED");
var commitAction = editor.getActionsManager().getActionById('Git/Commit');
console.log("commitAction: " + commitAction);
var oldActionPerformed = commitAction.actionPerformed;
commitAction.actionPefrormed = function(callback) {
console.log("before Git/Commit");
oldActionPerformed.call(commitAction, callback);
console.log("after Git/Commit");
};
});
});
But on commit I get no additional output on the console - so my code wasn't executed.
And even if it was executed I still don't know how to access the AuthorDocumentModel .
Regards,
Patrik
-
- Posts: 495
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Adding xsl-transformation to custom framework
Post by cristi_talau »
Hello,
The code was intended to be used in a plugin. In a framework you can use the "editorCreated" callback in your extension implementation [1]. There you get a handle on an editor. With that you can listen for ACTIONS_LOADED event and patch the "Commit" action.
Also, note that the Commit action is asynchronous - to write a console.log after its execution you should use its callback argument.
Best,
Cristian
[1] https://www.oxygenxml.com/maven/com/oxy ... nsion.html
The code was intended to be used in a plugin. In a framework you can use the "editorCreated" callback in your extension implementation [1]. There you get a handle on an editor. With that you can listen for ACTIONS_LOADED event and patch the "Commit" action.
Also, note that the Commit action is asynchronous - to write a console.log after its execution you should use its callback argument.
Best,
Cristian
[1] https://www.oxygenxml.com/maven/com/oxy ... nsion.html
Re: Adding xsl-transformation to custom framework
Hi again,
I found and fixed a typo in your code: commitAction.actionPefrormed = function(callback)
Now I get the colsole output - by placing the code in a plugin and also by placing the code in a framework.
However, I still don't now, how to get access to the DocumentValidator. Your sample plugin uses the authorDocumentModel which is passed as parameter to the callback function - so I can't use this method!?
Regards,
Patrik
I found and fixed a typo in your code: commitAction.actionPefrormed = function(callback)
Now I get the colsole output - by placing the code in a plugin and also by placing the code in a framework.
However, I still don't now, how to get access to the DocumentValidator. Your sample plugin uses the authorDocumentModel which is passed as parameter to the callback function - so I can't use this method!?
Regards,
Patrik
-
- Posts: 495
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Adding xsl-transformation to custom framework
Post by cristi_talau »
Hello,
The sample plugin runs the JS code on the server. The simplest way to query the validation status is to use an AuthorOperationWithResult. We have a tutorial on how to use one here [1].
Best,
Cristian
[1] https://www.oxygenxml.com/maven/com/oxy ... esult.html
The sample plugin runs the JS code on the server. The simplest way to query the validation status is to use an AuthorOperationWithResult. We have a tutorial on how to use one here [1].
Best,
Cristian
[1] https://www.oxygenxml.com/maven/com/oxy ... esult.html
Re: Adding xsl-transformation to custom framework
Hi again,
thanks, now I could make it work.
Java class in my plugin:
javascript code in my framework:
Regards,
Patrik
thanks, now I could make it work.
Java class in my plugin:
Code: Select all
@WebappCompatible
@WebappRestSafe
public class IsDocumentValid extends AuthorOperationWithResult {
private final static Logger logger = Logger.getLogger(IsDocumentValid.class.getName());
@Override
public String doOperation(AuthorDocumentModel model, ArgumentsMap args) throws AuthorOperationException {
try {
final List<DocumentPositionedInfo> errors = model.getDocumentValidator().getValidationTask().call();
return String.valueOf((errors == null) || (errors.isEmpty()));
} catch (Exception e) {
logger.error(e, e);
throw new AuthorOperationException(e.getMessage(), e);
}
}
}
Code: Select all
goog.events.listenOnce(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
var editor = e.editor;
goog.events.listenOnce(e.editor, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
var commitAction = editor.getActionsManager().getActionById('Git/Commit');
var oldActionPerformed = commitAction.actionPerformed;
commitAction.actionPerformed = function(callback) {
editor.getActionsManager().invokeOperation(
'com.gdvdl.webauth.IsDocumentValid',
{}, // no parameters
function (err, result) {
console.log('Git/Commit - isValid: ' + result);
if (result == 'true') {
console.log('Git/Commit - valid');
oldActionPerformed.call(commitAction, callback);
} else {
console.log('Git/Commit - invalid');
dialog = workspace.createDialog();
dialog.setButtonConfiguration(sync.api.Dialog.ButtonConfiguration.OK);
dialog.setTitle('Error');
dialog.getElement().innerHTML = 'Commit with validation errors is not allowed.';
dialog.show();
}
},
null,
true // This is a background operation - it does not update the document
);
};
});
});
Patrik
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