Plugin config, plugin dir, and API

Hi, I am investigating a bit with writing plugins for oXygen. I am at the point where I'd like to be able to configure it. I can of course write my own config file format and read it explicitely, but I guess that something similar already exists (like e.g. configuring simple key/value pairs in plugin.xml et read them through an API from the plugin SDK). Is there anything like that? My second (related) question is: how can we get the plugin dir via the API? And how to resolve resources in that dir? Congrats for the SDK! Starting a new plugin is very easy! (even though I still have to investigate more deeply the APIs :-p) Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/

Hi Florent, We do not yet have such support of setting pairs of key/value in the plugin.xml and then making them available to the Plugin Java classes. But it seems like an interesting improvement in order to control some configuration of a plugin without making changes in the Java code so we'll look into it. Please see more answers below:
My second (related) question is: how can we get the plugin dir via the API? And how to resolve resources in that dir?
Well, you could use the class loader to see from where the main plugin JAR library was loaded. For example on one of our implemented plugins we used a method like:
private File getLibDir() { URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); URL[] urls = cl.getURLs(); for (int i = 0; i < urls.length; i++) { URL url = urls[i]; if(url.toString().endsWith("acrolinx.jar")){ return pluginWorkspaceAccess.getUtilAccess().locateFile(url).getParentFile(); } } return null; }
Another approach would be to find out the location where Oxygen is installed using code like:
pluginWorkspaceAccess.getUtilAccess().expandEditorVariables(EditorVariables.OXYGEN_INSTALL_DIR, null);
and then append a "plugins/your-plugin-name" to that path.
Congrats for the SDK! Starting a new plugin is very easy! (even though I still have to investigate more deeply the APIs :-p)
If you find any quirks or have trouble finding certain APIs please do not hesitate to contact us. Regards, Radu Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 2/18/2012 12:25 AM, Florent Georges wrote:
Hi,
I am investigating a bit with writing plugins for oXygen. I am at the point where I'd like to be able to configure it. I can of course write my own config file format and read it explicitely, but I guess that something similar already exists (like e.g. configuring simple key/value pairs in plugin.xml et read them through an API from the plugin SDK).
Is there anything like that?
My second (related) question is: how can we get the plugin dir via the API? And how to resolve resources in that dir?
Congrats for the SDK! Starting a new plugin is very easy! (even though I still have to investigate more deeply the APIs :-p)
Regards,

Oxygen XML Editor Support wrote: Hi,
We do not yet have such support of setting pairs of key/value in the plugin.xml and then making them available to the Plugin Java classes. But it seems like an interesting improvement in order to control some configuration of a plugin without making changes in the Java code so we'll look into it.
Thanks. Actually, if we could have the current plugin directory, it would be very easy to implement such a feature. Either with property files, or even better with, you know, XML files...
My second (related) question is: how can we get the plugin dir via the API? And how to resolve resources in that dir?
Well, you could use the class loader to see from where the main plugin JAR library was loaded. [...] Another approach would be to find out the location where Oxygen is installed using code like: [...] and then append a "plugins/your-plugin-name" to that path.
Thanks! I use the second approach, as it looks like more robust, even though it requires to hard-code the plugin name in Java. The ideal solution would be to improve the API (e.g. on Plugin or PluginExtension) with a new method like: public File getPluginDir();
Congrats for the SDK! Starting a new plugin is very easy! (even though I still have to investigate more deeply the APIs :-p)
If you find any quirks or have trouble finding certain APIs please do not hesitate to contact us.
I will ;-) Thanks for your response, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/

Hi Florent, Well, to my shame it seems we already have a way. I looked more closely at the API and it seems we already have a method called:
ro.sync.exml.plugin.PluginDescriptor.getBaseDir()
So from a custom ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension implementation you could use code like this:
WorkspaceAccessPlugin.getInstance().getDescriptor().getBaseDir()
Regards, Radu Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 2/25/2012 3:26 PM, Florent Georges wrote:
Oxygen XML Editor Support wrote:
Hi,
We do not yet have such support of setting pairs of key/value in the plugin.xml and then making them available to the Plugin Java classes. But it seems like an interesting improvement in order to control some configuration of a plugin without making changes in the Java code so we'll look into it.
Thanks. Actually, if we could have the current plugin directory, it would be very easy to implement such a feature. Either with property files, or even better with, you know, XML files...
My second (related) question is: how can we get the plugin dir via the API? And how to resolve resources in that dir?
Well, you could use the class loader to see from where the main plugin JAR library was loaded. [...] Another approach would be to find out the location where Oxygen is installed using code like: [...] and then append a "plugins/your-plugin-name" to that path.
Thanks! I use the second approach, as it looks like more robust, even though it requires to hard-code the plugin name in Java. The ideal solution would be to improve the API (e.g. on Plugin or PluginExtension) with a new method like:
public File getPluginDir();
Congrats for the SDK! Starting a new plugin is very easy! (even though I still have to investigate more deeply the APIs :-p)
If you find any quirks or have trouble finding certain APIs please do not hesitate to contact us.
I will ;-)
Thanks for your response,
-- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/
participants (2)
-
Florent Georges
-
Oxygen XML Editor Support