Crate a new LinkService

Folder structure of InsertService

A plugin which provides an insertion service of HTML code or an insertion service of links must implement the HtmlService or LinkService interface.

The InsertService is composed by :

  • A parent interface generalizing the notion of InsertService and providing an abstract method getSelectorUI which gives access to the the user interface of the object to be inserted ;
  • An LinkService interface modelizing the link insertion Services and providing a method returning the LinkServiceSelectionBean selection class;
  • A HtmlService interface modelizing the HTML code insertion services and providing a method returning the HtmlServiceSelectionBean selection class;
  • abstract classes,DefaultLinkService and DefaultHtmlService, facilitating implementation of the 2 interfaces above.

Note : A plugin may consist of both a LinkService and an HtmlService ;

Saving Service

The service concerning 2 functions rather similar,we opted for a single service : InsertServiceManager.

Methods allowing fetching seperately « HtmlService » , « LinkService » or all InsertServices.

Link selection's interace

As in the Lutece 1.0 version, the link selection or object to be inserted in an HTML editor is done through a popup window.

This allows to keep user session and avoids persisting data , already entered (saving data in the HTML editor is performed before calling the insertion service ).

Return code insertion

Implementation depends on the previous choice and the wish to persist or not already entered data.

Insertion of HTML code corresponding to the selected object is done through a javascript function proposed by the caller :

insert_html (String ChaineAInsérer).

Saving services

Implementations of InsertService are saved on plugin loading. A <html-service> (link-service) section must be added in the plugin'sconfiguration file :

<!-- Links Service -->
<link-service>
    <link-service-id>mylinkservice</link-service-id>
    <link-service-class>fr.paris.lutece.plugins.mylinkservice.service.MyLinkService</link-service-class>
    <link-service-bean-class>fr.paris.lutece.plugins.mylinkservice.web.MyLinkServiceJspBean</link-service-bean-class>
    <link-service-label>Link to my URIs</link-service-label>
</link-service>    

Extension of DefaultHTMLService (or DefaultLinkService)

Extend DefaultHTMLService (resp. DefaultLinkService) by implementing getPluginName method :

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

    public String getPluginName() 
    {
        return PLUGIN_NAME;
    }
}
                        

Implementation of HtmlServiceSelectionBean (or LinkServiceSelectionBean)

A JSPBean, implementing the HtmlServiceSelectionBean's interface and containing a getHtmlSelectorUI() method, is needed.

ImageLibraryJspBean example for ImageLibrary plugin.

Insertion of HTML code

The cut and paste of HTML code to be inserted is done in javascript by calling the opener.insert_html(strCodeHTMLAInserer) method.

Exemple taken from 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();
} 
else 
{
   alert("HTML editor is not accessible!" );
}
                        

Using a service

An example of InsertServide is given in the HTML plugin, by the editor_portlet_html.html template.

Submitting a link to insertion service

Calling the GetAvailableServices.jsp JSP, by using ,for example, the following code :

function create_insert_window()
{
   var url="GetAvailableServices.jsp";
   var nom = "Link or code HTML";
   child = window.open(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>
                        

Providing a insert_html() method

It refers to providing a javascript function insert_html in the calling page, which adds HTML code returned by the insertion service.

example for an HTML portlet :

function insert_html(strHTMLToInsert)

{
   //TEXT
   document.Form.html_content.value = document.Form.html_content.value + strHTMLToInsert;

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