Nov 9, 2021 3:48:01 PM Thomas Dumont avatar

Create a LinkService

Tree of InsertService

A plugin that offers an HTML code insertion service or a link insertion service will have to implement a HtmlService or LinkService interface.

The InsertService tree is composed as follows :

  • an ancestor interface generalizing the notion of InsertService and providing an abstract method getSelectorUI giving access to a selection GUI of the object to be inserted
  • a LinkService interface modeling the Link insertion services and providing a method returning an implementing class of selection LinkServiceSelectionBean
  • a HtmlService interface modeling the HTML insertion services and providing a method returning an implementing class of selection HtmlServiceSelectionBean
  • abstract classes, DefaultLinkService and DefaultHtmlService, facilitating implementations of the 2 interfaces above.

A plugin can offer both a LinkService and an HtmlService.

Registration service

The service concerning two very similar features, so we decided to create only one service Registration InsertServiceManager.

Methods are provided to recover separately HtmlService or LinkService or all InsertServices.

As in version 1.0 of Lutece, the selection of links or to insert into an HTML editor is via a window popup type.

This allows one hand not to lose the user and other part of not having to manage the persistence of the data entered in the calling party (saving unsaved data in the HTML editor before calling the insert function).

Inserting the return code

The implementation is conditioned by the previous choice and the will not worry about data storage entered in the appellant.

The insertion of the HTML code corresponding to the selected object done directly via a JavaScript function that the caller must propose : insert_html( String StringInsert ).

Registration of services

Registration of InsertService implementations is performed when launching the application when loading plugins.

This is to add a <insert-service> section in the plugin configuration file :

<!-- Insert Services -->

Derivation of DefaultHTMLService (or DefaultLinkService)

Derive DefaultHTMLService (or DefaultLinkService) by implementing the getPluginName( ) method :

public class MyHtmlService extends DefaultHtmlService 
    private static final String PLUGIN_NAME = "myhtmlservice";

    public String getPluginName( ) 
        return PLUGIN_NAME;

Implementing HtmlServiceSelectionBean (or LinkServiceSelectionBean)

This is to provide a JSPBean that implements the HtmlServiceSelectionBean interface by providing a getHtmlSelectorUI( ) method, returning an HMI to select the object to insert (an example is ImageLibraryJspBean for the ImageLibrary plugin).

Insert the HTML code

The insertion of the HTML code will be made in javascript by calling the method opener.insert_html( strCodeHtmlToInsert ).

Example from the imageLibrary :

_buffer = _buffer + _hspace + _vspace + _width + _height + _align + ">";

if (opener != null)
    // The caller must provide an insert_html method
    alert("Editeur HTML indisponible !" );

Using a service

An example of using the InsertService is given by the HTML plugin, through the template editor_portlet_html.html.

It's calling the JSP GetAvailableServices.jsp, for example using the following code :

function create_insert_window ()
    var url="GetAvailableServices.jsp";
    var nom = "Lien ou code HTML";
    child =,'','toolbar=no, scrollbars=yes, status=no, location=no, directories=no, menubar=no, width=450, height=350');

<a href="#" onClick="create_insert_window();"> Insert Link or HTML </a>

Provide a javascript method insert_html()

This is to provide, in the page calling the insertion service, a javascript function insert_html realizing adding the HTML code returned by the insert service.

Example from the HTML portlet :

function insert_html(strHTMLToInsert)
    // TEXT
    document.Form.html_content.value = document.Form.html_content.value + strHTMLToInsert;

    // HTML
    theDoc.innerHTML = theDoc.innerHTML + strHTMLToInsert;