1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.leaflet.service;
35
36 import fr.paris.lutece.portal.service.datastore.DatastoreService;
37 import fr.paris.lutece.portal.service.spring.SpringContextService;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39 import fr.paris.lutece.util.ReferenceItem;
40 import fr.paris.lutece.util.ReferenceList;
41
42 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
43
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.HashSet;
47
48
49
50
51
52 public class IconService
53 {
54 private static final String BEAN_PREFIX = "leaflet-icon-provider-";
55 private static final String DATASTORE_PREFIX = "leaflet.icon.";
56 private static final String DATASTORE_ICONS_PREFIX = DATASTORE_PREFIX + "icons.";
57
58
59
60 private IconService( )
61 {
62 }
63
64
65
66
67
68
69 public static Collection<String> getList( )
70 {
71 ReferenceList referenceList = DatastoreService.getDataByPrefix( DATASTORE_ICONS_PREFIX );
72 HashSet<String> hashSet = new HashSet<String>( );
73
74 for ( ReferenceItem referenceItem : referenceList )
75 {
76 String codeSuffix = referenceItem.getCode( ).substring( DATASTORE_ICONS_PREFIX.length( ) );
77 String code = codeSuffix.substring( 0, codeSuffix.indexOf( '.' ) );
78 hashSet.add( code );
79 }
80
81 ArrayList<String> result = new ArrayList<String>( hashSet );
82
83 return result;
84 }
85
86
87
88
89
90
91
92
93 public static String getIcon( String strProvider, String strIconKey )
94 {
95 try
96 {
97 IIconProvider./../fr/paris/lutece/plugins/leaflet/service/IIconProvider.html#IIconProvider">IIconProvider iconProvider = (IIconProvider) SpringContextService.getBean( BEAN_PREFIX + strProvider );
98 String icon = iconProvider.getIcon( strIconKey );
99
100 return ( icon == null ) ? "default" : icon;
101 }
102 catch ( NoSuchBeanDefinitionException e )
103 {
104 AppLogService.error( "icon API: Missing strProvider " + strProvider + " , strIconKey " + strIconKey +
105 ", exception " + e );
106
107 return "default";
108 }
109 }
110 }