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.stock.modules.billetterie.web;
35
36 import fr.paris.lutece.plugins.stock.modules.tickets.service.IShowService;
37 import fr.paris.lutece.portal.service.spring.SpringContextService;
38
39 import org.apache.commons.io.IOUtils;
40 import org.apache.commons.lang.StringUtils;
41
42 import org.apache.log4j.Logger;
43
44 import java.io.IOException;
45
46 import javax.servlet.ServletException;
47 import javax.servlet.ServletOutputStream;
48 import javax.servlet.http.HttpServlet;
49 import javax.servlet.http.HttpServletRequest;
50 import javax.servlet.http.HttpServletResponse;
51
52
53
54
55
56
57 public class PosterImageServlet extends HttpServlet
58 {
59 private static final String ERROR_MESSAGE = "Appel de PosterImageServlet avec un id de produit null";
60 private static final String CONTENT_TYPE_IMAGE_JPEG = "image/jpeg";
61 private static final String PARAMETER_TB = "tb";
62 private static final String PARAMETER_REAL_IMAGE = "img_real";
63 private static final String PARAMETER_PRODUCT_ID = "product_id";
64 private static final String BEAN_STOCK_TICKETS_SHOW_SERVICE = "stock-tickets.showService";
65
66
67
68
69 private static final long serialVersionUID = -1165966480942742905L;
70 private static final Logger LOGGER = Logger.getLogger( PosterImageServlet.class );
71
72
73 private IShowService _productService = (IShowService) SpringContextService.getBean( BEAN_STOCK_TICKETS_SHOW_SERVICE );
74
75
76
77
78
79
80
81
82
83
84
85
86
87 protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
88 {
89 String sIdProduct = request.getParameter( PARAMETER_PRODUCT_ID );
90
91 if ( StringUtils.isNotEmpty( sIdProduct ) )
92 {
93 Integer idProduct = Integer.parseInt( sIdProduct );
94 boolean isThumbnail = ( request.getParameter( PARAMETER_TB ) != null ) && request.getParameter( PARAMETER_TB ).equals( String.valueOf( true ) );
95 boolean isImageReal = ( request.getParameter( PARAMETER_REAL_IMAGE ) != null )
96 && request.getParameter( PARAMETER_REAL_IMAGE ).equals( String.valueOf( true ) );
97 byte [ ] bImage;
98
99 if ( isImageReal )
100 {
101 bImage = _productService.getRealImage( idProduct );
102 }
103 else
104 {
105 if ( isThumbnail )
106 {
107 bImage = _productService.getTbImage( idProduct );
108 }
109 else
110 {
111 bImage = _productService.getImage( idProduct );
112 }
113 }
114 response.setContentLength( bImage.length );
115 response.setContentType( CONTENT_TYPE_IMAGE_JPEG );
116
117 ServletOutputStream os = response.getOutputStream( );
118 IOUtils.write( bImage, os );
119 os.flush( );
120 os.close( );
121 }
122 else
123 {
124 LOGGER.error( ERROR_MESSAGE );
125 }
126 }
127 }