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 _currentFileStoreServiceProvider;
63 private static FileService/file/FileService.html#FileService">FileService _instance = new FileService( );
64
65
66
67
68 private FileService( )
69 {
70 _currentFileStoreServiceProvider = getDefaultServiceProvider( );
71 }
72
73
74
75
76
77
78 public static FileService getInstance( )
79 {
80 return _instance;
81 }
82
83
84
85
86
87
88 public IFileStoreServiceProvider getFileStoreServiceProvider( )
89 {
90 return _currentFileStoreServiceProvider;
91 }
92
93
94
95
96
97
98
99 public IFileStoreServiceProvider getFileStoreServiceProvider( String strFileStoreServiceProviderName )
100 {
101 List<IFileStoreServiceProvider> fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
102
103
104 if ( !fileStoreServiceProviderList.isEmpty( ) )
105 {
106 for ( IFileStoreServiceProvider fss : fileStoreServiceProviderList )
107 {
108 if ( strFileStoreServiceProviderName.equals( fss.getName( ) ) )
109 {
110 return fss;
111 }
112 }
113 }
114
115
116 throw new AppException( MSG_NO_FILE_SERVICE );
117 }
118
119
120
121
122
123
124 public void setFileStoreServiceProvider( String strFileStoreServiceProviderName )
125 {
126 List<IFileStoreServiceProvider> fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
127
128
129 if ( !fileStoreServiceProviderList.isEmpty( ) )
130 {
131 for ( IFileStoreServiceProvider fss : fileStoreServiceProviderList )
132 {
133 if ( strFileStoreServiceProviderName.equals( fss.getName( ) ) )
134 {
135 _currentFileStoreServiceProvider = fss;
136 return;
137 }
138 }
139 }
140
141
142 throw new AppException( MSG_NO_FILE_SERVICE );
143 }
144
145
146
147
148
149
150 private IFileStoreServiceProvider getDefaultServiceProvider( )
151 {
152 List<IFileStoreServiceProvider> fileStoreServiceProviderList = SpringContextService.getBeansOfType( IFileStoreServiceProvider.class );
153
154
155 if ( !fileStoreServiceProviderList.isEmpty( ) )
156 {
157 for ( IFileStoreServiceProvider fss : fileStoreServiceProviderList )
158 {
159 if ( fss.isDefault( ) )
160 {
161 return fss;
162 }
163 }
164
165
166 return fileStoreServiceProviderList.get( 0 ) ;
167 }
168
169
170 throw new AppException( MSG_NO_FILE_SERVICE );
171 }
172 }