Package org.silverpeas.core.util.file
Class FileUploadUtil
- java.lang.Object
-
- org.silverpeas.core.util.file.FileUploadUtil
-
public class FileUploadUtil extends Object
Utility class for file uploading.- Author:
- ehugonnet
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ENCODING
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.apache.commons.fileupload.FileItem
getFile(List<org.apache.commons.fileupload.FileItem> items)
static org.apache.commons.fileupload.FileItem
getFile(List<org.apache.commons.fileupload.FileItem> items, String parameterName)
static org.apache.commons.fileupload.FileItem
getFile(javax.servlet.http.HttpServletRequest request)
static String
getFileName(org.apache.commons.fileupload.FileItem file)
static org.apache.commons.fileupload.FileItem
getOldFile(List items, String parameterName)
static String
getOldParameter(List items, String parameterName)
static String
getOldParameter(List items, String parameterName, String defaultValue)
static String
getParameter(List<org.apache.commons.fileupload.FileItem> items, String parameterName)
Get the parameter value from the list of FileItems.static String
getParameter(List<org.apache.commons.fileupload.FileItem> items, String parameterName, String defaultValue)
Get the parameter value from the list of FileItems.static String
getParameter(List<org.apache.commons.fileupload.FileItem> items, String parameterName, String defaultValue, String encoding)
Get the parameter value from the list of FileItems.static List<String>
getParameterValues(List<org.apache.commons.fileupload.FileItem> items, String parameterName, String encoding)
static boolean
isRequestMultipart(javax.servlet.http.HttpServletRequest request)
static List<org.apache.commons.fileupload.FileItem>
parseRequest(javax.servlet.http.HttpServletRequest request)
Parses the multipart stream in the specified request to fetch the file items.static void
saveToFile(File file, org.apache.commons.fileupload.FileItem item)
-
-
-
Field Detail
-
DEFAULT_ENCODING
public static final String DEFAULT_ENCODING
- See Also:
- Constant Field Values
-
-
Method Detail
-
isRequestMultipart
public static boolean isRequestMultipart(javax.servlet.http.HttpServletRequest request)
-
parseRequest
public static List<org.apache.commons.fileupload.FileItem> parseRequest(javax.servlet.http.HttpServletRequest request) throws UtilException
Parses the multipart stream in the specified request to fetch the file items. This method shouldn't be used directly; instead use the HttpRequest instance.- Parameters:
request
- the HTTP servlet request.- Returns:
- a list of file items encoded into the multipart stream of the request.
- Throws:
UtilException
- if an error occurs while fetching the file items.
-
getParameter
public static String getParameter(List<org.apache.commons.fileupload.FileItem> items, String parameterName, String defaultValue, String encoding)
Get the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.- Parameters:
items
- the items resulting from parsing the request.parameterName
-defaultValue
- the value to be returned if the parameter is not found.encoding
- the request encoding.- Returns:
- the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
-
getParameterValues
public static List<String> getParameterValues(List<org.apache.commons.fileupload.FileItem> items, String parameterName, String encoding)
-
getParameter
public static String getParameter(List<org.apache.commons.fileupload.FileItem> items, String parameterName, String defaultValue)
Get the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.- Parameters:
items
- the items resulting from parsing the request.parameterName
-defaultValue
- the value to be returned if the parameter is not found.- Returns:
- the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
-
getParameter
public static String getParameter(List<org.apache.commons.fileupload.FileItem> items, String parameterName)
Get the parameter value from the list of FileItems. Returns null if the parameter is not found.- Parameters:
items
- the items resulting from parsing the request.parameterName
-- Returns:
- the parameter value from the list of FileItems. Returns null if the parameter is not found.
-
getOldParameter
public static String getOldParameter(List items, String parameterName, String defaultValue)
-
getOldFile
public static org.apache.commons.fileupload.FileItem getOldFile(List items, String parameterName)
-
getFile
public static org.apache.commons.fileupload.FileItem getFile(List<org.apache.commons.fileupload.FileItem> items, String parameterName)
-
getFile
public static org.apache.commons.fileupload.FileItem getFile(List<org.apache.commons.fileupload.FileItem> items)
-
getFile
public static org.apache.commons.fileupload.FileItem getFile(javax.servlet.http.HttpServletRequest request) throws UtilException
- Throws:
UtilException
-
getFileName
public static String getFileName(org.apache.commons.fileupload.FileItem file)
-
saveToFile
public static void saveToFile(File file, org.apache.commons.fileupload.FileItem item) throws IOException
- Throws:
IOException
-
-