Plugin - access files bundled with plugin

Post here questions and problems related to oXygen frameworks/document types.
Krille
Posts: 33
Joined: Thu Nov 12, 2020 12:24 pm

Plugin - access files bundled with plugin

Post by Krille »

Hi!

I'm writing a plugin for importing files from classical text editor to (TEI-) XML. In the plugin, I'd like to access an XSLT stylesheet bundled in the plugin. It is in the plugins folder xsl/tei.xsl.

I'd like to pass this stylesheet to a Saxon transformer the plugin instantiates. But I don't know how to get the file path from my java extension class. Here is what I've tried:

Code: Select all

...
import java.nio.file.Paths;
...

public class CTEImportPluginExtension implements WorkspaceAccessPluginExtension {

    public static String getExtensionRoot() {
	// get the URL of the jar file
	File jarFile = new File(WorkspaceAccessPluginExtension.class.getProtectionDomain().getCodeSource().getLocation().getPath());
	String path = jarFile.getParent();
	return path;
    }

    private static String xsl = Paths.get(getExtensionRoot(), "xsl", "tei.xsl").toString();

  ...

}


The xsl variable points to /opt/oxygenxml/Oxygen%20XML%20Editor%2024/lib/xsl/tei.xsl, but I would expect it to be /opt/oxygenxml/Oxygen%20XML%20Editor%2024/plugins/oxygen-cte-importer/xsl/tei.xsl , as I have installed the plugin directory oxygen-cte-importer by sym-linking it to OXYGEN_INSTALL_DIR/plugin.

How can I access the stylesheet?

Kind regards,
Christian
Cosmin Duna
Site Admin
Posts: 120
Joined: Wed Dec 12, 2018 5:33 pm

Re: Plugin - access files bundled with plugin

Post by Cosmin Duna »

Hi Christian,

For obtaining the plugin directory you should get the instance of the class that extends "ro.sync.exml.plugin.Plugin" and from this instance, get the "PluginDescriptor" using the "getDescriptor" method. From this object you can find the plugin's directory using the "ro.sync.exml.plugin.PluginDescriptor.getBaseDir()" method.
For example:

Code: Select all

File baseDir = CTEImportPlugin.getInstance().getDescriptor().getBaseDir();
File teiXsl = new File (baseDir, "xsl/tei.xsl");
Also, make sure that the "xsl" folder will be packed into the jar file of the add-on. For this you should add the following fileset element into the "assembly.xml" file:

Code: Select all

     <fileSet>
	      <directory>xsl</directory>
	      <outputDirectory>xsl</outputDirectory>
	      <includes>
	        <include>**/*</include>
	      </includes>
    </fileSet>
Best regards,
Cosmin
Cosmin Duna
<oXygen/> XML Editor
http://www.oxygenxml.com
Krille
Posts: 33
Joined: Thu Nov 12, 2020 12:24 pm

Re: Plugin - access files bundled with plugin

Post by Krille »

Hi Cosmin!

Great, that works. Thanks.

I will post a link to my source code as soon as it's on a public repo.

Kind regards,
Christian
Post Reply