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.portal.service.file;
35
36 import fr.paris.lutece.portal.service.spring.SpringContextService;
37 import fr.paris.lutece.portal.service.util.AppException;
38 import java.util.List;
39
40
41
42
43
44 public class FileService
45 {
46
47
48 public static final String PARAMETER_FILE_ID = "file_id";
49 public static final String PARAMETER_RESOURCE_ID = "resource_id";
50 public static final String PARAMETER_RESOURCE_TYPE = "resource_type";
51 public static final String PARAMETER_VALIDITY_TIME = "validity_time";
52 public static final String PARAMETER_DATA = "data";
53 public static final String PARAMETER_BO = "is_bo";
54 public static final String PARAMETER_PROVIDER = "provider";
55
56
57 public static final String PERMISSION_VIEW = "VIEW";
58
59
60 private static final String MSG_NO_FILE_SERVICE = "No file service Available";
61
62 private IFileStoreServiceProvider _defaulFileStoreServiceProvider;
63 private List<IFileStoreServiceProvider> _fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
64
65 private static FileService _instance;
66
67
68
69
70 private FileService( )
71 {
72 _defaulFileStoreServiceProvider = getDefaultServiceProvider( );
73 }
74
75
76
77
78
79
80 public static FileService getInstance( )
81 {
82 if ( _instance == null )
83 {
84 _instance = new FileService( );
85 }
86 return _instance;
87 }
88
89
90
91
92
93
94 public IFileStoreServiceProvider getFileStoreServiceProvider( )
95 {
96 return getFileStoreServiceProvider( null) ;
97 }
98
99
100
101
102
103
104
105 public IFileStoreServiceProvider getFileStoreServiceProvider( String strFileStoreServiceProviderName )
106 {
107 _fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
108
109 if ( strFileStoreServiceProviderName == null && _defaulFileStoreServiceProvider != null )
110 {
111 return _defaulFileStoreServiceProvider;
112 }
113
114
115 if ( !_fileStoreServiceProviderList.isEmpty( ) && strFileStoreServiceProviderName != null )
116 {
117 for ( IFileStoreServiceProvider fss : _fileStoreServiceProviderList )
118 {
119 if ( strFileStoreServiceProviderName.equals( fss.getName( ) ) )
120 {
121 return fss;
122 }
123 }
124 }
125
126
127 throw new AppException( MSG_NO_FILE_SERVICE );
128 }
129
130
131
132
133
134
135 private IFileStoreServiceProvider getDefaultServiceProvider( )
136 {
137
138 if ( !_fileStoreServiceProviderList.isEmpty( ) )
139 {
140 for ( IFileStoreServiceProvider fss : _fileStoreServiceProviderList )
141 {
142 if ( fss.isDefault( ) )
143 {
144 return fss;
145 }
146 }
147
148
149 return _fileStoreServiceProviderList.get( 0 ) ;
150 }
151
152
153 throw new AppException( MSG_NO_FILE_SERVICE );
154 }
155 }