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 StringDEFAULT_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 booleancheckExtension(String extension, boolean emitMessage)Checks if the given extension is supported.booleancheckLimits(long itemSize)booleancheckLimits(long itemSize, boolean compressed)StringgetFileName()Getters and SettersStringgetPath()FilegetPathDir()StringgetRelativePath()org.apache.commons.fileupload.FileItemgetUploadedFileItem()javax.servlet.http.PartgetUploadedPart()WritergetWriter()protected StringhandleGZip(File file, boolean fullPath)protected StringhandleTar(File file)protected StringhandleTarGZ(File file)protected booleanhandleUnzip(File file)protected StringhandleZip(File file)Decompress a zip file and return a list of the file names that were unpackedbooleanisShouldUnzip()booleanisTemporary()booleanprocess()booleanprocess(InputStream inputStream)process uploading using inputStream instead of UploadedFileItem do not support unzippingprotected StringremoveFileName(String filename)Removes the file name, leaving all extensions of a given filename.voidsetFileName(String value)voidsetShouldUnzip(boolean value)voidsetTemporary(boolean value)voidsetUploadedFileItem(org.apache.commons.fileupload.FileItem value)voidsetUploadedPart(javax.servlet.http.Part uploadedPart)voidsetWriter(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
nullis 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:
trueif the given extension is supported,falseif 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:
trueif the processing finished successfully andfalseotherwise- 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
nullif filename isnull, and an empty string if the filename is empty or has no extensions.The result, if not
nullnor 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()
-
-