View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.web.xsl;
35  
36  import fr.paris.lutece.portal.business.file.File;
37  import fr.paris.lutece.portal.business.file.FileHome;
38  import fr.paris.lutece.portal.business.physicalfile.PhysicalFile;
39  import fr.paris.lutece.portal.business.physicalfile.PhysicalFileHome;
40  import fr.paris.lutece.portal.business.rbac.RBAC;
41  import fr.paris.lutece.portal.business.xsl.XslExport;
42  import fr.paris.lutece.portal.business.xsl.XslExportHome;
43  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
44  import fr.paris.lutece.portal.service.fileupload.FileUploadService;
45  import fr.paris.lutece.portal.service.i18n.I18nService;
46  import fr.paris.lutece.portal.service.message.AdminMessage;
47  import fr.paris.lutece.portal.service.message.AdminMessageService;
48  import fr.paris.lutece.portal.service.plugin.Plugin;
49  import fr.paris.lutece.portal.service.plugin.PluginService;
50  import fr.paris.lutece.portal.service.rbac.RBACService;
51  import fr.paris.lutece.portal.service.template.AppTemplateService;
52  import fr.paris.lutece.portal.service.util.AppPathService;
53  import fr.paris.lutece.portal.service.util.AppPropertiesService;
54  import fr.paris.lutece.portal.service.xsl.XslExportResourceIdService;
55  import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
56  import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
57  import fr.paris.lutece.portal.web.util.LocalizedPaginator;
58  import fr.paris.lutece.util.ReferenceItem;
59  import fr.paris.lutece.util.ReferenceList;
60  import fr.paris.lutece.util.filesystem.FileSystemUtil;
61  import fr.paris.lutece.util.html.HtmlTemplate;
62  import fr.paris.lutece.util.html.Paginator;
63  import fr.paris.lutece.util.url.UrlItem;
64  
65  import org.apache.commons.fileupload.FileItem;
66  import org.apache.commons.lang.StringUtils;
67  
68  import org.xml.sax.InputSource;
69  
70  import java.io.ByteArrayInputStream;
71  import java.io.IOException;
72  import java.io.OutputStream;
73  
74  import java.util.Collection;
75  import java.util.HashMap;
76  import java.util.List;
77  
78  import javax.servlet.http.HttpServletRequest;
79  import javax.servlet.http.HttpServletResponse;
80  
81  import javax.xml.parsers.SAXParser;
82  import javax.xml.parsers.SAXParserFactory;
83  
84  
85  /**
86   *
87   * class XslExportJspBean
88   *
89   */
90  public class XslExportJspBean extends PluginAdminPageJspBean
91  {
92      /**
93       * Right to manage XSL Export
94       */
95      public static final String RIGHT_MANAGE_XSL_EXPORT = "CORE_XSL_EXPORT_MANAGEMENT";
96  
97      /**
98       * Serial version UID
99       */
100     private static final long serialVersionUID = -8697851692630602527L;
101 
102     // templates
103     private static final String TEMPLATE_MANAGE_XSL_EXPORT = "admin/xsl/manage_xsl_export.html";
104     private static final String TEMPLATE_CREATE_XSL_EXPORT = "admin/xsl/create_xsl_export.html";
105     private static final String TEMPLATE_MODIFY_XSL_EXPORT = "admin/xsl/modify_xsl_export.html";
106 
107     // Markers
108     private static final String MARK_XSL_EXPORT_LIST = "xsl_export_list";
109     private static final String MARK_XSL_EXPORT = "xsl_export";
110     private static final String MARK_PAGINATOR = "paginator";
111     private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
112     private static final String MARK_PERMISSION_CREATE = "right_create";
113     private static final String MARK_PERMISSION_MODIFY = "right_modify";
114     private static final String MARK_PERMISSION_DELETE = "right_delete";
115     private static final String MARK_LIST_PLUGINS = "list_plugins";
116 
117     // parameters form
118     private static final String PARAMETER_ID_XSL_EXPORT = "id_xsl_export";
119     private static final String PARAMETER_ID_FILE = "id_file";
120     private static final String PARAMETER_TITLE = "title";
121     private static final String PARAMETER_DESCRIPTION = "description";
122     private static final String PARAMETER_EXTENSION = "extension";
123     private static final String PARAMETER_PAGE_INDEX = "page_index";
124     private static final String PARAMETER_PLUGIN = "plugin";
125 
126     // other constants
127     private static final String EMPTY_STRING = "";
128 
129     // message
130     private static final String MESSAGE_CONFIRM_REMOVE_XSL_EXPORT = "portal.xsl.message.confirm_remove_xsl_export";
131     private static final String MESSAGE_MANDATORY_FIELD = "portal.util.message.mandatoryField";
132 
133     // private static final String MESSAGE_CAN_NOT_REMOVE_XSL_EXPORT = "portal.xsl.message.can_not_remove_xsl_export";
134     private static final String FIELD_TITLE = "portal.xsl.create_xsl_export.label_title";
135     private static final String FIELD_DESCRIPTION = "portal.xsl.create_xsl_export.label_description";
136     private static final String FIELD_EXTENSION = "portal.xsl.create_xsl_export.label_extension";
137 
138     // private static final String FIELD_EXTENSION = "portal.xsl.create_xsl_export.label_extension";
139     private static final String FIELD_FILE = "portal.xsl.create_xsl_export.label_file";
140     private static final String MESSAGE_XML_NOT_VALID = "portal.xsl.message.xml_not_valid";
141     private static final String MESSAGE_PERMISSION_DENIED = "portal.xsl.message.permission_denied";
142 
143     // properties
144     private static final String PROPERTY_ITEM_PER_PAGE = "paginator.xsl.itemsPerPage";
145     private static final String PROPERTY_MANAGE_XSL_EXPORT_TITLE = "portal.xsl.manage_xsl_export.page_title";
146     private static final String PROPERTY_MODIFY_XSL_EXPORT_TITLE = "portal.xsl.modify_xsl_export.title";
147     private static final String PROPERTY_CREATE_XSL_EXPORT_TITLE = "portal.xsl.create_xsl_export.title";
148 
149     // Jsp Definition
150     private static final String JSP_MANAGE_XSL_EXPORT = "jsp/admin/xsl/ManageXslExport.jsp";
151     private static final String JSP_DO_REMOVE_XSL_EXPORT = "jsp/admin/xsl/DoRemoveXslExport.jsp";
152 
153     // session fields
154     private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_ITEM_PER_PAGE, 15 );
155     private String _strCurrentPageIndex;
156     private int _nItemsPerPage;
157 
158     /**
159      * Return the xsl export management page ( list of export format )
160      * @param request The Http request
161      * @return Html of the xsl export management page
162      */
163     public String getManageXslExport( HttpServletRequest request )
164     {
165         HashMap<String, Object> model = new HashMap<String, Object>(  );
166         List<XslExport> listXslExport = XslExportHome.getList(  );
167         _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
168         _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
169                 _nDefaultItemsPerPage );
170 
171         model.put( MARK_PERMISSION_CREATE,
172             RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
173                 XslExportResourceIdService.PERMISSION_CREATE, getUser(  ) ) );
174         model.put( MARK_PERMISSION_MODIFY,
175             RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
176                 XslExportResourceIdService.PERMISSION_MODIFY, getUser(  ) ) );
177         model.put( MARK_PERMISSION_DELETE,
178             RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
179                 XslExportResourceIdService.PERMISSION_DELETE, getUser(  ) ) );
180 
181         LocalizedPaginator<XslExport> paginator = new LocalizedPaginator<XslExport>( listXslExport, _nItemsPerPage,
182                 getJspManageXslExport( request ), PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale(  ) );
183 
184         model.put( MARK_PAGINATOR, paginator );
185         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPage );
186         model.put( MARK_XSL_EXPORT_LIST, paginator.getPageItems(  ) );
187         setPageTitleProperty( PROPERTY_MANAGE_XSL_EXPORT_TITLE );
188 
189         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_XSL_EXPORT, getLocale(  ), model );
190 
191         return getAdminPage( templateList.getHtml(  ) );
192     }
193 
194     /**
195      * Gets the xsl export creation page
196      * @param request The HTTP request
197      * @throws AccessDeniedException the {@link AccessDeniedException}
198      * @return The xsl export creation page
199      */
200     public String getCreateXslExport( HttpServletRequest request )
201         throws AccessDeniedException
202     {
203         HashMap<String, Object> model = new HashMap<String, Object>(  );
204 
205         Collection<Plugin> listPlugins = PluginService.getPluginList(  );
206         ReferenceList refListPlugins = new ReferenceList(  );
207         ReferenceItem refItem = new ReferenceItem(  );
208         Plugin pluginCore = PluginService.getCore(  );
209         refItem.setCode( pluginCore.getName(  ) );
210         refItem.setName( pluginCore.getName(  ) );
211         refListPlugins.add( refItem );
212 
213         for ( Plugin plugin : listPlugins )
214         {
215             if ( plugin != null )
216             {
217                 refItem = new ReferenceItem(  );
218                 refItem.setCode( plugin.getName(  ) );
219                 refItem.setName( plugin.getName(  ) );
220                 refListPlugins.add( refItem );
221             }
222         }
223 
224         model.put( MARK_LIST_PLUGINS, refListPlugins );
225 
226         if ( !RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
227                     XslExportResourceIdService.PERMISSION_CREATE, getUser(  ) ) )
228         {
229             throw new AccessDeniedException( MESSAGE_PERMISSION_DENIED );
230         }
231 
232         setPageTitleProperty( PROPERTY_CREATE_XSL_EXPORT_TITLE );
233 
234         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_XSL_EXPORT, getLocale(  ), model );
235 
236         return getAdminPage( template.getHtml(  ) );
237     }
238 
239     /**
240      * Perform the xsl export creation
241      * @param request The HTTP request
242      * @throws AccessDeniedException the {@link AccessDeniedException}
243      * @return The URL to go after performing the action
244      */
245     public String doCreateXslExport( HttpServletRequest request )
246         throws AccessDeniedException
247     {
248         XslExport xslExport = new XslExport(  );
249         String strError = getXslExportData( request, xslExport );
250 
251         if ( !RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
252                     XslExportResourceIdService.PERMISSION_CREATE, getUser(  ) ) )
253         {
254             throw new AccessDeniedException( MESSAGE_PERMISSION_DENIED );
255         }
256 
257         if ( strError != null )
258         {
259             return strError;
260         }
261 
262         if ( xslExport.getFile(  ) != null )
263         {
264             xslExport.getFile(  ).setIdFile( FileHome.create( xslExport.getFile(  ) ) );
265         }
266 
267         XslExportHome.create( xslExport );
268 
269         return getJspManageXslExport( request );
270     }
271 
272     /**
273      * Gets the export format modification page
274      * @param request The HTTP request
275      * @throws AccessDeniedException the {@link AccessDeniedException}
276      * @return The export format creation page
277      */
278     public String getModifyXslExport( HttpServletRequest request )
279         throws AccessDeniedException
280     {
281         if ( !RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
282                     XslExportResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
283         {
284             throw new AccessDeniedException( MESSAGE_PERMISSION_DENIED );
285         }
286 
287         XslExport xslExport;
288         String strIdXslExport = request.getParameter( PARAMETER_ID_XSL_EXPORT );
289         HashMap<String, Object> model = new HashMap<String, Object>(  );
290         int nIdXslExport = Integer.parseInt( strIdXslExport );
291         xslExport = XslExportHome.findByPrimaryKey( nIdXslExport );
292         model.put( MARK_XSL_EXPORT, xslExport );
293 
294         Collection<Plugin> listPlugins = PluginService.getPluginList(  );
295         ReferenceList refListPlugins = new ReferenceList(  );
296         ReferenceItem refItem = new ReferenceItem(  );
297         Plugin pluginCore = PluginService.getCore(  );
298         refItem.setCode( pluginCore.getName(  ) );
299         refItem.setName( pluginCore.getName(  ) );
300         refListPlugins.add( refItem );
301 
302         for ( Plugin plugin : listPlugins )
303         {
304             if ( plugin != null )
305             {
306                 refItem = new ReferenceItem(  );
307                 refItem.setCode( plugin.getName(  ) );
308                 refItem.setName( plugin.getName(  ) );
309                 refListPlugins.add( refItem );
310             }
311         }
312 
313         model.put( MARK_LIST_PLUGINS, refListPlugins );
314 
315         setPageTitleProperty( PROPERTY_MODIFY_XSL_EXPORT_TITLE );
316 
317         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_XSL_EXPORT, getLocale(  ), model );
318 
319         return getAdminPage( template.getHtml(  ) );
320     }
321 
322     /**
323      * Perform the xsl export modification
324      * @param request The HTTP request
325      * @throws AccessDeniedException the {@link AccessDeniedException}
326      * @return The URL to go after performing the action
327      */
328     public String doModifyXslExport( HttpServletRequest request )
329         throws AccessDeniedException
330     {
331         if ( !RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
332                     XslExportResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
333         {
334             throw new AccessDeniedException( MESSAGE_PERMISSION_DENIED );
335         }
336 
337         XslExport xslExport;
338         String strIdXslExport = request.getParameter( PARAMETER_ID_XSL_EXPORT );
339         int nIdXslExport = Integer.parseInt( strIdXslExport );
340         xslExport = XslExportHome.findByPrimaryKey( nIdXslExport );
341 
342         String strError = getXslExportData( request, xslExport );
343 
344         if ( strError != null )
345         {
346             return strError;
347         }
348 
349         // if xslExport
350         File fileStore = XslExportHome.findByPrimaryKey( nIdXslExport ).getFile(  );
351 
352         if ( xslExport.getFile(  ) != null )
353         {
354             // the file has been modified
355             File fileSource = xslExport.getFile(  );
356             // init id file source and id physical file before update
357             fileSource.setIdFile( fileStore.getIdFile(  ) );
358 
359             if ( fileStore.getPhysicalFile(  ) != null )
360             {
361                 fileSource.getPhysicalFile(  ).setIdPhysicalFile( fileStore.getPhysicalFile(  ).getIdPhysicalFile(  ) );
362             }
363 
364             FileHome.update( fileSource );
365         }
366         else
367         {
368             xslExport.setFile( fileStore );
369         }
370 
371         XslExportHome.update( xslExport );
372 
373         return getJspManageXslExport( request );
374     }
375 
376     /**
377      * Gets the confirmation page of delete xsl export
378      * @param request The HTTP request
379      * @throws AccessDeniedException the {@link AccessDeniedException}
380      * @return the confirmation page of delete xsl export
381      */
382     public String getConfirmRemoveXslExport( HttpServletRequest request )
383         throws AccessDeniedException
384     {
385         if ( !RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
386                     XslExportResourceIdService.PERMISSION_DELETE, getUser(  ) ) )
387         {
388             throw new AccessDeniedException( MESSAGE_PERMISSION_DENIED );
389         }
390 
391         String strIdXslExport = request.getParameter( PARAMETER_ID_XSL_EXPORT );
392 
393         UrlItem url = new UrlItem( JSP_DO_REMOVE_XSL_EXPORT );
394         url.addParameter( PARAMETER_ID_XSL_EXPORT, strIdXslExport );
395 
396         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_XSL_EXPORT, url.getUrl(  ),
397             AdminMessage.TYPE_CONFIRMATION );
398     }
399 
400     /**
401      * Perform the export format supression
402      * @param request The HTTP request
403      * @throws AccessDeniedException the {@link AccessDeniedException}
404      * @return The URL to go after performing the action
405      */
406     public String doRemoveXslExport( HttpServletRequest request )
407         throws AccessDeniedException
408     {
409         if ( !RBACService.isAuthorized( XslExport.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
410                     XslExportResourceIdService.PERMISSION_DELETE, getUser(  ) ) )
411         {
412             throw new AccessDeniedException( MESSAGE_PERMISSION_DENIED );
413         }
414 
415         // ArrayList<String> listErrors = new ArrayList<String>( );
416         String strIdXslExport = request.getParameter( PARAMETER_ID_XSL_EXPORT );
417         int nIdXslExport = Integer.parseInt( strIdXslExport );
418         XslExport xslExport = XslExportHome.findByPrimaryKey( nIdXslExport );
419 
420         // if ( !XslExportRemovalListenerService.getService( ).checkForRemoval( strIdXslExport, listErrors, getLocale( ) ) )
421         // {
422         // String strCause = AdminMessageService.getFormattedList( listErrors, getLocale( ) );
423         // Object[] args =
424         // { strCause };
425         //
426         // return AdminMessageService.getMessageUrl( request, MESSAGE_CAN_NOT_REMOVE_XSL_EXPORT, args, AdminMessage.TYPE_STOP );
427         // }
428         XslExportHome.remove( nIdXslExport );
429 
430         if ( xslExport.getFile(  ) != null )
431         {
432             FileHome.remove( xslExport.getFile(  ).getIdFile(  ) );
433         }
434 
435         return getJspManageXslExport( request );
436     }
437 
438     /**
439      * Initiate a download of a XSL file
440      * @param request The request
441      * @param response The response
442      * @throws IOException Throw an exception if the outputstream has error.
443      */
444     public void doDownloadXslExport( HttpServletRequest request, HttpServletResponse response )
445         throws IOException
446     {
447         String strXslExportId = request.getParameter( PARAMETER_ID_XSL_EXPORT );
448 
449         if ( strXslExportId != null )
450         {
451             int nXslExportId = Integer.parseInt( strXslExportId );
452             XslExport xslExport = XslExportHome.findByPrimaryKey( nXslExportId );
453 
454             String strMimetype = xslExport.getFile(  ).getMimeType(  );
455             response.setContentType( ( strMimetype != null ) ? strMimetype : "application/octet-stream" );
456             response.setHeader( "Content-Disposition",
457                 "attachement; filename=\"" + xslExport.getFile(  ).getTitle(  ) + "\"" );
458 
459             OutputStream out = response.getOutputStream(  );
460             PhysicalFile physicalFile = PhysicalFileHome.findByPrimaryKey( xslExport.getFile(  ).getPhysicalFile(  )
461                                                                                     .getIdPhysicalFile(  ) );
462             out.write( physicalFile.getValue(  ) );
463             out.flush(  );
464             out.close(  );
465         }
466     }
467 
468     /**
469      * Get the request data and if there is no error insert the data in the
470      * exportFormat object specified in parameter. return null if there is no
471      * error or else return the error page url
472      * @param request the request
473      * @param xslExport the exportFormat Object
474      * @return null if there is no error or else return the error page url
475      */
476     private String getXslExportData( HttpServletRequest request, XslExport xslExport )
477     {
478         String strError = StringUtils.EMPTY;
479         String strTitle = request.getParameter( PARAMETER_TITLE );
480         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
481         String strExtension = request.getParameter( PARAMETER_EXTENSION );
482         String strPlugin = request.getParameter( PARAMETER_PLUGIN );
483         File fileSource = getFileData( PARAMETER_ID_FILE, request );
484 
485         if ( ( strTitle == null ) || strTitle.trim(  ).equals( EMPTY_STRING ) )
486         {
487             strError = FIELD_TITLE;
488         }
489 
490         else if ( ( strDescription == null ) || strDescription.trim(  ).equals( EMPTY_STRING ) )
491         {
492             strError = FIELD_DESCRIPTION;
493         }
494 
495         else if ( StringUtils.isBlank( strExtension ) )
496         {
497             strError = FIELD_EXTENSION;
498         }
499 
500         else if ( ( xslExport.getFile(  ) == null ) && ( fileSource == null ) )
501         {
502             strError = FIELD_FILE;
503         }
504 
505         if ( strPlugin == null )
506         {
507             strPlugin = StringUtils.EMPTY;
508         }
509 
510         // Mandatory fields
511         if ( !strError.equals( EMPTY_STRING ) )
512         {
513             Object[] tabRequiredFields = { I18nService.getLocalizedString( strError, getLocale(  ) ) };
514 
515             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
516                 AdminMessage.TYPE_STOP );
517         }
518 
519         // Check the XML validity of the XSL stylesheet
520         if ( fileSource != null )
521         {
522             strError = isValid( fileSource.getPhysicalFile(  ).getValue(  ) );
523 
524             if ( strError != null )
525             {
526                 Object[] args = { strError };
527 
528                 return AdminMessageService.getMessageUrl( request, MESSAGE_XML_NOT_VALID, args, AdminMessage.TYPE_STOP );
529             }
530         }
531 
532         xslExport.setTitle( strTitle );
533         xslExport.setDescription( strDescription );
534         xslExport.setExtension( strExtension );
535         xslExport.setPlugin( strPlugin );
536 
537         xslExport.setFile( fileSource );
538 
539         return null;
540     }
541 
542     /**
543      * Use parsing for validate the modify xsl file
544      * @param baXslSource the xsl source
545      * @return the message exception when the validation is false
546      */
547     private String isValid( byte[] baXslSource )
548     {
549         String strError = null;
550 
551         try
552         {
553             SAXParserFactory factory = SAXParserFactory.newInstance(  );
554             SAXParser analyzer = factory.newSAXParser(  );
555             InputSource is = new InputSource( new ByteArrayInputStream( baXslSource ) );
556             analyzer.getXMLReader(  ).parse( is );
557         }
558         catch ( Exception e )
559         {
560             strError = e.getMessage(  );
561         }
562 
563         return strError;
564     }
565 
566     /**
567      * return the url of manage export format
568      * @param request the request
569      * @return the url of manage export format
570      */
571     private String getJspManageXslExport( HttpServletRequest request )
572     {
573         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_XSL_EXPORT;
574     }
575 
576     /**
577      * Get a file contained in the request from the name of the parameter
578      *
579      * @param strFileInputName name of the file parameter of the request
580      * @param request the request
581      * @return file the file contained in the request with the given parameter
582      *         key
583      */
584     private static File getFileData( String strFileInputName, HttpServletRequest request )
585     {
586         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
587         FileItem fileItem = multipartRequest.getFile( strFileInputName );
588 
589         if ( ( fileItem != null ) && ( fileItem.getName(  ) != null ) && !EMPTY_STRING.equals( fileItem.getName(  ) ) )
590         {
591             File file = new File(  );
592             PhysicalFile physicalFile = new PhysicalFile(  );
593             physicalFile.setValue( fileItem.get(  ) );
594             file.setTitle( FileUploadService.getFileNameOnly( fileItem ) );
595             file.setSize( (int) fileItem.getSize(  ) );
596             file.setPhysicalFile( physicalFile );
597             file.setMimeType( FileSystemUtil.getMIMEType( FileUploadService.getFileNameOnly( fileItem ) ) );
598 
599             return file;
600         }
601 
602         return null;
603     }
604 }