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.document.modules.geoloc.service;
35
36 import fr.paris.lutece.plugins.document.business.DocumentType;
37 import fr.paris.lutece.plugins.document.business.DocumentTypeHome;
38 import fr.paris.lutece.plugins.document.business.attributes.DocumentAttribute;
39 import fr.paris.lutece.plugins.document.business.attributes.DocumentAttributeHome;
40 import fr.paris.lutece.plugins.leaflet.service.IIconProvider;
41 import fr.paris.lutece.portal.service.util.AppLogService;
42
43 import java.util.List;
44
45 public class DocumentIconProvider implements IIconProvider
46 {
47
48 private static final String ATTR_PARAMETER_ICON = "icon";
49
50 public String getIcon( String iconKey )
51 {
52 String documentTypeCode = iconKey.substring( 0, iconKey.indexOf( "-" ) );
53 String documentAttributeCode = iconKey.substring( iconKey.indexOf( "-" ) + 1 );
54
55 DocumentType type = DocumentTypeHome.findByPrimaryKey( documentTypeCode );
56 DocumentAttribute attribute = null;
57
58 for ( DocumentAttribute _attribute : type.getAttributes( ) )
59 {
60 if ( _attribute.getCode( ).equals( documentAttributeCode ) )
61 {
62 attribute = _attribute;
63
64 break;
65 }
66 }
67
68 if ( attribute == null )
69 {
70 AppLogService.error( "Document icon provider: no attribute " + documentAttributeCode + " for doctype " + documentTypeCode );
71
72 return null;
73 }
74
75 List<String> parameterValues = DocumentAttributeHome.getAttributeParameterValues( attribute.getId( ), ATTR_PARAMETER_ICON );
76
77 if ( parameterValues.size( ) > 0 )
78 {
79 return parameterValues.get( 0 );
80 }
81
82 return null;
83 }
84 }