Edit online

Selection Plugin Extension

This type of plugin allows you to manage selections of text.

A selection plugin can be applied to both XML and non-XML documents. The plugin is started by making a selection in the editor, then selecting the corresponding menu item from the Plugins submenu in the contextual menu of Text mode.

This plugin type provides the following API:

SelectionPluginExtension interface
The context containing the selected text is passed to the extension and the processed result is going to replace the initial selection. The process(GeneralPluginContext) method must return a SelectionPluginResult object that contains the result of the processing. The String value returned by the SelectionPluginResult object can include editor variables such as ${caret} and ${selection}.
SelectionPluginContext object
Represents the context and provides four methods:
  • getSelection() - Returns a String that is the current selection of text.
  • getFrame() - Returns a Frame that is the editing frame.
  • getPluginWorkspace() - Returns access to the workspace of Oxygen XML Developer.
  • getDocumentURL() - Returns the URL of the currently edited document.
Edit online

Example - Uppercase Plugin

The following plugin is called UppercasePlugin and is an example of a Selection plugin.. It is used in Oxygen XML Developer for capitalizing the characters in the current selection. This example consists of two Java classes and the plugin descriptor file (plugin.xml):

  • UppercasePlugin.java:
    
    package ro.sync.sample.plugin.uppercase;
    
    import ro.sync.exml.plugin.Plugin;
    import ro.sync.exml.plugin.PluginDescriptor;
    
    public class UppercasePlugin extends Plugin {
        /**
        * Plugin instance.
        */
        private static UppercasePlugin instance = null;  
        
        /**
        * UppercasePlugin constructor.
        * 
        * @param descriptor Plugin descriptor object.
        */
        public UppercasePlugin(PluginDescriptor descriptor) {
            super(descriptor);
        
            if (instance != null) {
                throw new IllegalStateException("Already instantiated !");
            }    
            instance = this;
        }
        
        /**
        * Get the plugin instance.
        * 
        * @return the shared plugin instance.
        */
        public static UppercasePlugin getInstance() {
            return instance;
        }
    }
    
  • UppercasePluginExtension.java:
    
    package ro.sync.sample.plugin.uppercase;
    
    import ro.sync.exml.plugin.selection.SelectionPluginContext;
    import ro.sync.exml.plugin.selection.SelectionPluginExtension;
    import ro.sync.exml.plugin.selection.SelectionPluginResult;
    import ro.sync.exml.plugin.selection.SelectionPluginResultImpl;
    
    public class UppercasePluginExtension implements SelectionPluginExtension {
        /**
        * Convert the text to uppercase.
        *
        *@param  context  Selection context.
        *@return          Uppercase plugin result.
        */
        public SelectionPluginResult process(SelectionPluginContext context) {
            return new SelectionPluginResultImpl(
                context.getSelection().toUpperCase());
        }
    }
    
  • plugin.xml:
    
    <!DOCTYPE plugin SYSTEM "../plugin.dtd">
    <plugin
        name="UpperCase"
        description="Convert the selection to uppercase"
        version="1.0.0"
        vendor="SyncRO"
        class="ro.sync.sample.plugin.uppercase.UppercasePlugin">
        <runtime>
            <library name="lib/uppercase.jar"/>
        </runtime>
        <extension type="selectionProcessor" 
         class="ro.sync.sample.plugin.uppercase.UppercasePluginExtension"/>
    </plugin>