Creating LibreOffice Extensions

This topic was published by and viewed 4447 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author
    Posts

  • DevynCJohnson
    Keymaster
    • Topics - 437
    • @devyncjohnson

    LibreOffice is a popular open-source alternative to Microsoft-Office. Like many other popular pieces of software, LibreOffice's abilities can be enhanced and expanded by using "extensions" (addons). With extensions, users can have additional gallery objects, calculation tasks (for LibreOffice Calc), dictionaries, and many other special features that people may need. Learning how to make LibreOffice extensions can further help open-source developers to contribute to the world and make people's lives and jobs easier and more efficient.

    NOTE: This article primarily explains how to make non-coded extensions. However, there are some important details and links that will help developers wanting to make coded extensions.

    General Concepts

    LibreOffice extensions can be obtained and uploaded/submitted at http://extensions.libreoffice.org/. Downloading and studying the extensions of other developers can help people learn how to design extensions. Also, it may be possible to find a developer that can provide tips and help. OpenOffice extensions are almost always compatible with LibreOffice extensions (and vice versa), so any documentation for OpenOffice is also applies to LibreOffice.

    FUN FACT: LibreOffice is a fork of OpenOffice.

    LibreOffice extension files use the *.oxt file-extension. "oxt" stands for "OpenOffice ExTension". The file is a zip file that uses a different extension. If an extension file is uncompressed, it will contain the below listed files and directories.

    NOTE: This article will use the "Gallery of Danger Signs" (https://extensions.libreoffice.org/extensions/gallery-of-danger-signs) for most of the examples and "sample files" (seen near the end of the article).

    • Directories
      • gallery - Contains *.sdg, *.sdv, *.str, and *.thm files
      • license - Contains the license file like the LGPL license
      • META-INF - Contains the "manifest.xml" file which lists the paths to the extensions important files
      • pkg-desc - Contains multiple text files each describing the extension in different languages
      • Release-notes - Changelog as a plain-text-file
    • Files
      • description.xml - Info about the extension such as minimal LibreOffice version, path to release notes, version, etc.
      • mimetype - Plain-text-file containing the mimetype string of LibreOffice extensions
      • Paths.xcu - Informs the extension installer where to place the files

    There are many choices of programming languages to use when creating extensions. Such languages include C++, Java, JavaScript, LibreOffice Basic (LibreOffice dialect), and Python. If using Java or C++ to create an extension, the LibreOffice SDK is required (http://api.libreoffice.org/docs/install.html). There are special instructions for particular programming languages used in LibreOffice extensions, but this article will not explain the programming-language-specific needs or the programming languages themselves.

    FUN FACT: LibreOffice Basic is a derivative of OpenOffice Basic (also called OOoBasic, StarOffice Basic, or StarBasic).

    UNO (Universal Network Objects) is an interface-based component model that allows many programming languages to seamlessly work well in extensions. It also makes it possible for LibreOffice to support multiple programming languages as extensions. Extensions and code written as UNO objects run in the UNO Runtime Environment (URE). This is how LibreOffice extensions written in C++ can run on many machines and operating systems without needing to have multiple forms/builds of the extension for each platform.

    There are a few types of extensions; not all extensions use/need programming. Some extension types include template extensions, gallery extensions, spell-checker extensions, etc. Some of these extensions may use a slightly different file and directory layout inside the OXT file than the above list. For instance, only gallery extensions will contain the "gallery" directory.

    Creating an Extension

    All types of extensions are created nearly the same way. However, there are some minor differences, but once one extension type is understood, then the others are easy to make. For example, gallery extensions will have a "gallery" directory while template extensions will have a "templates" folder. Also remember to use the proper extension-type name in the "Paths.xcu" file in the "oor:name" attribute of the "node" XML tag. For instance, "AutoText" extensions would use [code]node oor:name="AutoText"[/code]

    All of the files and directories needed by the extension should be placed in a single folder. This folder must be named after the extension and include the version number (such as "Sample.1.0"). Once the extension is ready for testing or ready to be used, compress the folder as a zip-file (*.zip) and then change the extension to "*.oxt".

    To create extensions, create the required folders and files such as Paths.xcu, description.xml, META-INF, manifest.xml, license, and all other needed files and directories. Use the sample code in this article to properly place the needed information in the files. Replace the sample values with ones pertaining to the extension being made.

    Below are some additional instructions for specific types of extensions.

    Creating Template Extensions

    Template extensions have a "templates" directory (among the other needed files) that contains document-template files. Create LibreOffice template files and place them in the "templates" folder. If a developer wants to organize the documents into template categories, then sub-directories can be created and named after the category. The name of a template will come from the document metadata/properties; if none are set, then the filename will be used. Localization is possible if the "groupuinames.xml" file is place in the "templates" folder.

    Creating Gallery Extensions

    Gallery extensions contain a "gallery" directory as well as the files needed by extensions. To create a gallery extension, prepare the files and folders that are typically used in extensions. Afterwards, create a new "theme" in the gallery of LibreOffice Draw. Next, insert the desired images into LibreOffice Draw and then drag the images into the created theme. Developers can insert and add one or a few images at a time if desired. Once done, right-click each image in the gallery theme and set a "title" for each image. After completing all of those tasks, go to the location that was mentioned when creating the theme. In that file location, there will be several *.sdg, *.sdv, *.str, and *.thm files. Copy all of these to the extension's "gallery" directory. Lastly, compress the extension folder and test the extension.

    Additional Details

    In "description.xml", within the "dependencies" XML section, the minimal LibreOffice version is declared. If "LibreOffice-minimal-version" is in that section, then the extension contains LibreOffice-specific features while "OpenOffice.org-minimal-version" indicates that the extension works on OpenOffice and LibreOffice.

    The "Paths.xcu" file informs the extension installer where to place the files. In the file, the path is specified using a variable that ensures extensions are installed with other extensions across all computer systems. There is an attribute pertaining to the path of some extensions to declare that the files be merged with other contents and folders if new files and folders do not exist. This attribute is "fuse" (seen in the sample file in a different section of this article) and it is used with template extensions.

    In the "description.xml" file, the "identifier value" must use an identifier. Developers should use the reversed domain-name of their website. For instance, if Linux.org made an extension, then its identifier would be "org.linux".

    An icon for the extension can be made by creating a 42x42 pixel Jpeg or PNG image. Then, the image's pathname must be specified in the "description.xml" file (see the examples in this article).

    Sometimes, it may be necessary to make a platform-specific extension. The target platform can be specified in the "description.xml" file in the "platform" XML tag (https://wiki.openoffice.org/wiki/Documentation/DevGuide/Extensions/Target_Platform).

    Submitting Extensions

    Once an extension is complete and tested, developers can submit their extensions (if desired). Extensions that work on OpenOffice can be submitted to http://extensions.services.openoffice.org/node/add/project-project after the developer obtains an account. However, it is best to read the submission instructions first - https://wiki.openoffice.org/wiki/Extensions/website/submission. The same instructions are useful prior to submitting LibreOffice extensions - http://extensions.libreoffice.org/@@hosting-your-extension.

    Sample Files

    The below code comes from the "Gallery of Danger Signs" (https://extensions.libreoffice.org/extensions/gallery-of-danger-signs) LibreOffice extension.

    description.xml

    NOTE: Code for some of the spoken languages have been removed from the sample code for easier viewing.

    <?xml version="1.0" encoding="UTF-8"?>
    <description
        xmlns="http://openoffice.org/extensions/description/2006"
        xmlns:d="http://openoffice.org/extensions/description/2006"
        xmlns:l="http://libreoffice.org/extensions/description/2011"
        xmlns:xlink="http://www.w3.org/1999/xlink">
    
            <identifier value="fr.jumbo444.gallery.Signs.Danger2" />
            <version value="2.1.0" />
            <dependencies>
                 <l:LibreOffice-minimal-version value="3.5" d:name="LibreOffice 3.5" />
            </dependencies>
            <release-notes>
                <src xlink:href="release-notes/release-notes_en.txt" lang="en" />
                <src xlink:href="release-notes/release-notes_fr.txt" lang="fr" />
            </release-notes>
            <display-name>
                <name lang="en">Gallery of hazard signs</name>
                <name lang="fr">Gallery des symboles de dangers</name>
                <name lang="es">Galería de símbolos de peligro</name>
                <name lang="de">Gallery von Gefahrzeichen</name>
                <name lang="af">Gallery: Tekens- gevare</name>
                <name lang="am">Gallery: Signage - Hazards</name>
                <name lang="an">Gallery: Signage - Hazards</name>
                <name lang="be">Gallery: прыкметы - небяспекі </name>
                <name lang="bg">Gallery: знак - риск </name>
                <name lang="bn">Gallery: Signage - Hazards</name>
                <name lang="bn-IN">Gallery: Signage - Hazards</name>
                <name lang="bo">Gallery: Signage - Hazards</name>
                <name lang="br">Gallery: Signage - Hazards</name>
                <name lang="brx">Gallery: Signage - Hazards</name>
                <name lang="bs">Gallery: znakovi - opasnosti </name>
                <name lang="ca">Gallery: Signes - Perills </name>
                <name lang="ca-XV">Gallery: Signes - Perills </name>
                <name lang="cs">Gallery: známky - nebezpečí </name>
                <name lang="cy">Gallery: Arwyddion - peryglon </name>
                <name lang="da">Gallery: Skiltning - farer </name>
                <name lang="dgo">Gallery: Signage - Hazards</name>
                <name lang="dz">Gallery: Signage - Hazards</name>
                <name lang="el">Gallery: Σημάδια - Κίνδυνοι </name>
                <name lang="eo">Gallery: Signoj - danĝeroj </name>
                <name lang="et">Gallery: Märgid - Ohtude </name>
                <name lang="eu">Gallery: Errotuluak - arriskuak </name>
                <name lang="fi">Gallery: Kyltti- vaarat </name>
                <name lang="ga">Gallery: Comharthaí - guaiseacha </name>
                <name lang="gd">Gallery: Signage - Hazards</name>
                <name lang="gl">Gallery: Signos - perigos </name>
                <name lang="hr">Gallery: Znakovi - Opasnosti </name>
                <name lang="hu">Gallery: Jelek - veszélyek </name>
                <name lang="id">Gallery: Tanda - bahaya </name>
                <name lang="is">Gallery: Merki - hættur </name>
                <name lang="it">Gallery: Segnaletica - rischi </name>
                <name lang="kk">Gallery: Signage - Hazards</name>
                <name lang="kl">Gallery: Signage - Hazards</name>
                <name lang="kok">Gallery: Signage - Hazards</name>
                <name lang="ks">Gallery: Signage - Hazards</name>
                <name lang="ku">Gallery: Signage - Hazards</name>
                <name lang="ky">Gallery: Signage - Hazards</name>
                <name lang="lb">Gallery: Signage - Hazards</name>
                <name lang="lt">Gallery: ženklai - pavojai </name>
                <name lang="lv">Gallery: pazīmes - apdraudējumi </name>
                <name lang="mai">Gallery: Signage - Hazards</name>
                <name lang="mk">Gallery: знаци - опасности </name>
                <name lang="ml">Gallery: Signage - Hazards</name>
                <name lang="mn">Gallery: Signage - Hazards</name>
                <name lang="mni">Gallery: Signage - Hazards</name>
                <name lang="my">Gallery: Signage - Hazards</name>
                <name lang="nb">Gallery: Signage - farer </name>
                <name lang="ne">Gallery: Signage - Hazards</name>
                <name lang="nl">Gallery: Tekenen - gevaren </name>
                <name lang="nn">Gallery: Signage - farer </name>
                <name lang="nr">Gallery: Signage - Hazards</name>
                <name lang="nso">Gallery: Signage - Hazards</name>
                <name lang="oc">Gallery: Signage - Hazards</name>
                <name lang="om">Gallery: Signage - Hazards</name>
                <name lang="or">Gallery: Signage - Hazards</name>
                <name lang="pa-IN">Gallery: Signage - Hazards</name>
                <name lang="pl">Gallery: Znaki - Zagrożenia </name>
                <name lang="pt">Gallery: Sinais - perigos </name>
                <name lang="pt-BR">Gallery: Sinais - perigos </name>
                <name lang="ro">Gallery: Semne - pericole </name>
                <name lang="ru">Gallery: знак - опасности </name>
                <name lang="rw">Gallery: Signage - Hazards</name>
                <name lang="sa-IN">Gallery: Signage - Hazards</name>
                <name lang="sah">Gallery: Signage - Hazards</name>
                <name lang="sat">Gallery: Signage - Hazards</name>
                <name lang="sd">Gallery: Signage - Hazards</name>
                <name lang="sh">Gallery: Signage - Hazards</name>
                <name lang="si">Gallery: Signage - Hazards</name>
                <name lang="sid">Gallery: Signage - Hazards</name>
                <name lang="sk">Gallery: známky - nebezpečenstvo </name>
                <name lang="sl">Gallery: znaki - nevarnosti </name>
                <name lang="sq">Gallery: Signage - Rreziqet </name>
                <name lang="sr">Gallery: Знаци - Опасности </name>
                <name lang="ss">Gallery: Signage - Hazards</name>
                <name lang="st">Gallery: Signage - Hazards</name>
                <name lang="sv">Gallery: Tecken - Farliga </name>
                <name lang="zu">Gallery: Signage - Hazards</name>
            </display-name>
            <platform value="all" />
            <icon>
                <default xlink:href="feu42.png" />
            </icon>
    </description>

    groupuinames.xml

    NOTE: This sample code is from https://wiki.openoffice.org/wiki/Non-code_extensions

    <?xml version="1.0" encoding="UTF-8"?>
    <groupuinames:template-group-list xmlns:groupuinames="http://openoffice.org/2006/groupuinames">
            <groupuinames:template-group groupuinames:name="educate" 
                    groupuinames:default-ui-name="Bildung" />
            <groupuinames:template-group groupuinames:name="layout" 
                    groupuinames:default-ui-name="Präsentationshintergründe" />
            <groupuinames:template-group groupuinames:name="misc" 
                    groupuinames:default-ui-name="Diverses" />
            <groupuinames:template-group groupuinames:name="officorr" 
                    groupuinames:default-ui-name="Geschäftliche Korrespondenz" />
            <groupuinames:template-group groupuinames:name="offimisc" 
                    groupuinames:default-ui-name="Sonstige geschäftliche Dokumente" />
            <groupuinames:template-group groupuinames:name="personal" 
                    groupuinames:default-ui-name="Private Korrespondenz und Dokumente" />
            <groupuinames:template-group groupuinames:name="presnt" 
                    groupuinames:default-ui-name="Präsentationen" />
    </groupuinames:template-group-list>

    Paths.xcu

    <?xml version='1.0' encoding='UTF-8'?>
    <oor:component-data 
        oor:package="org.openoffice.Office" 
        oor:name="Paths" 
        xmlns:install="http://openoffice.org/2004/installation" 
        xmlns:oor="http://openoffice.org/2001/registry" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
        <node oor:name="Paths">
            <node oor:name="Gallery" oor:op="fuse">
                <node oor:name="InternalPaths">
                    <node oor:name="%origin%/gallery" oor:op="fuse"/>
                </node>
            </node>
        </node>
    </oor:component-data>

    Further Reading

Viewing 1 post (of 1 total)