A plugin which provides an insertion service of HTML code or an insertion service of links must implement the HtmlService or LinkService interface.
Note : A plugin may consist of both a LinkService and an HtmlService ;
The service concerning 2 functions rather similar,we opted for a single service : InsertServiceManager.
Methods allowing fetching seperately « HtmlService » , « LinkService » or all InsertServices.
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 ).
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).
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> 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;
}
}
A JSPBean, implementing the HtmlServiceSelectionBean's interface and containing a getHtmlSelectorUI() method, is needed.
ImageLibraryJspBean example for ImageLibrary plugin.
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!" );
}
An example of InsertServide is given in the HTML plugin, by the editor_portlet_html.html template.
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>
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;
}