Finding the file path to a database file embedded in an extension (.oxt)

As already mentionend in my previous post, one of the advantages of an extension from a user perspective is that you install everything from one file, including an eventually needed database file as is the case for the Jitenize extension. unpacks the contents of an .oxt file and puts it in a separate directory before executing it. The place of this directory depends on the operating system, whether the extension is installed for a single or for all users and the path contains some random directory names. For example on my Ubuntu installation the Jitenize extension can be found at


For writing a platform independent extension you therefore need  a way to

  1. find the path to the directory in which the extension sits
  2. extend the path with the file name of the database file using the correct (platform dependent) delimiter sign (“/”, “\” or “:”)

Fortunately the UNO framework has some support for doing this but I had to make intensive usage of Google to find out how and some code snippets that I found simply did not work. So I thought it would be a good idea to publish my final solution here:

// Create path to dictionary database in UNO component package cache in a platform independant way
//The dictionary database of the Jitenize extension is always in the root directory of the UNO extension package
String databasePath;
try {
   XPackageInformationProvider xPackageInformationProvider = PackageInformationProvider.get(m_xContext);
   String packageLocation = xPackageInformationProvider.getPackageLocation("com.fuyosoft.jitenize");
   XFileIdentifierConverter xFileConverter = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class, m_xContext.getServiceManager().createInstanceWithContext("", m_xContext));
   databasePath = xFileConverter.getSystemPathFromFileURL(packageLocation + "/dict.sqlite");
} catch ( ex) {
   databasePath = "Exception during construction of path to dictionary database!";

com.fuyosoft.jitenize is the identifier of the extension specified in the description.xml file as explained in this post.

This has been tested with Ubuntu 10.04 and Windows XP. Feedback from any other operating system platform highly welcome!

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/38/d73375733/htdocs/wordpress/wp-includes/class-wp-comment-query.php on line 405

2 thoughts on “Finding the file path to a database file embedded in an extension (.oxt)

  1. Jorg,

    I am having a bit of trouble getting your Jitenize extension to work in OpenOffice and was hoping you could help. When I try to add Jitenize to OpenOfficeWriter via the Extension Manager tab, I receive the following error:

    “bad root element in file:///C:/users/ … /jintenize.xcu”

    After the installation process has completed, the Extension Manager lists the status of Jitenize as “unknown”. It then prompts me with the bad root element error message each time I try to enable the Jitenize extension.

    Other environmental details:

    Windows 7 Pro (86x)
    OpenOffice 3.4
    Jitenize 8.3

    Thanks in advance for your help!


Leave a Reply

Your email address will not be published. Required fields are marked *