Page 1 of 1
Frameworks JAR talking to Plugin JAR
Posted: Thu Jul 28, 2022 1:59 pm
by vishwavaranasi
Hello Team ,
We have a oxygen plugin as jar placed inside C:\Program Files\Oxygen XML Editor 24\plugins , this plugin has some menus and has some business logic which will connect to a Database to retrieve some folders/files.
We have framework project under C:\Program Files\Oxygen XML Editor 24\frameworks\"myown-oxygen-dita " which has some custom java code to customize the Menus under "DITA" , when we open the menu item , the menu item opens a swing window and that swing window has to talk to the business logic inside the oxygen plugin jar to list files/folders.
would be great please suggest how to make this happen?
Thanks,
vishwa
Re: Frameworks JAR talking to Plugin JAR
Posted: Thu Jul 28, 2022 2:08 pm
by Radu
Hi,
Usually Oxygen creates separate java class loaders for each plugin and framework so they cannot communicate with each other.
If you edit in the Oxygen Preferences->"Document Type Associations" page your custom framework, in the Classpath tab you can set the ID of the parent plugin:
https://www.oxygenxml.com/doc/versions/ ... yn_bgk_54b
and this should allow your plugin's code to call static methods from the plugin side.
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Thu Jul 28, 2022 2:44 pm
by vishwavaranasi
Thanks Radu for quick response.
what does it mean "and this should allow your plugin's code to call static methods from the plugin side.?"
am not understanding this sorry.
Re: Frameworks JAR talking to Plugin JAR
Posted: Fri Jul 29, 2022 8:03 am
by Radu
Hi,
For example if in your plugin extension you keep a static reference to the extension instance like this:
Code: Select all
public class MyPluginExtension implements WorkspaceAccessPluginExtension {
private static MyPluginExtension instance;
/**
* @return Returns the instance.
*/
public static MyPluginExtension getInstance() {
return instance;
}
@Override
public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
this.instance = this;
}
public void doSomething() {
//
}
public boolean applicationClosing() {
return true;
}
}
On the framework side, in the framework's Java code you could do something like "MyPluginExtension.getInstance().doSomething()".
To compile the framework's Java code you would need the plugin's JAR libraries in the classpath but when Oxygen is running you will not need in the framework's Classpath list references to the plugin's libraries if you specify in the Classpath list the parent plugin ID.
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Fri Jul 29, 2022 9:31 am
by vishwavaranasi
Thanks Radu for the detailed explanation , we will try this , and let you know how this goes.
Thanks,
vishwa
Re: Frameworks JAR talking to Plugin JAR
Posted: Mon Aug 01, 2022 3:47 pm
by vishwavaranasi
Hi Radu ....here one more blocker I see
in my frameworks jar , i need the reference of StandalonePluginWorkspace of my plugin extension , so what am doing here
--------------------------------------------------------------------------------------------------------------------------------------------------------------
MyPluginExtension
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Code: Select all
public class MyPluginExtension implements WorkspaceAccessPluginExtension {
private static MyPluginExtension instance;
private static StandalonePluginWorkspace myPluginWorkspace;
/**
* @return Returns the instance.
*/
public static MyPluginExtension getInstance() {
return instance;
}
@Override
public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
this.instance = this;
/** here am setting the pluginWorkspaceAccess -call setWorkspace method*/
setWorkspace(pluginWorkspaceAccess);
} //applicationStarted closed
public void doSomething() {
//
}
public boolean applicationClosing() {
return true;
}
public static StandalonePluginWorkspace getWorkspace() {
return myPluginWorkspace;
}
public static void setWorkspace(StandalonePluginWorkspace pluginWorkspaceAccess) {
myPluginWorkspace = pluginWorkspaceAccess;
}
--------------------------------------------------------------------------------------
in my frameworks jar ,
---------------------------------------------------------------------------------------------------------------------------------------------------------
getting workspace acess using MyPluginExtension.getWorkspace() is always returning null ,
here is my java class inside frameworks jar
Code: Select all
if (AuthorNode.NODE_TYPE_ELEMENT == authorNode.getType()) {
AuthorNode parent = authorNode.getParent();
if (parent != null) {
WSEditor editor =null;
if (AuthorNode.NODE_NAME_DOCUMENT.equals(parent.getName())) {
URL location = authorNode.getXMLBaseURL();
if(MyPluginExtension.getWorkspace()!=null) {
editor = MyPluginExtension.getWorkspace().getEditorAccess(location, 0);
}else{
System.out.println("Workspace object is null");
if (editor != null && editor.getCurrentPage() instanceof WSAuthorEditorPage) {
WSAuthorEditorPage authorPage = (WSAuthorEditorPage)editor.getCurrentPage();
if (!authorPage.isEditable()) {
styles.setProperty(Styles.KEY_BACKGROUND_COLOR, Color.COLOR_LIGHT_GRAY);
}
}
}
// WSEditor editor = AuthoringBridge.getWorkspace().getEditorAccess(location, 0);
}
}
}
Would you please help me here , is this correct way am doing?
Re: Frameworks JAR talking to Plugin JAR
Posted: Mon Aug 01, 2022 4:12 pm
by Radu
Hi,
We have our own a singleton access to the plugin workspace which you can use in your framework's Java code:
Code: Select all
ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace();
So that singleton access we offer should always work on the plugin side.
Other than that, what you tried should work as long as in the Oxygen Preferences->"Document Type Associations" page you edit your custom framework and in the Classpath tab you set the ID of the parent plugin. The plugin ID is specified in the plugin.xml file.
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Mon Aug 01, 2022 8:29 pm
by vishwavaranasi
I did this step
Oxygen Preferences->"Document Type Associations" page you edit your custom framework and in the Classpath tab you set the ID of the parent plugin. The plugin ID is specified in the plugin.xml file.
but i am getting an error
22:50:25.964 [main] ERROR ro.sync.exml.plugin.PluginManager - Failed to inject dependency to class com.xxx.xxx.xxx.workspace.xxxWorkspaceAccessPluginExtension
Re: Frameworks JAR talking to Plugin JAR
Posted: Tue Aug 02, 2022 7:40 am
by Radu
Hi,
I'm afraid I do not know why this does not work for your particular case. Can you paste the entire contents of your plugin.xml file in a followup email?
One more thing, have you tried using the alternative I gave you, the "ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace()" singleton access in your framework's Java code?
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Tue Aug 02, 2022 8:24 am
by vishwavaranasi
Yes Radu i used this
ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace()" singleton access in my frameworks code.
and the Document type associations used id as com.xxx.xxx.xxx.workspace.WorkspaceAccess as parent plugin ID
here is the plugin.xml in mycase
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!-- The plugin.dtd file is located in the OXYGEN_INSATALL_DIR/plugins directory -->
<!DOCTYPE plugin SYSTEM "../plugin.dtd">
<plugin
id="com.xxx.xxx.xxx.workspace.WorkspaceAccess"
name="xxxWorkspaceAccess"
description="Test"
version="1.0-SNAPSHOT"
vendor="oXygen XML"
class="com.xxx.xxx.xxx.workspace.WorkspaceAccessPlugin"
classLoaderType="preferReferencedResources">
<runtime>
<librariesFolder name="lib" />
<library name="target/classes" />
<librariesFolder name="target/lib" />
</runtime>
<extension type="WorkspaceAccess"
class="com.xxx.xxx.xxx.workspace.xxxWorkspaceAccessPluginExtension"/>
<!--The sample view which will present messages from the sample plugin.-->
<view id="xxxxWorkspaceAccessID" initialSide="WEST" initialRow="0" description="xxxOxygenWorkspace" />
<!--The sample toolbar which will present messages from the sample plugin.-->
<toolbar id="xxxxWorkspaceAccessID" initialSide="NORTH" initialRow="1"/>
</plugin>
Re: Frameworks JAR talking to Plugin JAR
Posted: Tue Aug 02, 2022 10:43 am
by Radu
Hi,
I'm afraid that without reproducing the problem on my side and adding logging in our code I do not know precisely why you get that "Failed to inject dependency to class" error in the console.
In my opinion, you should try to edit your framework customization and remove the reference to the parent plugin ID, then use in the framework Java code the "ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace()" singleton access that we provide.
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Tue Aug 02, 2022 8:40 pm
by vishwavaranasi
surprisingly this error "Failed to inject dependency to class" error in the console. not showing anymore.
but wanted to ask you here
We have our java.nio custom filesystem , and we are creating and initializing custom filesystem inside the method
Code: Select all
private static FileSystem customfileSystemObject =null;
public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess)
{
customfileSystemObject initialized and created
/** and then i used a static method setFileSystem() out side applicationStarted to set the the same.
setFileSystem(customfileSystemObject);
}
/**
* @param usethisFileSystem
*/
public static void setFileSystem(FileSystem usethisFileSystem) {
customfileSystemObject = usethisFileSystem;
}
/**
* @return
*/
public static FileSystem getFileSystem() {
return customfileSystemObject ;
}
and then inside frameworks jar
tried this
Code: Select all
FileSystem customfileSystemObject = xxxWorkspaceAccessPluginExtension.getFileSystem();
but my customfileSystemObject is always returning null
would you please help me here.
Re: Frameworks JAR talking to Plugin JAR
Posted: Wed Aug 03, 2022 7:51 am
by Radu
Hi,
A hack (which should work) would be to store the file system object on the plugin side in the UIManager map:
Code: Select all
javax.swing.UIManager.put("MY_KEY", filesystem);
and on the framework Java code side to retrieve it like:
Code: Select all
FileSystem fs = javax.swing.UIManager.get("MY_KEY");
Other than that, the elegant way would have been to add the parent plugin ID in the framework configuration, but this did not seem to work for you.
And I do not understand why it did not. The framework configuration has a "Classpath" list, it should have referenced in that classpath list JAR libraries which are not used by the plugin itself. So I think this would have worked if you had separate JAR libraries containing the Java code for the framework and for the plugin.
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Fri Aug 05, 2022 7:27 pm
by vishwavaranasi
Thanks Radu , the trick
(FileSystem) UIManager.get("KEY_TO_FILE_SYSTEM"); worked for me.
as we have customized the Menu Item under the menu "DITA" and now we are able to invoke the plugin classes from the frameworks.
for the first time the menu items are showing fine , but next time the DITA menu items are showing with a overlapped as shown below
![Image]()
error.png
any suggestions please?
Re: Frameworks JAR talking to Plugin JAR
Posted: Fri Aug 05, 2022 7:56 pm
by Radu
Hi,
Maybe you could have started a new thread for this other problem. How exactly did you customize the top level "DITA" menu? Can you give me some sample source code similar to how you customize it on your side?
Regards,
Radu
Re: Frameworks JAR talking to Plugin JAR
Posted: Thu Aug 11, 2022 7:11 am
by vishwavaranasi
Thanks Radu, soon I will write my implementation sample code , we will see if that createing any other threads.
Thanks,
vishwa