Create a LinkService
- Tree of InsertService
- Registration service
- Interface for selecting a link
- Inserting the return code
- Registration of services
- Derivation of DefaultHTMLService (or DefaultLinkService)
- Implementing HtmlServiceSelectionBean (or LinkServiceSelectionBean)
- Insert the HTML code
- Using a service
- Suggest a link to the insertion service
- Provide a javascript method insert_html()
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.
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.
Interface for selecting a link
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 --> <insert-services> <insert-service> <insert-service-id>my_insert_service</insert-service-id> <insert-service-name>myplugin.insertService.name</insert-service-name> <insert-service-label>myplugin.insertService.label</insert-service-label> <insert-service-bean-class>fr.paris.lutece.plugins.myplugin.web.MyInsertServiceJspBean</insert-service-bean-class> </insert-service> ... </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 opener.insert_html(_buffer); window.close(); } else { 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.
Suggest a link to the insertion service
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 = 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>
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; }