This page provides information on how to create a simple, customized version of the EditLive! for XML. The customized version of EditLive! for XML is created using the advanced API Java classes and interfaces. The applet instance in the example's webpage then loads this newly created Java class to load a customized version of EditLive! for XML.
This tutorial demonstrates how to perform the following using the EditLive! for XML Advanced APIs:
Creating a Java class containing an instance of the ELXBean class.
Registering an EventListener with an instance of the ELXBean class
Detect when an event has been fired by a specific custom menu item and display a dialog.
The sample_elxconfig.xml file contains the configuration information for the example. This file configures the custom menu item to use the raiseEvent functionality of EditLive! for XML.
The examination here is only of those XML tags which pertain to the configuration of the custom menu item. For more information on how to create a complete EditLive! for XML configuration file and other XML elements please see the EditLive! for XML Developer Guide packaged with this SDK.
Create a menu bar for use with EditLive! for XML.
<editLiveForXML>
...
<menuBar>
</menuBar>
...
</editLiveForXML>Create a menu for the custom menu item to be placed in. In this case the menu is called the Current Charset menu.
<editLiveForXML>
...
<menuBar>
...
<menu name="&Current Charset">
</menu>
...
</menuBar>
...
</editLiveForJava>Create the custom menu item which uses the raiseEvent functionality of EditLive! for XML. The following arguements are assigned to this menu item:
name: dislayCharsetMenuItem - a unique name for the menu item
text: Display Current Charset - text to appear on the menu item
action: raiseEvent - raises an event to the EventListener registered with the EditLive! for XML instance. See the Registering an EventListener with ELXBean section of this example.
value: displayCharset - string sent with event sent to EventListener to uniquely identify which menu item was pressed.
For detailed documentation on the values that can be assigned to customMenuItem arguments, see the XML Configuration API section of this document.
<editLiveForXML>
...
<menuBar>
...
<menu name="Insert">
...
<customMenuItem
name="displayCharsetMenuItem"
text="Display Current Charset"
action="raiseEvent"
value="displayCharset"
/>
...
</menu>
...
</menuBar>
...
</editLiveForXML>The BasicELX class is created in the file BasicELX.java The main class for the example application is the BasicELX class. This class takes an instance of the EditLive! for XML class, ELXBean and registers an event listener to the EditLive! for XML instance.
In order to use the advanced APIs, the main class defined needs to provide a constructor allowing a single ELXBean class to be passed as a parameter. This instance of ELXBean will be the instance the developer defined using the instantiation APIs in the webpage containing the EditLive! for XML applet. See the Instantiating EditLive! for XML in a Webpage section of this example for the webpage instantiation of EditLive! for XML.
public class BasicELX{
private ELXBean _bean;
public BasicELX(ELXBean bean) {
_bean = bean;
}
}To detect events being fired by an instance of ELXBean, a class implementing the EventListener interface has to be registered with an instance of the ELXBean class. In this example, the BasicELX class itself implements the EventListener interface and registers itself as a listener with the ELXBean instance.
public class BasicELX implements EventListener {
ELXBean _bean;
public BasicELX(ELXBean bean) {
_bean= bean;
System.err.println("Created with bean: " + bean);
bean.addEditorEventListener(this);
}
}For this example, this method has to detect events
fired by the Display Current Charset menu item. The following steps
are taken to detect when an event is fired by this menu
item:Detect if the event fired is a custom action event.
Detect if the event fired is a raise event type custom action.
Detect if the extra string parameter sent with the event matches the value arguement in the Display Current Charset menu item (i.e. "displayCharset")
public void raiseEvent(TextEvent e) {
if (e.getActionCommand() == TextEvent.CUSTOM_ACTION) {
if (e.getExtraInt() == TextEvent.CustomAction.RAISE_EVENT) {
if (e.getExtraString().equals("displayCharset")) {
// code custom action here
}
}
}
}Finally, this method need to display the current
version of EditLive! for XML once the conditions in raiseEvent are
met. To display the version number this example uses a
JOptionPane and the
getOutputCharset() method of
ELXBean.public void raiseEvent(TextEvent e) {
if (e.getActionCommand() == TextEvent.CUSTOM_ACTION) {
if (e.getExtraInt() == TextEvent.CustomAction.RAISE_EVENT) {
if (e.getExtraString().equals("displayCharset")) {
e.setHandled(true);
String versionString = "EditLive! for XML - Current Charset: " + _
bean.getVersion();
JOptionPane.showMessageDialog(null, versionString);
}
}
}
}Now this newly defined instance of EditLive! for XML has to be loaded into a webpage. In order to embed this new instance of EditLive! for XML the following steps must be undertaken:
Compile the created classes and stored them in a jar file.
For detailed information on compiling Java classes and creating jar files, see the Compiling Examples section of this document.
For this example the jar containing these classes is named BasicELX.jar.
Include the editlivejava.js file in the webpage.
EditLive! for XML requires a JavaScript file to be included. The file provides functions which EditLive! for XML uses to work.
<!--Include the EditLive! for XML JavaScript Library--> <script src="redistributables/editlivexml/editlivexml.js"></script>
Creating the instance of EditLive! for XML
For each instance of EditLive! for XML that you wish to create within a Web page a new instance object must be created. Each instance of EditLive! for XML which is created must have a name property which is unique within that particular Web page (eg. ELXApplet1, ELXApplet2). Also, each EditLive! for XML JavaScript object should have a different name which is unique within that particular Web page (eg. editlivexml1, editlivexml2).
<script language="JavaScript">
var editlivexml1;
editlivexml1 = new EditLiveXML("ELXApplet1", "700", "400");
editlivexml1.setDownloadDirectory("../../redistributables/editlivexml");
editlivexml1.setXMLURL("sample_elxconfig.xml");
editlivexml1.setXSDURL("salesreport.xsd");
editlivexml1.setOutputCharset("ASCII");
editlivexml1.addView("Article", "sales.xsl");Specify the new EditLive! for XML instance to load
To specify the new instance of EditLive! for XML use the addJar method. The method takes two parameters:
Jar Location: the URL location of the jar file containing the new instance of EditLive! for XML
Class Name: the fully qualified name of the class in the jar file that will load the new instance of EditLive! for XML
For this example, the following parameters are given to the addJar method:
editlivexml1.addJar("BasicELX.jar", "BasicELX");
editlivexml1.show();
</script> Using the advanced API, a new Java class can be created which can be loaded into a webpage instead of the default instance of the EditLive! for XML applet. This customized version of the EditLive! for XML applet can capitalize on creating new dialogs to display based on custom menu or toolbar items.
Copyright 2001-2005 Ephox Corporation. All Rights Reserved.