Lutece provides a base implementation for internal services to applcations, allowing them to load their resources. For example , the calendar plugin manages agendas and has an AgendaService service which enables it to load resources, in this case from agenda by means of an identfier.
The aims of this base implementation called Resource Service are to provide :
Here is the class diagram of the API :
Here is a minimal implementation of a service under a singleton form.
public class MyResourceService extends ResourceService
{
private static MyResourceService _singleton = new MyResourceService
private static final String PROPERTY_NAME = "myplugin.service.name";
private static final String PROPERTY_CACHE = "myplugin.service.cache";
private static final String PROPERTY_LOADERS = "myplugin.service.loaders";
/**
* Private constructor
*/
private MyResourceService
{
super();
setCacheKey( PROPERTY_CACHE );
setNameKey( PROPERTY_NAME );
}
/**
* Returns the instance of the singleton
*
* @return The instance of the singleton
*/
public static MyResourceService getInstance()
{
return _singleton;
}
/**
* Returns the property key that contains the loaders list
* @return A property key
*/
protected String getLoadersProperty( )
{
return PROPERTY_LOADERS;
}
/**
* Returns the Resource corresponding to the given name
*
* @param strResourceName The resource name
* @return the Resource corresponding to the given name
*/
public MyResource getMyResource( String strResourceName )
{
return ( MyResource ) getResource( strResourceName );
}
La configuration du service se fait dans le fichier properties. Les valeurs de base à configurer sont :
| Elément de configuration | Exemple dans le fichier properties |
|---|---|
| Nom du service | myplugin.service.name=Plugin MyPlugin - MyResources Loading Service |
| Activation du cache | myplugin.service.cache=true |
| Liste des loaders | myplugin.service.loaders=com.mycompany.myapp.service.MyResourceLoader |
L'implémentation minimum d'un ResourceLoader est la suivante :
import fr.paris.lutece.portal.service.resource.Resource;
import fr.paris.lutece.portal.service.resource.ResourceLoader;
import java.util.ArrayList;
/**
* MyResourceLoader
*/
public class MyResourceLoader implements ResourceLoader
{
/**
* Implementation of the ResourceLoader interface
* @return A collection of resources
*/
public Collection getResources( )
{
// Build a collection of all resources available by this loader
ArrayList listResources = new ArrayList( );
...
return listResources
}
/**
* Implementation of the ResourceLoader interface
* @param strId The resource Id
* @return The Resource
*/
public Resource getResource( String strId )
{
...
}
}