com.ephox.editlive
Class ELXBean

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bycom.ephox.editlive.ELXBean
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class ELXBean
extends JPanel

This class provides a simple JavaBean style interface to EditLive! for XML.

The general usage pattern of this class is that you create a new instance, set the appropriate properties and then call init(). init() should only be called once.

Most methods should only be called before init() is called, methods which do work after init() has been called are explicitely marked with the text:

This method may be called after init() has been called.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ELXBean()
          Creates a new ELXBean with the default settings.
 
Method Summary
 void addEditorEventListener(EventListener oListener)
          Adds an editor listener for notification of any changes.
 void addHyperlinkDialogComponent(String className, Object[] params)
          Adds a HyperlinkDialogComponent to the bean for use in the insert hyperlink dialog.
 void addImageDialogComponent(String className, Object[] params)
          Adds an ImageDialogComponent to the bean for use in the insert image dialog.
 void addSchema(String xsd)
          Adds the specified schema to the bean.
 void addView(String name, String xslt)
          Adds a view to the component.
 void addView(String name, URL url)
          Adds a view to the component.
 String getBaseURL()
          Returns the Base URL used for loading resources (e.g.
 Document getConfigurationDocument()
          Get the DOM the XML configuration will be loaded from.
 File getConfigurationFile()
          Get the file the XML configuration will be loaded from.
 String getConfigurationText()
          Get the String the XML configuration will be loaded from.
 URL getConfigurationURL()
          Get the URL the XML configuration will be loaded from.
 String getCookie()
          Returns the cookie that will be sent with HTTP requests.
 File getCurrentFile()
          Returns the file currently being edited.
 String getDocument()
          Returns the XML document being edited.
 Document getDOM()
          Get the DOM for the document being edited.
 String getEphoxIdFor(Node node)
          Returns the EphoxID for the specified node.
 SourceFilter getFilter()
          Get the filter that will be applied to content on the way in and out of the editor.
 JTextPane getHTMLPane()
          Method used return the underlying JTextPane.
 JMenuBar getMenuBar()
          Returns the menubar for this bean.
 Node getNode(String ephoxID)
          Retrieves a node from the DOM being edited.
 String getOutputCharset()
          Returns the character set to be used when outputting the document.
 String getSchemaLocation()
          Returns the list of URLs to download XML schema from.
 void init()
          Initializes the component so that it is ready for display.
 void insertHTMLAtCursor(String html)
          Inserts the specified html at the current caret position.
 boolean isCrippled()
          Determines whether or not functionality has been restricted.
 boolean isDirty()
          Returns true if the content in the editor has been changed.
 boolean isInited()
          Get the inited
 boolean isMenuEmbedded()
          Determines whether or not the menubar is currently embedded in the bean.
 boolean isToolBarEmbedded()
          Determines whether or not the toolbar is currently embedded in the bean.
 void loadSolution(URL solution)
          Load the schema and views from the specified solution.
 void raiseEvent(TextEvent e)
          Method used to raise an event within EditLive! for XML.
 void refreshDisplay()
          Updates the display to reflect any changes to the structure of the XML DOM.
 void registerCustomBlockTag(String tagName, Icon startIcon, String startLabel, Icon endIcon, String endLabel, ViewClickListener listener)
          Registers a custom block tag.
 void registerCustomBlockView(String tagName, String viewClass, Object extraData)
          Registers a custom view for the specified block tag.
 void registerCustomEmptyTag(String tagName, Icon icon, String label, ViewClickListener listener)
          Registers a custom empty tag.
 void registerCustomEmptyView(String tagName, String viewClass, Object extraData)
          Registers a custom view for the specified empty tag.
 void registerCustomInlineTag(String tagName, Icon startIcon, String startLabel, Icon endIcon, String endLabel, ViewClickListener listener)
          Registers a custom inline tag.
 void registerCustomInlineView(String tagName, String viewClass, Object extraData)
          Registers a custom view for the specified inline tag.
 void removeEditorEventListener(EventListener oListener)
          Removes an editor listener.
 void setBaseURL(String url)
          Sets the Base URL used for loading resources (e.g.
 void setBrowserCallback(Object object)
          Provides the data required for custom actions which call back to functions in the browser to work.
 void setConfigurationDocument(Document configuration)
          Set the DOM to load the configuration from.
 void setConfigurationFile(File configuration)
          Set the file to load the configuration from.
 void setConfigurationText(String configuration)
          Set the configuration.
 void setConfigurationURL(URL configuration)
          Set the URL to load the configuration from.
 void setCookie(String cookie)
          Adds a cookie to send with HTTP requests.
 void setCurrentFile(File file)
          Sets the path to the currently edited file.
 void setDirty(boolean dirty)
          Sets whether or not the content in the editor has been changed.
 void setDocument(String xml)
          Sets the XML document to edit.
 void setFilter(SourceFilter filter)
          Set the filter to apply to content on the way in and out of the editor.
 void setMenuEmbedded(boolean embed)
          Sets whether or not the menubar is embedded in the bean.
 void setOutputCharset(String encoding)
          Sets the character set to use when outputting the document.
 void setPreviewXSLT(String xslt)
          Set the preview XSLT to use as a text string.
 void setPreviewXSLT(URL url)
          Set the URL to download the preview XSLT from.
 void setSchemaLocation(String locations)
          Sets the list of URLs to download XML schemas from.
 void setToolBarEmbedded(boolean embed)
          Sets whether or not the toolbar is embedded in the bean.
 void uploadLocalFiles()
          Uploads all local images and embedded objects stored within the document and also adjusts their src attribute.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ELXBean

public ELXBean()
Creates a new ELXBean with the default settings.

Method Detail

addView

public void addView(String name,
                    URL url)
Adds a view to the component.

Parameters:
name - the name of the view.
url - the URL to download the XSLT from.
See Also:
addView(String, String)

addView

public void addView(String name,
                    String xslt)
Adds a view to the component.

Parameters:
name - the name of the view.
xslt - the XSLT for the view.
See Also:
addView(String, URL)

setPreviewXSLT

public void setPreviewXSLT(String xslt)
Set the preview XSLT to use as a text string.

Parameters:
xslt - the XSLT to use for the preview.

setPreviewXSLT

public void setPreviewXSLT(URL url)
Set the URL to download the preview XSLT from.

Parameters:
url - the URL to download the preview XSLT from.

addSchema

public void addSchema(String xsd)
Adds the specified schema to the bean.

Parameters:
xsd - the schema to add as a String.

loadSolution

public void loadSolution(URL solution)
                  throws IOException
Load the schema and views from the specified solution.

Parameters:
solution - the URL to the solution. This may be a http, file or jar URL.
Throws:
IOException - if an error occurs while accessing the solution.

getNode

public Node getNode(String ephoxID)
Retrieves a node from the DOM being edited. The EphoxID of the node should be retrieved from within the XSLT, for example:

will raise and event with the extra string containing the ephoxid of the context element. For attributes, the EphoxID is defined as the EphoxID of the owner node with "@" and the name of the attribute appended to it. If the attribute in question is the current context node, the following XPath expression would create the correct EphoxID:

concat(../@ephoxid, '@', local-name())

For Text nodes, the EphoxID is defined as the EphoxID of the parent node with # and the position of the text node appended to it. If the text node in question is the current context node, the following XPath expression would create the correct EphoxID:

concat(../@ephoxid, '#', position())

It is important that structural changes (adding or removing nodes) must not be performed on the DOM as the changes will not be correctly identified by EditLive! for XML. Future versions will add support for these changes.

All access to the node must be done within a synchronized block synchronizing on the owner document for the node. For example:

Node n = bean.getNode(ephoxid);
 synchronized (n.getOwnerDocument()) {
     n.setNodeValue("Test Value");
 }

Parameters:
ephoxID - the EphoxID of the node to retrieve.
Returns:
the Node corresponding to ephoxID or null if no matching node is found.

getEphoxIdFor

public String getEphoxIdFor(Node node)
Returns the EphoxID for the specified node. The node must have already been added to the DOM.

Parameters:
node - the node to retrieve the id for.
Returns:
the Ephox ID for node. The return value is undefined if node has not been added to the DOM.

getDOM

public Document getDOM()
Get the DOM for the document being edited. All access to the DOM must be synchronized on the Document.

Returns:
the DOM for the document.

refreshDisplay

public void refreshDisplay()
Updates the display to reflect any changes to the structure of the XML DOM. If elements or attributes are added or removed this method must be called. There is no requirement to call this method if only node values have changed.


setSchemaLocation

public void setSchemaLocation(String locations)
Sets the list of URLs to download XML schemas from. These are used in addition to any XSDs added using #addXSD(String).

Parameters:
locations - a whitespace separated list of URLs to download schemas from.

getSchemaLocation

public String getSchemaLocation()
Returns the list of URLs to download XML schema from. These are used in addition to any XSDs added using #addXSD(String).

Returns:
a whitespace separated list of URLs that schemas are downloaded from.

setDocument

public void setDocument(String xml)
Sets the XML document to edit.

This method may be called after init() has been called.

Parameters:
xml - the XML to edit as a String.

getDocument

public String getDocument()
Returns the XML document being edited.

This method may be called after init() has been called.

Returns:
the XML document being edited.

setCurrentFile

public void setCurrentFile(File file)
Sets the path to the currently edited file. If this is set to a non-null value, the TextEvent.SAVE_ACTION will save to this file without prompting the user. If set to null, the user will be prompted as in the TextEvent.SAVE_AS_ACTION. The default behaviour of the TextEvent.OPEN_ACTION and TextEvent.SAVE_AS_ACTION will set the current file to the users selection.

Parameters:
file - the file to save to by default.
See Also:
getCurrentFile()

getCurrentFile

public File getCurrentFile()
Returns the file currently being edited.

Returns:
the file currently being editor or null if no file is set.
See Also:
setCurrentFile(File)

isDirty

public boolean isDirty()
Returns true if the content in the editor has been changed.

This method may be called after init() has been called.

Returns:
true if the content has been changed, otherwise false.

setDirty

public void setDirty(boolean dirty)
Sets whether or not the content in the editor has been changed. This is useful if you are using your own load and save functions.

This method may be called after init() has been called.

Parameters:
dirty - true if the content in the editor has been changed, otherwise false.

addEditorEventListener

public void addEditorEventListener(EventListener oListener)
Adds an editor listener for notification of any changes.

This method may be called after init() has been called.

Parameters:
oListener - Object to add to listener list.

removeEditorEventListener

public void removeEditorEventListener(EventListener oListener)
Removes an editor listener.

This method may be called after init() has been called.

Parameters:
oListener - Object to remove from listener list.

raiseEvent

public void raiseEvent(TextEvent e)
Method used to raise an event within EditLive! for XML. Events drive nearly all the actions in EditLive! for XML, including all actions resulting from menubars and toolbars.

See the documentation for TextEvent for information about what the events can be fired.

This method may be called after init() has been called.

Parameters:
e - TextEvent to be parsed.

setCookie

public void setCookie(String cookie)
Adds a cookie to send with HTTP requests.

Parameters:
cookie - the cookie to include with any HTTP requests generated.
See Also:
getCookie()

getCookie

public String getCookie()
Returns the cookie that will be sent with HTTP requests.

Returns:
the cookie set on this bean.
See Also:
setCookie(String)

getHTMLPane

public JTextPane getHTMLPane()
Method used return the underlying JTextPane. This method should only be used when the TextEvent class does not support the required operation. Note that this method must not be called until #isLoadingComplete()returns true.

Returns:
Underlying JTextPane editor.

registerCustomBlockTag

public void registerCustomBlockTag(String tagName,
                                   Icon startIcon,
                                   String startLabel,
                                   Icon endIcon,
                                   String endLabel,
                                   ViewClickListener listener)
Registers a custom block tag. The tag will be displayed with the given icons and labels at the start and end of the block. The ViewClickListener will be notified when a mouse click is detected on the view.

Parameters:
tagName - the name of the custom block tag.
startIcon - the icon to display at the start of the block, or null for no icon.
startLabel - the label to display at the start of the block, or null for no label.
endIcon - the icon to display at the end of the block, or null for no icon.
endLabel - the label to display at the end of the block, or null for no label.
listener - the listener to notify of mouse click events, or null if no notification is required.

registerCustomInlineTag

public void registerCustomInlineTag(String tagName,
                                    Icon startIcon,
                                    String startLabel,
                                    Icon endIcon,
                                    String endLabel,
                                    ViewClickListener listener)
Registers a custom inline tag. The tag will be displayed with the given icons and labels at the start and end of the tag. The ViewClickListener will be notified when a mouse click is detected on the view.

Parameters:
tagName - the name of the custom inline tag.
startIcon - the icon to display at the start of the tag, or null for no icon.
startLabel - the label to display at the start of the tag, or null for no label.
endIcon - the icon to display at the end of the tag, or null for no icon.
endLabel - the label to display at the end of the tag, or null for no label.
listener - the listener to notify of mouse click events, or null if no notification is required.

registerCustomEmptyTag

public void registerCustomEmptyTag(String tagName,
                                   Icon icon,
                                   String label,
                                   ViewClickListener listener)
Registers a custom empty tag. The tag will be displayed with the given icon and label. The ViewClickListener will be notified when a mouse click is detected on the view.

Parameters:
tagName - the name of the custom inline tag.
icon - the icon to display for the tag, or null for no icon.
label - the label to display for the tag, or null for no label.
listener - the listener to notify of mouse click events, or null if no notification is required.

registerCustomBlockView

public void registerCustomBlockView(String tagName,
                                    String viewClass,
                                    Object extraData)
Registers a custom view for the specified block tag.

Parameters:
tagName - the name of the tag to use the view for.
viewClass - the fully qualify class name for the Viewfor the tag.
extraData - this can be any object (or null) and is passed into the constructor for viewClass if it has a constructor that takes both an element and an object.

registerCustomInlineView

public void registerCustomInlineView(String tagName,
                                     String viewClass,
                                     Object extraData)
Registers a custom view for the specified inline tag.

Parameters:
tagName - the name of the tag to use the view for.
viewClass - the fully qualify class name for the Viewfor the tag.
extraData - this can be any object (or null) and is passed into the constructor for viewClass if it has a constructor that takes both an element and an object.

registerCustomEmptyView

public void registerCustomEmptyView(String tagName,
                                    String viewClass,
                                    Object extraData)
Registers a custom view for the specified empty tag.

Parameters:
tagName - the name of the tag to use the view for.
viewClass - the fully qualify class name for the Viewfor the tag.
extraData - this can be any object (or null) and is passed into the constructor for viewClass if it has a constructor that takes both an element and an object.

isMenuEmbedded

public boolean isMenuEmbedded()
Determines whether or not the menubar is currently embedded in the bean.

Returns:
true if the menu is embedded, otherwise false.

setMenuEmbedded

public void setMenuEmbedded(boolean embed)
Sets whether or not the menubar is embedded in the bean.

If set to false, the menubar will not be displayed in the bean and the application must ensure that it adds the menubar to the frame.

Parameters:
embed - true if the menubar should be embedded, otherwise false.
See Also:
getMenuBar()

getMenuBar

public JMenuBar getMenuBar()
Returns the menubar for this bean.

Returns:
the menubar for this bean.
See Also:
setMenuEmbedded(boolean), isMenuEmbedded()

isToolBarEmbedded

public boolean isToolBarEmbedded()
Determines whether or not the toolbar is currently embedded in the bean.

Returns:
true if the toolbar is embedded, otherwise false.

setToolBarEmbedded

public void setToolBarEmbedded(boolean embed)
Sets whether or not the toolbar is embedded in the bean.

If set to false, the toolbar will not be displayed in the bean and the application must ensure that it adds the toolbar to the frame.

Parameters:
embed - true if the toolbar should be embedded, otherwise false.
See Also:
#getToolBar()

insertHTMLAtCursor

public void insertHTMLAtCursor(String html)
Inserts the specified html at the current caret position.

Parameters:
html - the html to insert.

uploadLocalFiles

public void uploadLocalFiles()
Uploads all local images and embedded objects stored within the document and also adjusts their src attribute.


isCrippled

public boolean isCrippled()
Determines whether or not functionality has been restricted. This will return true if the 30 day trial has expired and no valid license was supplied in the XML configuration.

Returns:
true if the trial period has expired and no valid license was found.

setBrowserCallback

public void setBrowserCallback(Object object)
Provides the data required for custom actions which call back to functions in the browser to work. This is not generally useful except when the ELXBean is being embedded inside an applet and custom actions such as getWordCount, getCharacterCount and raiseEvent should be sent to the browser. Most users should not call this function.

Parameters:
object - the callback. On Windows, Solaris and Linux this should be an instance of netscape.javascript.JSObject. On OS X it should be a String representing the JavaScript path to the frame the applet is in eg: window.mainFrame.contentFrame

addImageDialogComponent

public void addImageDialogComponent(String className,