Page 1 of 1

The list of actions available for applet

Posted: Wed May 06, 2015 1:48 am
by sderrick
in the main applet function that configures the toolbar is the following code

Code: Select all

			if (EditorPageConstants.PAGE_AUTHOR.equals(editorComponent
.getWSEditorAccess().getCurrentPageID())) {
WSAuthorComponentEditorPage authorPage = (WSAuthorComponentEditorPage) editorComponent
.getWSEditorAccess().getCurrentPage();

Map<String, Object> authorCommonActions = authorPage
.getActionsProvider().getAuthorCommonActions();

// You can look in the list of actions to see what's available.
Where is this "list of actions" mentioned on the last line?

Another question:

If I add a "save" action, I imagine I need to add a js function to send the contents to my server. Is there an example of how hook that action to a js function?

thanks,

Scott

Re: The list of actions available for applet

Posted: Wed May 06, 2015 8:09 am
by Radu
Hi Scott,

So:
Where is this "list of actions" mentioned on the last line?
That remark meant that you can use System.out.println("Common actions: " + authorCommonActions); and then look in the Java console to see what action keys are available for usage.
If I add a "save" action, I imagine I need to add a js function to send the contents to my server. Is there an example of how hook that action to a js function?
You have about two choices:

1) Have a "Save" action in the HTML page surrounding the applet (so it would not be on the applet toolbar). The action would call a method from the applet side to obtain its XML content and then possibly use an AJAX request to send the content to a server.
The applet sample already comes with a Javascript file which shows how you can call methods from the Java applet instantiated in the page:

Code: Select all

/**
* Sets the content to be edited.
*
* @param url The base system ID of the content. Used to resolve referred resources.
* @param content The serialized XML
*/
function setDocumentContent(url, content) {
var sample = document.getElementById('authorComponentApplet').getAuthorComponentSample();
if(sample != null){
// May be null if not licensed.

try {
sample.setDocumentContent(url, content);
}
catch (e) {
alert("setDocumentContent " + e);
}
}
}
2) The Save action could be on the applet's internal toolbar.
The Author Component is usually loaded from an URL ro.sync.ecss.extensions.api.component.ComponentProvider.load(URL, Reader).
If that URL points to a webdav enabled server, when you call ro.sync.ecss.extensions.api.component.ComponentProvider.getWSEditorAccess().save() the component will try to use the PUT HTTP method to save the content back to the URL from where the content was opened.
Or again you can obtain the edited XML content using ro.sync.ecss.extensions.api.component.ComponentProvider.getWSEditorAccess().createContentReader() and save it to a server either by calling some Java code or by calling some Javascript code from the web page where the applet is embedded. As an example of calling Javascript code from Java is found in the class AuthorComponentSampleApplet.java which at some point does:

Code: Select all

getAppletContext().showDocument(new URL("javascript:onLoad()"));
Regards,
Radu