Mar 8, 2018 11:53:14 AM seb leridon avatar   793

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.

Note: 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 [1].

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 <html-service> section (link-service) in the plugin configuration file:

<!-- Links Service -->
   <link-service-label>Link to my URIs</link-service-label>

Derivation of DefaultHTMLService (or DefaultLinkService)

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

public class MyHtmlService extends DefaultHtmlService
/ ** The plugin name. * /
private static final String PLUGIN_NAME = "myhtmlservice";

public String getPluginName ()

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.

example of ImageLibraryJspBean for the ImageLibrary plugin.

Insert the HTML code

the copy paste of the HTML code to insert will be in javascript by calling the method opener.insert_html (strCodeHTMLAInserer) .

Example from the imageLibrary:

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

   if (opener! = null)
      // The caller must provide an insert_html method
      opener.insert_html (_buffer);
      window.close ();
         alert ("HTML Editor unavailable!");

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 name = "Link or HTML code";
child = (url, '', 'toolbar = no, scrollbars = yes, status = no, location = no, directories = no, menubar = no, width = 450, height = 350');
child.focus ();

<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 for the HTML portlet:

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

theDoc.innerHTML = theDoc.innerHTML + strHTMLToInsert;