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.blobstore.service.download;
35
36 import fr.paris.lutece.plugins.blobstore.util.BlobStoreConstants;
37 import fr.paris.lutece.plugins.blobstore.util.BlobStoreLibConstants;
38 import fr.paris.lutece.plugins.blobstore.util.BlobStoreUtils;
39 import fr.paris.lutece.portal.service.util.AppPropertiesService;
40 import fr.paris.lutece.util.url.UrlItem;
41
42 import java.util.ArrayList;
43 import java.util.Date;
44 import java.util.List;
45
46
47
48
49
50 public class JSPBlobStoreDownloadUrlService implements IBlobStoreDownloadUrlService
51 {
52 private static final long serialVersionUID = 1L;
53
54
55
56
57
58
59
60
61
62
63 @Override
64 public String getFileUrl( String strBlobStore, String strBlobKey )
65 {
66 return getBlobUrl( strBlobStore, strBlobKey, BlobStoreConstants.JSP_DO_DOWNLOAD_FILE );
67 }
68
69
70
71
72
73
74
75
76
77
78 @Override
79 public String getDownloadUrl( String strBlobStore, String strBlobKey )
80 {
81 return getBlobUrl( strBlobStore, strBlobKey, BlobStoreConstants.JSP_DO_DOWNLOAD_BLOB );
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95 private static String getBlobUrl( String strBlobStore, String strBlobKey, String strJsp )
96 {
97 String strBaseUrl = AppPropertiesService.getProperty( BlobStoreLibConstants.PROPERTY_BASE_URL,
98 AppPropertiesService.getProperty( BlobStoreLibConstants.PROPERTY_PROD_URL ) );
99 String strBlobUrl;
100
101 if ( strBaseUrl != null )
102 {
103 if ( !strBaseUrl.endsWith( "/" ) )
104 {
105 strBaseUrl += "/";
106 }
107
108 UrlItem urlItem = new UrlItem( strBaseUrl + strJsp );
109 urlItem.addParameter( BlobStoreLibConstants.PARAMETER_BLOB_STORE, strBlobStore );
110 urlItem.addParameter( BlobStoreLibConstants.PARAMETER_BLOB_KEY, strBlobKey );
111
112 List<String> listElements = new ArrayList<String>( );
113 listElements.add( strBlobStore );
114 listElements.add( strBlobKey );
115
116 String strTimestamp = Long.toString( new Date( ).getTime( ) );
117 String strSignature = BlobStoreUtils.getRequestAuthenticator( ).buildSignature( listElements, strTimestamp );
118
119 urlItem.addParameter( BlobStoreConstants.PARAMETER_TIMESTAMP, strTimestamp );
120 urlItem.addParameter( BlobStoreConstants.PARAMETER_SIGNATURE, strSignature );
121
122 strBlobUrl = urlItem.getUrl( );
123 }
124 else
125 {
126 strBlobUrl = null;
127 }
128
129 return strBlobUrl;
130 }
131 }