Page 1 of 1

oXygen 9.1 - writing a document plugin, how do I access it?

Posted: Mon Feb 04, 2008 6:58 am
by ctparker
So, I've written a DocumentPluginExtension for what used to be a command-line Java program (XML in, XML out).

Oxygen shows that it is initialized in Preferences -> Plugins. However, I have no idea how to invoke my plugin via the user interface. The documentation seems to indicate that it should be available when modifying the contextual menu, but it does not show up there. The documentation is a little sparse in this area. Can someone point me in the right direction?

Re: oXygen 9.1 - writing a document plugin, how do I access it?

Posted: Mon Feb 04, 2008 2:13 pm
by sorin_ristache
Hello,

Just follow the example of the action ReplaceTextAction (com.oxygenxml.editor.sample.extension.action.ReplaceTextAction) which is defined as an extension of the oXygen plugin in the plugin.xml file descriptor of the example Eclipse plugin included in the oXygen extensions development kit which you can find on the Community page:

Code: Select all

    <extension point="com.oxygenxml.editor.contextMenuAdditions">
<group id="Example_group_1">
<action
id="Example_action_1"
label="Replace selection"
icon="images/ReplaceText16.gif"
text="NEW_TEXT"
class="com.oxygenxml.editor.sample.extension.action.ReplaceTextAction"/>
</group>
</extension>
The replace text action shows up on the contextual menu of the editor panel of an editor contributed by the oXygen plugin (the Oxygen XML Editor for example). You can find the complete source code of the action ReplaceTextAction in the development kit.


Regards,
Sorin

Re: oXygen 9.1 - writing a document plugin, how do I access it?

Posted: Mon Feb 04, 2008 6:07 pm
by ctparker
I appreciate the quick response. This is not using the Eclipse plugin though. This is a plugin for the standalone oXygen distribution, using OxygenPluginsDevelopmentKit.

I'm looking at plugin.dtd, and there is no mention of a group element or point attribute.

This was my original plugin.xml (edited):

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin SYSTEM "../plugin.dtd">
<plugin
name="Auto-tagger plugin"
description="Description of the plugin."
version="1.0.0"
vendor="sample vendor"
class="com.packagename.oxygen.TaggerPlugin">
<runtime>
<library name="lib/n4l.jar"/>
</runtime>
<extension type="documentProcessor" class="com.packagename.oxygen.TaggerPluginExtension"/>
</plugin>

Re: oXygen 9.1 - writing a document plugin, how do I access it?

Posted: Tue Feb 05, 2008 6:58 pm
by sorin_ristache
For oXygen standalone plugins just look at the source code of the sample plugins in the section Plugins of the Community page, for example the CapLines plugin. In your DocumentPluginExtension implementation you have to implement only the method process(DocumentPluginContext). The following is an example of plugin that appends the string "ABC" at the end of the edited document. You run the plugin by right clicking in the editor panel and selecting Plugins -> Insert Text. If you install the plugin correctly in a subfolder of the folder [oXygen-install-folder]/plugins you can see in Options -> Preferences -> Plugins the details that are specified in the plugin.xml descriptor of the plugin:

- InsertTextExtension.java:

Code: Select all

package ro.sync.sample.plugin;

import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

import ro.sync.exml.plugin.document.DocumentPluginContext;
import ro.sync.exml.plugin.document.DocumentPluginExtension;
import ro.sync.exml.plugin.document.DocumentPluginResult;

public class InsertTextExtension implements DocumentPluginExtension {

/**
* @see ro.sync.exml.plugin.document.DocumentPluginExtension#process(ro.sync.exml.plugin.document.DocumentPluginContext)
*/
public DocumentPluginResult process(DocumentPluginContext context) {
final Document doc = context.getDocument();

try {
doc.insertString(doc.getLength() - 1, "ABC", null);
} catch (BadLocationException e) {
e.printStackTrace();
}

return new DocumentPluginResult() {
public Document getProcessedDocument() {
return doc;
}
};
}
}

- InsertTextPlugin.java:

Code: Select all

package ro.sync.sample.plugin;

import ro.sync.exml.plugin.Plugin;
import ro.sync.exml.plugin.PluginDescriptor;

public class InsertTextPlugin extends Plugin {
private static InsertTextPlugin instance = null;

public InsertTextPlugin(PluginDescriptor descriptor) {
super(descriptor);

if (instance != null) {
throw new IllegalStateException("Already instantiated!");
}
instance = this;
}

public static InsertTextPlugin getInstance() {
return instance;
}
}

- plugin.xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin SYSTEM "../plugin.dtd">
<plugin
name="Insert Text"
description="Insert text in the editor"
version="1.0.0"
vendor="SyncRO"
class="ro.sync.sample.plugin.InsertTextPlugin">
<runtime>
<library name="lib/textInsert.jar"/>
</runtime>
<extension type="documentProcessor"
class="ro.sync.sample.plugin.InsertTextExtension"/>
</plugin>
You can find details about creating and installing a plugin in the plugins development guide available on the same Community page.


Regards,
Sorin

Re: oXygen 9.1 - writing a document plugin, how do I access it?

Posted: Tue Feb 05, 2008 7:36 pm
by ctparker
Ah, I see it now! For some reason, I expected it to be available in Author mode.

I've been through all of the documentation, and I don't see anything about the following:

Is there a way to set up hotkeys for a plugin?

How are errors reported?

Is there an easy way to debug a plugin (console or some other logging method available)?

Re: oXygen 9.1 - writing a document plugin, how do I access it?

Posted: Wed Feb 06, 2008 2:01 pm
by sorin_ristache
No, you cannot set a shortcut for a plugin. We will consider adding this in a future version of oXygen.

The developer of the plugin should add logging instructions in the code of the plugin and a method/external library to output the logging data. oXygen just executes the code of the plugin without restricting the plugin to a logging method or a logging message format.


Regards,
Sorin