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.digglike.business;
35
36 import fr.paris.lutece.plugins.digglike.service.DiggSubmitService;
37 import fr.paris.lutece.plugins.digglike.utils.DiggUtils;
38 import fr.paris.lutece.portal.service.i18n.I18nService;
39 import fr.paris.lutece.portal.service.message.AdminMessage;
40 import fr.paris.lutece.portal.service.message.AdminMessageService;
41 import fr.paris.lutece.portal.service.plugin.Plugin;
42 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
43
44 import java.util.ArrayList;
45 import java.util.List;
46 import java.util.Locale;
47
48 import javax.servlet.http.HttpServletRequest;
49
50 import org.apache.commons.fileupload.FileItem;
51
52
53
54
55
56
57
58 public class EntryTypeVideo extends Entry
59 {
60 private static final String PARAMETER_CREDITS = "credits";
61 private static final String PARAMETER_AUTOSTART = "autostart";
62 private static final String PARAMETER_LOOP = "loop";
63 private static final String PARAMETER_QUALITY = "quality";
64 private static final String PARAMETER_ALIGNMENT = "alignment";
65 private static final String PARAMETER_MENU = "menu";
66 private static final String MESSAGE_FILE_TOO_HEAVY = "digglike.message.fileTooHeavy";
67 private static final String PROPERTY_CREDITS = "digglike.createEntry.labelCredits";
68 private final String _template_create = "admin/plugins/digglike/create_entry_type_video.html";
69 private final String _template_modify = "admin/plugins/digglike/modify_entry_type_video.html";
70 private final String _template_html_code_form = "admin/plugins/digglike/html_code_form_entry_type_video.html";
71 private final String _template_html_code_response = "admin/plugins/digglike/html_code_response_entry_type_video.html";
72
73
74
75
76
77
78 public String getTemplateHtmlCodeForm( )
79 {
80 return _template_html_code_form;
81 }
82
83
84
85
86
87
88
89 public String getRequestData( HttpServletRequest request, Locale locale )
90 {
91 String strTitle = request.getParameter( PARAMETER_TITLE );
92 String strHelpMessage = request.getParameter( PARAMETER_HELP_MESSAGE );
93 String strComment = request.getParameter( PARAMETER_COMMENT );
94 String strValue = request.getParameter( PARAMETER_VALUE );
95 String strMandatory = request.getParameter( PARAMETER_MANDATORY );
96 String strWidth = request.getParameter( PARAMETER_WIDTH );
97 String strHeight = request.getParameter( PARAMETER_HEIGHT );
98 String strShowInDiggSubmitList = request.getParameter( PARAMETER_SHOW_IN_DIGG_SUBMIT_LIST );
99 String strAutostart = request.getParameter( PARAMETER_AUTOSTART );
100 String strLoop = request.getParameter( PARAMETER_LOOP );
101 String strQuality = request.getParameter( PARAMETER_QUALITY );
102 String strAlignment = request.getParameter( PARAMETER_ALIGNMENT );
103 String strMenu = request.getParameter( PARAMETER_MENU );
104
105 int nWidth = -1;
106 int nHeight = -1;
107
108 String strFieldError = EMPTY_STRING;
109
110 if ( ( strTitle == null ) || strTitle.trim( ).equals( EMPTY_STRING ) )
111 {
112 strFieldError = FIELD_TITLE;
113 }
114
115 if ( !strFieldError.equals( EMPTY_STRING ) )
116 {
117 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, locale ) };
118
119 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
120 AdminMessage.TYPE_STOP );
121 }
122
123 try
124 {
125 if ( !( ( strHeight == null ) || strHeight.trim( ).equals( EMPTY_STRING ) ) )
126 {
127 nHeight = Integer.parseInt( strHeight );
128 }
129 }
130 catch ( NumberFormatException ne )
131 {
132 strFieldError = FIELD_HEIGHT;
133 }
134
135 try
136 {
137 if ( !( ( strWidth == null ) || strWidth.trim( ).equals( EMPTY_STRING ) ) )
138 {
139 nWidth = Integer.parseInt( strWidth );
140 }
141 }
142 catch ( NumberFormatException ne )
143 {
144 strFieldError = FIELD_WIDTH;
145 }
146
147 if ( !strFieldError.equals( EMPTY_STRING ) )
148 {
149 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, locale ) };
150
151 return AdminMessageService.getMessageUrl( request, MESSAGE_NUMERIC_FIELD, tabRequiredFields,
152 AdminMessage.TYPE_STOP );
153 }
154
155 List<EntryAdditionalAttribute> entryAdditionalAttributeList = new ArrayList<EntryAdditionalAttribute>( );
156 EntryAdditionalAttribute entryAdditionalAttributeAutostart = new EntryAdditionalAttribute( );
157 entryAdditionalAttributeAutostart.setName( PARAMETER_AUTOSTART );
158 entryAdditionalAttributeAutostart.setValue( strAutostart );
159 entryAdditionalAttributeList.add( entryAdditionalAttributeAutostart );
160
161 EntryAdditionalAttribute entryAdditionalAttributeLoop = new EntryAdditionalAttribute( );
162 entryAdditionalAttributeLoop.setName( PARAMETER_LOOP );
163 entryAdditionalAttributeLoop.setValue( strLoop );
164 entryAdditionalAttributeList.add( entryAdditionalAttributeLoop );
165
166 EntryAdditionalAttribute entryAdditionalAttributeAlignment = new EntryAdditionalAttribute( );
167 entryAdditionalAttributeAlignment.setName( PARAMETER_ALIGNMENT );
168 entryAdditionalAttributeAlignment.setValue( strAlignment );
169 entryAdditionalAttributeList.add( entryAdditionalAttributeAlignment );
170
171 EntryAdditionalAttribute entryAdditionalAttributeQuality = new EntryAdditionalAttribute( );
172 entryAdditionalAttributeQuality.setName( PARAMETER_QUALITY );
173 entryAdditionalAttributeQuality.setValue( strQuality );
174 entryAdditionalAttributeList.add( entryAdditionalAttributeQuality );
175
176 EntryAdditionalAttribute entryAdditionalAttributeMenu = new EntryAdditionalAttribute( );
177 entryAdditionalAttributeMenu.setName( PARAMETER_MENU );
178 entryAdditionalAttributeMenu.setValue( strMenu );
179 entryAdditionalAttributeList.add( entryAdditionalAttributeMenu );
180
181 this.setTitle( strTitle );
182 this.setHelpMessage( DiggUtils.trim( strHelpMessage ) );
183 this.setComment( strComment );
184
185 this.setDefaultValue( strValue );
186 this.setWidth( nWidth );
187 this.setHeight( nHeight );
188
189 this.setEntryAdditionalAttributeList( entryAdditionalAttributeList );
190
191 if ( strMandatory != null )
192 {
193 this.setMandatory( true );
194 }
195 else
196 {
197 this.setMandatory( false );
198 }
199
200 if ( strShowInDiggSubmitList != null )
201 {
202 this.setShowInDiggSubmitList( true );
203 }
204 else
205 {
206 this.setShowInDiggSubmitList( false );
207 }
208
209 return null;
210 }
211
212
213
214
215
216 public String getTemplateCreate( )
217 {
218 return _template_create;
219 }
220
221
222
223
224
225 public String getTemplateModify( )
226 {
227 return _template_modify;
228 }
229
230
231
232
233
234
235
236
237
238
239 public FormError getResponseData( int nIdDiggSubmit, HttpServletRequest request, List<Response> listResponse,
240 Locale locale, Plugin plugin )
241 {
242 String strCredits = request.getParameter( PARAMETER_CREDITS + this.getIdEntry( ) );
243
244 MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
245 FileItem item = mRequest.getFile( DiggUtils.EMPTY_STRING + this.getIdEntry( ) );
246
247 byte[] bytes = item.get( );
248
249 Response response = new Response( );
250 response.setEntry( this );
251
252 if ( bytes != null )
253 {
254 VideoType video = new VideoType( );
255 video.setVideo( bytes );
256 video.setMimeType( item.getContentType( ) );
257 video.setCredits( strCredits );
258 video.setIdDiggSubmit( nIdDiggSubmit );
259
260 try
261 {
262 VideoTypeHome.create( video, plugin );
263
264 String strMenu = "false";
265 String strLoop = "false";
266 String strAutostart = "false";
267
268 String strQuality = "low";
269
270 for ( EntryAdditionalAttribute attr : this.getEntryAdditionalAttributeList( ) )
271 {
272 if ( attr.getName( ).equals( PARAMETER_AUTOSTART ) )
273 {
274 strAutostart = attr.getValue( );
275 }
276
277
278
279
280 else if ( attr.getName( ).equals( PARAMETER_LOOP ) )
281 {
282 strLoop = attr.getValue( );
283 }
284 else if ( attr.getName( ).equals( PARAMETER_QUALITY ) )
285 {
286 strQuality = attr.getValue( );
287 }
288 else if ( attr.getName( ).equals( PARAMETER_MENU ) )
289 {
290 strMenu = attr.getValue( );
291 }
292 }
293
294 String strResponse = "<div id='mediaspace" + nIdDiggSubmit + "'></div>" +
295 "<script type='text/javascript' src='js/player/swfobject.js'></script>" +
296 "<script type='text/javascript'>" + " var so = new SWFObject('js/player/player.swf','mpl','" +
297 this.getWidth( ) + "','" + this.getHeight( ) + "','9');" +
298 " so.addParam('allowfullscreen','true');" + " so.addParam('allowscriptaccess','always');" +
299 " so.addParam('wmode','opaque');" + " so.addParam('quality','" + strQuality + "');" +
300 " so.addParam('menu','" + strMenu + "');" +
301 " so.addVariable('file','../../jsp/site/plugins/digglike/getVideo.jsp?video_id=" + nIdDiggSubmit +
302 "');" + " so.addVariable('provider','video');" + " so.addVariable('autostart','" + strAutostart +
303 "');" + " so.addVariable('icons','false');" + " so.addVariable('repeat','" + strLoop + "');" +
304 " so.write('mediaspace" + nIdDiggSubmit + "');" + "</script>";
305
306 strResponse += ( "<br /><b>" + I18nService.getLocalizedString( PROPERTY_CREDITS, locale ) +
307 " : </b>" + strCredits );
308
309 response.setValueResponse( strResponse );
310 }
311 catch ( com.mysql.jdbc.PacketTooBigException e )
312 {
313
314 DiggSubmitService.getService( ).remove( nIdDiggSubmit, plugin );
315
316 VideoTypeHome.remove( nIdDiggSubmit, plugin );
317
318 FormError formError = new FormError( );
319 formError.setTitleQuestion( this.getTitle( ) );
320 formError.setErrorMessage( I18nService.getLocalizedString( MESSAGE_FILE_TOO_HEAVY, locale ) );
321
322 return formError;
323 }
324 }
325 else
326 {
327 if ( this.isMandatory( ) )
328 {
329 FormError formError = new FormError( );
330 formError.setMandatoryError( true );
331 formError.setTitleQuestion( this.getTitle( ) );
332
333 return formError;
334 }
335 }
336
337 listResponse.add( response );
338
339 return null;
340 }
341
342
343
344
345
346 public String getTemplateHtmlCodeResponse( )
347 {
348 return _template_html_code_response;
349 }
350 }