1 /* 2 * Copyright (c) 2002-2021, City of 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.plugins.asynchronousupload.service; 35 36 import fr.paris.lutece.portal.web.upload.IAsynchronousUploadHandler2; 37 38 import org.apache.commons.fileupload.FileItem; 39 40 import java.util.List; 41 import java.util.Locale; 42 43 import javax.servlet.http.HttpServletRequest; 44 import javax.servlet.http.HttpSession; 45 46 /** 47 * Interface for asynchronous upload handlers used by entries of type upload. Handler must be declared as Spring beans. 48 */ 49 public interface IAsyncUploadHandler extends IAsynchronousUploadHandler2 50 { 51 /** 52 * Get the upload submit prefix 53 * 54 * @return The upload submit prefix 55 */ 56 String getUploadSubmitPrefix( ); 57 58 /** 59 * Get the upload delete prefix 60 * 61 * @return The upload delete prefix 62 */ 63 String getUploadDeletePrefix( ); 64 65 /** 66 * Get the upload checkbox prefix 67 * 68 * @return The upload checkbox prefix 69 */ 70 String getUploadCheckboxPrefix( ); 71 72 /** 73 * Check if the file can be uploaded or not. 74 * 75 * @param request 76 * The request 77 * @param strFieldName 78 * the field name 79 * @param listFileItemsToUpload 80 * the list of files to upload 81 * @param locale 82 * the locale 83 * @return The error message if any, or null if the files can be uploaded. 84 */ 85 String canUploadFiles( HttpServletRequest request, String strFieldName, List<FileItem> listFileItemsToUpload, Locale locale ); 86 87 /** 88 * Gets the list of upload files for a given field and a given session. The order of files in the list must be the upload order. Their index in this list 89 * (from 0 to the list size) will be used to identify them. 90 * 91 * @param strFieldName 92 * the field name 93 * @param session 94 * The session of the current user 95 * @return the fileItem found, <code>null</code> otherwise. 96 */ 97 List<FileItem> getListUploadedFiles( String strFieldName, HttpSession session ); 98 99 /** 100 * Gets the list of partial upload files for a given field and a given session. The order of files in the list must be the upload order. Their index in this 101 * list (from 0 to the list size) will be used to identify them. 102 * 103 * @param strFieldName 104 * the field name 105 * @param session 106 * The session of the current user 107 * @return the fileItem found, <code>null</code> otherwise. 108 */ 109 List<FileItem> getListPartialUploadedFiles( String strFieldName, HttpSession session ); 110 111 /** 112 * Remove file Item 113 * 114 * @param strFieldName 115 * the field name 116 * @param session 117 * The session of the current user 118 * @param nIndex 119 * the index of the file to remove (from 0 to n). The index is the index of the file in the uploaded file list given by the method 120 * {@link #getListUploadedFiles(String, HttpSession) } 121 */ 122 void removeFileItem( String strFieldName, HttpSession session, int nIndex ); 123 124 /** 125 * Remove all file Item for a given session 126 * 127 * @param session 128 * The session of the current user 129 */ 130 void removeAllFileItem( HttpSession session ); 131 132 /** 133 * Add a file item to the list of uploaded files 134 * 135 * @param fileItem 136 * the file item 137 * @param strFieldName 138 * the field name 139 * @param request 140 * the request 141 */ 142 void addFileItemToUploadedFilesList( FileItem fileItem, String strFieldName, HttpServletRequest request ); 143 144 /** 145 * Add file item to the list of partial uploaded files 146 * 147 * @param fileItem 148 * the file item 149 * @param strFieldName 150 * the field name 151 * @param request 152 * the request 153 */ 154 void addFileItemToPartialUploadedFilesList( FileItem fileItem, String strFieldName, HttpServletRequest request ); 155 156 /** 157 * Check if the request has a remove flag for a given entry. 158 * 159 * @param request 160 * The request 161 * @param strFieldName 162 * The field name 163 * @return True if the request has a remove flag for the given entry, false otherwise 164 */ 165 boolean hasRemoveFlag( HttpServletRequest request, String strFieldName ); 166 167 /** 168 * Do remove a file of a given entry if a flag is present in the request. Files are selected from the request. 169 * 170 * @param request 171 * The request 172 * @param strFieldName 173 * The field name 174 */ 175 void doRemoveFile( HttpServletRequest request, String strFieldName ); 176 177 /** 178 * Do remove a list of files from uploaded files. 179 * 180 * @param request 181 * The request 182 * @param strFieldName 183 * The field name of the files to remove 184 * @param listIndexesFilesToRemove 185 * The list of indexes of files to remove 186 * @return The result JSON 187 */ 188 String doRemoveUploadedFile( HttpServletRequest request, String strFieldName, List<Integer> listIndexesFilesToRemove ); 189 190 /** 191 * Check if the request has the flag to submit a file without submitting the form. 192 * 193 * @param request 194 * The request 195 * @param strFieldName 196 * The id of the entry 197 * @return True if the flag is present in the request, false otherwise 198 */ 199 boolean hasAddFileFlag( HttpServletRequest request, String strFieldName ); 200 201 /** 202 * Add files uploaded synchronously for a given field 203 * 204 * @param request 205 * The request 206 * @param strFieldName 207 * The name of the field to add files of 208 */ 209 void addFilesUploadedSynchronously( HttpServletRequest request, String strFieldName ); 210 211 /** 212 * Get the name of the handler. The name of the handler must be unique. The handler name must only contain alphabetic characters (no point, no space, no 213 * coma, no #, ...). 214 * 215 * @return The name of the handler 216 */ 217 String getHandlerName( ); 218 219 /** 220 * Do retrieve a file from uploaded files. 221 * 222 * @param request 223 * The request 224 * @return The file 225 */ 226 byte [ ] doRetrieveUploadedFile( HttpServletRequest request ); 227 228 /** 229 * 230 * @return true if the handler manage partial content 231 */ 232 boolean isManagePartialContent( ); 233 234 /** 235 * Removes all files associated to the session 236 * 237 * @param strSessionId 238 * the session id 239 */ 240 default void removeSessionFiles( HttpSession session ) 241 { 242 } 243 }