View Javadoc
1   /*
2    * Copyright (c) 2002-2015, 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  
35  package fr.paris.lutece.plugins.directory.modules.exportfile.web;
36  
37  import fr.paris.lutece.plugins.directory.modules.exportfile.business.File;
38  import fr.paris.lutece.plugins.directory.modules.exportfile.business.FileHome;
39  import fr.paris.lutece.portal.service.message.AdminMessage;
40  import fr.paris.lutece.portal.service.message.AdminMessageService;
41  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
42  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
43  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
44  import fr.paris.lutece.util.url.UrlItem;
45  
46  import java.util.List;
47  import java.util.Map;
48  
49  import javax.servlet.http.HttpServletRequest;
50  
51  /**
52   * This class provides the user interface to manage File features ( manage, create, modify, remove )
53   */
54  @Controller( controllerJsp = "ManageFiles.jsp", controllerPath = "jsp/admin/plugins/directory/modules/exportfile/", right = "EXPORTFILE_MANAGEMENT" )
55  public class FileJspBean extends ManageExportfileJspBean
56  {
57  
58      // //////////////////////////////////////////////////////////////////////////
59      // Constants
60  
61      // templates
62      private static final String TEMPLATE_MANAGE_FILES = "/admin/plugins/directory/modules/exportfile/manage_files.html";
63  
64      // Parameters
65      private static final String PARAMETER_ID_FILE = "id";
66  
67      // Properties for page titles
68      private static final String PROPERTY_PAGE_TITLE_MANAGE_FILES = "module.directory.exportfile.manage_files.pageTitle";
69  
70      // Markers
71      private static final String MARK_FILE_LIST = "file_list";
72  
73      private static final String JSP_MANAGE_FILES = "jsp/admin/plugins/directory/modules/exportfile/ManageFiles.jsp";
74  
75      // Properties
76      private static final String MESSAGE_CONFIRM_REMOVE_FILE = "module.directory.exportfile.message.confirmRemoveFile";
77  
78      // Views
79      private static final String VIEW_MANAGE_FILES = "manageFiles";
80  
81      // Actions
82  
83      private static final String ACTION_REMOVE_FILE = "removeFile";
84      private static final String ACTION_CONFIRM_REMOVE_FILE = "confirmRemoveFile";
85  
86      // Infos
87  
88      private static final String INFO_FILE_REMOVED = "module.directory.exportfile.info.file.removed";
89  
90      // Session variable to store working values
91      private File _file;
92  
93      @View( value = VIEW_MANAGE_FILES, defaultView = true )
94      public String getManageFiles( HttpServletRequest request )
95      {
96          _file = null;
97          List<File> listFiles = (List<File>) FileHome.getFilesList( );
98          Map<String, Object> model = getPaginatedListModel( request, MARK_FILE_LIST, listFiles, JSP_MANAGE_FILES );
99  
100         return getPage( PROPERTY_PAGE_TITLE_MANAGE_FILES, TEMPLATE_MANAGE_FILES, model );
101     }
102 
103     /**
104      * Manages the removal form of a file whose identifier is in the http request
105      *
106      * @param request
107      *            The Http request
108      * @return the html code to confirm
109      */
110     @Action( ACTION_CONFIRM_REMOVE_FILE )
111     public String getConfirmRemoveFile( HttpServletRequest request )
112     {
113         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_FILE ) );
114         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_FILE ) );
115         url.addParameter( PARAMETER_ID_FILE, nId );
116 
117         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_FILE, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
118 
119         return redirect( request, strMessageUrl );
120     }
121 
122     /**
123      * Handles the removal form of a file
124      *
125      * @param request
126      *            The Http request
127      * @return the jsp URL to display the form to manage files
128      */
129     @Action( ACTION_REMOVE_FILE )
130     public String doRemoveFile( HttpServletRequest request )
131     {
132         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_FILE ) );
133         FileHome.remove( nId );
134         addInfo( INFO_FILE_REMOVED, getLocale( ) );
135 
136         return redirectView( request, VIEW_MANAGE_FILES );
137     }
138 
139 }