Set filename and save folder via plugin or framework
Post here questions and problems related to oXygen frameworks/document types.
Set filename and save folder via plugin or framework
Hello again,
is there a way, when saving a file, to auto generate the filename (based on an ID value within the document) and set the save location to a predetermined folder on server filesystem.
I figured out how to inject code using the saveListener but have not found ways to manipulate the filename or savelocation.
Thank you!
is there a way, when saving a file, to auto generate the filename (based on an ID value within the document) and set the save location to a predetermined folder on server filesystem.
I figured out how to inject code using the saveListener but have not found ways to manipulate the filename or savelocation.
Thank you!
Re: Set filename and save folder via plugin or framework
Hi Andreas,
How about if on this callback:
you sometimes return "false" to cancel the save operation and then maybe call:
? Calling "saveAs" might also call the "editorAboutToBeSavedVeto" again so you need to make sure you do not end up in a loop.
Regards,
Radu
How about if on this callback:
Code: Select all
ro.sync.exml.workspace.api.listeners.WSEditorListener.editorAboutToBeSavedVeto(int)
Code: Select all
ro.sync.exml.workspace.api.editor.WSEditorBase.saveAs(URL)
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: Set filename and save folder via plugin or framework
Hi Radu
thanks, yes that was the direction in which I was thinking.
I forgot to mention that I'm using the a JS plugin to achieve this.
Here's a snippet of my current code, the message "in save event" is displayed as expected but I get the error "Cannot find function saveAs in object 0"
I have the feeling that I'm overlooking something really obvious here. "editor" as a WSEditor should have inherited the "saveAs" method from WSEditorBase (https://www.oxygenxml.com/InstData/Edit ... ditor.html)
thanks, yes that was the direction in which I was thinking.
I forgot to mention that I'm using the a JS plugin to achieve this.
Here's a snippet of my current code, the message "in save event" is displayed as expected but I get the error "Cannot find function saveAs in object 0"
Code: Select all
editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, Packages.ro.sync.exml.workspace.api.PluginWorkspace.MAIN_EDITING_AREA);
preSaveListener = {
editorAboutToBeSavedVeto: function(editor) {
javax.swing.JOptionPane.showMessageDialog(null, "in save event");
chosenURL = "[some url]";
editor.saveAs(chosenURL);
return false
Re: Set filename and save folder via plugin or framework
Hi Andreas,
Please give me more sample code from your side, especially about how you add the "preSaveListener" listener to the WSEditor using the API "ro.sync.exml.workspace.api.editor.WSEditor.addEditorListener(WSEditorListener)".
Tomorrow I can try to create a sample minimal plugin on my side to see if this works.
Regards,
Radu
Please give me more sample code from your side, especially about how you add the "preSaveListener" listener to the WSEditor using the API "ro.sync.exml.workspace.api.editor.WSEditor.addEditorListener(WSEditorListener)".
Tomorrow I can try to create a sample minimal plugin on my side to see if this works.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: Set filename and save folder via plugin or framework
This is the entire wsAccess.js right now.
When I return "true" in the preSaveListener, both event listeners work as expected showing my debug messages just before/after the save.
When I return "true" in the preSaveListener, both event listeners work as expected showing my debug messages just before/after the save.
Code: Select all
function applicationStarted(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println("Application started " + pluginWorkspaceAccess);
edChangedListener = {
/*Called when a document is Opened*/
editorOpened: function (editorLocation) {
Packages.java.lang.System.err.println("\nrunning " + editorLocation);
/*Get the opened editor*/
editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, Packages.ro.sync.exml.workspace.api.PluginWorkspace.MAIN_EDITING_AREA);
preSaveListener = {
/* Called when a document is about to be Saved */
editorAboutToBeSavedVeto: function(editor) {
javax.swing.JOptionPane.showMessageDialog(null, "in save event");
chosenURL = "[some url]";
editor.saveAs(chosenURL);
return false
}
}
postSaveListener = {
/* Called when a document is Saved */
editorSaved: function(editor) {
javax.swing.JOptionPane.showMessageDialog(null, "gespeichert")
}
}
preSaveListener = new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorListener, preSaveListener);
postSaveListener = new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorListener, postSaveListener);
if (editor !=0) {
editor.addEditorListener(preSaveListener)
editor.addEditorListener(postSaveListener)
}
}
}
edChangedListener = new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorChangeListener, edChangedListener);
pluginWorkspaceAccess.addEditorChangeListener(
edChangedListener,
Packages.ro.sync.exml.workspace.api.PluginWorkspace.MAIN_EDITING_AREA);
}
function applicationClosing(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println("Application closing " + pluginWorkspaceAccess);
}
Re: Set filename and save folder via plugin or framework
Hi Andreas,
The "saveAs" takes an URL as a parameter:
https://www.oxygenxml.com/InstData/Edit ... rBase.html
So you may need to rewrite the code to:
Regards,
Radu
The "saveAs" takes an URL as a parameter:
https://www.oxygenxml.com/InstData/Edit ... rBase.html
So you may need to rewrite the code to:
Code: Select all
chosenURL = new Packages.java.net.URL("[some url]");
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: Set filename and save folder via plugin or framework
Hi Radu
That's a good hint. Thanks.
Even with that, my code returned "TypeError: Cannot find function saveAs in object 0." in the above configuration.
Today I rewrote the preSaveListener and made some progress I think...
This fixes the TypeError. "saveAs" gets called now, but it does not actually save the file. (also tested with other URL without success)
That's a good hint. Thanks.
Even with that, my code returned "TypeError: Cannot find function saveAs in object 0." in the above configuration.
Today I rewrote the preSaveListener and made some progress I think...
Code: Select all
preSaveListener = {
/* Called when a document is about to be Saved */
editorAboutToBeSavedVeto: function(editor) {
javax.swing.JOptionPane.showMessageDialog(null, "in save event");
currentEditor = new JavaAdapter( Packages.ro.sync.exml.workspace.api.editor.WSEditor, editorLocation)
chosenURL = new Packages.java.net.URL("file:/C/testsave/test.xml");
currentEditor.saveAs(chosenURL);
return false
}
Re: Set filename and save folder via plugin or framework
Hi Andreas,
I'm attaching a test code which works on my side:
as a difference from what you did, if you look at the Java code for the method:
https://www.oxygenxml.com/InstData/Edit ... dVeto-int-
The parameter is "operationType" and I used it to perform the save-as only on the callback for the save operation.
Regards,
Radu
I'm attaching a test code which works on my side:
Code: Select all
function applicationStarted(pluginWorkspaceAccess) {
Packages.java.lang.System.err.println("Application started " + pluginWorkspaceAccess);
var edChangedListener = {
/*Called when a document is opened*/
/*See: https://www.oxygenxml.com/InstData/Editor/SDK/javadoc/ro/sync/exml/plugin/workspace/WorkspaceAccessPluginExtension.html */
editorOpened: function (editorLocation) {
Packages.java.lang.System.err.println("\nrunning " + editorLocation);
var editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, Packages.ro.sync.exml.workspace.api.PluginWorkspace.MAIN_EDITING_AREA);
preSaveListener = {
/* Called when a document is about to be Saved */
editorAboutToBeSavedVeto: function(operationType) {
if(operationType == Packages.ro.sync.exml.workspace.api.listeners.WSEditorListener.SAVE_OPERATION){
chosenURL = new Packages.java.net.URL("file:/D:/testsave/test.xml");
javax.swing.JOptionPane.showMessageDialog(null, "in save event");
editor.saveAs(chosenURL);
return false;
}
return true;
}
}
preSaveListener = new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorListener, preSaveListener);
if (editor !=0) {
editor.addEditorListener(preSaveListener)
}
}
}
var edChangedListenerAdapter = new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorChangeListener, edChangedListener);
/* Add the editor changed listener */
pluginWorkspaceAccess.addEditorChangeListener(
edChangedListenerAdapter,
Packages.ro.sync.exml.workspace.api.PluginWorkspace.MAIN_EDITING_AREA);
}
https://www.oxygenxml.com/InstData/Edit ... dVeto-int-
The parameter is "operationType" and I used it to perform the save-as only on the callback for the save operation.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
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