Package org.pentaho.platform.web.servlet
Class UploadFileUtils
- java.lang.Object
-
- org.pentaho.platform.web.servlet.UploadFileUtils
-
public class UploadFileUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_RELATIVE_UPLOAD_FILE_PATH
-
Constructor Summary
Constructors Constructor Description UploadFileUtils(org.pentaho.platform.api.engine.IPentahoSession sessionValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
checkExtension(String extension, boolean emitMessage)
Checks if the given extension is supported.boolean
checkLimits(long itemSize)
boolean
checkLimits(long itemSize, boolean compressed)
String
getFileName()
Getters and SettersString
getPath()
File
getPathDir()
String
getRelativePath()
org.apache.commons.fileupload.FileItem
getUploadedFileItem()
javax.servlet.http.Part
getUploadedPart()
Writer
getWriter()
protected String
handleGZip(File file, boolean fullPath)
protected String
handleTar(File file)
protected String
handleTarGZ(File file)
protected boolean
handleUnzip(File file)
protected String
handleZip(File file)
Decompress a zip file and return a list of the file names that were unpackedboolean
isShouldUnzip()
boolean
isTemporary()
boolean
process()
boolean
process(InputStream inputStream)
process uploading using inputStream instead of UploadedFileItem do not support unzippingprotected String
removeFileName(String filename)
Removes the file name, leaving all extensions of a given filename.void
setFileName(String value)
void
setShouldUnzip(boolean value)
void
setTemporary(boolean value)
void
setUploadedFileItem(org.apache.commons.fileupload.FileItem value)
void
setUploadedPart(javax.servlet.http.Part uploadedPart)
void
setWriter(Writer value)
-
-
-
Field Detail
-
DEFAULT_RELATIVE_UPLOAD_FILE_PATH
public static final String DEFAULT_RELATIVE_UPLOAD_FILE_PATH
-
-
Method Detail
-
checkExtension
protected boolean checkExtension(String extension, boolean emitMessage) throws IOException
Checks if the given extension is supported.
A
null
is an invalid extension; to check if a NoExtension is allowed, an empty string must be given.- Parameters:
extension
- the extension to checkemitMessage
- if a message is to be written when an error occurs- Returns:
true
if the given extension is supported,false
if it's an invalid or unsupported extension- Throws:
IOException
-
process
public boolean process(InputStream inputStream) throws Exception
process uploading using inputStream instead of UploadedFileItem do not support unzipping- Parameters:
inputStream
-- Returns:
true
if the processing finished successfully andfalse
otherwise- Throws:
Exception
-
handleUnzip
protected boolean handleUnzip(File file) throws IOException
- Throws:
IOException
-
handleZip
protected String handleZip(File file) throws IOException
Decompress a zip file and return a list of the file names that were unpacked- Parameters:
file
-- Returns:
- Throws:
IOException
-
handleGZip
protected String handleGZip(File file, boolean fullPath) throws IOException
- Throws:
IOException
-
handleTar
protected String handleTar(File file) throws IOException
- Throws:
IOException
-
handleTarGZ
protected String handleTarGZ(File file) throws IOException
- Throws:
IOException
-
checkLimits
public boolean checkLimits(long itemSize) throws IOException
- Throws:
IOException
-
checkLimits
public boolean checkLimits(long itemSize, boolean compressed) throws IOException
- Throws:
IOException
-
removeFileName
protected String removeFileName(String filename)
Removes the file name, leaving all extensions of a given filename.
Returns
null
if filename isnull
, and an empty string if the filename is empty or has no extensions.The result, if not
null
nor an empty string is sanitized by replacing any character that is not a letter (lower or upper case), a digit (0-9), an underscore ("_"), a dot (".") or a dash ("-"), by an underscore ("_").- Parameters:
filename
- the filename for which we want the extensions- Returns:
- all extensions (sanitized) of the given filename
-
getFileName
public String getFileName()
Getters and Setters
-
setFileName
public void setFileName(String value)
-
isShouldUnzip
public boolean isShouldUnzip()
-
setShouldUnzip
public void setShouldUnzip(boolean value)
-
isTemporary
public boolean isTemporary()
-
setTemporary
public void setTemporary(boolean value)
-
setWriter
public void setWriter(Writer value)
-
getWriter
public Writer getWriter()
-
setUploadedFileItem
public void setUploadedFileItem(org.apache.commons.fileupload.FileItem value)
-
getUploadedFileItem
public org.apache.commons.fileupload.FileItem getUploadedFileItem()
-
getUploadedPart
public javax.servlet.http.Part getUploadedPart()
-
setUploadedPart
public void setUploadedPart(javax.servlet.http.Part uploadedPart)
-
getPath
public String getPath()
-
getPathDir
public File getPathDir()
-
getRelativePath
public String getRelativePath()
-
-