Package net.sf.basedb.util.zip
Class AbstractFileUnpacker
- java.lang.Object
-
- net.sf.basedb.core.plugin.AbstractPlugin
-
- net.sf.basedb.util.zip.AbstractFileUnpacker
-
- All Implemented Interfaces:
InteractivePlugin
,Plugin
,SignalTarget
,FileUnpacker
- Direct Known Subclasses:
Bzip2FileUnpacker
,GzipFileUnpacker
,TarFileUnpacker
,ZipFileUnpacker
public abstract class AbstractFileUnpacker extends AbstractPlugin implements FileUnpacker, InteractivePlugin, SignalTarget
This is a base class for all plugins that wants to implement theFileUnpacker
interface. This class takes care of all the hard work that is required by a plugin. Ie. the creating and saving the parameters that are needed, context checking, etc. The subclass only has to implement the remaingin methods in theFileUnpacker
interface which basically boils down to implementing the actual unpacking of the compressed file.The implementation in this class asks for three parameters:
- The file to unpack
- The directory where the files should be placed
- If existing files should be overwritten or not
- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2012-09-14 09:28:35 +0200 (fr, 14 sep 2012) $
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin
Plugin.MainType
-
-
Field Summary
Fields Modifier and Type Field Description private RequestInformation
configureJob
private static Set<GuiContext>
guiContexts
The context is always [ FILE, ITEM].protected static String
OVERWRITE
The name of the parameter that asks if existing files should be overwritten or not.private static Set<Permissions>
permissions
private ThreadSignalHandler
signalHandler
protected static String
UNPACK_DIRECTORY
The name of the parameter that asks for the directory where the unpacked files are stored.private static PathParameterType
unpackType
The parameter type for unpack directory.protected static String
ZIP_FILE
The name of the parameter that asks for the file that is going to be unpacked.private static ItemParameterType<File>
zipFileType
The parameter type for file to unpack.-
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc
-
-
Constructor Summary
Constructors Constructor Description AbstractFileUnpacker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(GuiContext context, Request request, Response response)
Configure the plugin.private RequestInformation
getConfigureJobParameters(GuiContext context)
protected Directory
getCurrentDirectory(DbControl dc)
Get the current directory or null there is no current or it can't be loaded.protected File
getCurrentFile(DbControl dc)
Get the current file or null there is no current or it can't be loaded.protected PluginParameter<String>
getDirectoryParameter(String label, String description)
Get a plugin parameter that asks for the directory where the unpacked files are stored.Set<GuiContext>
getGuiContexts()
Get a set containing all items that the plugin handles.Plugin.MainType
getMainType()
Get the type of the plugin.protected boolean
getOverwrite()
If existing file should be overwritten or not.protected PluginParameter<Boolean>
getOverwriteParameter(String label, String description)
Get a plugin parameter that asks if existing files should be overwritten or not.Collection<Permissions>
getPermissions()
Request create and write access to File:s and Directory:s.RequestInformation
getRequestInformation(GuiContext context, String command)
This method will return theRequestInformation
for a given command, i.e.SignalHandler
getSignalHandler()
Get the signal handler that is handling signals on behalf of this object.protected Directory
getUnpackDirectory(DbControl dc)
Get the directory where the unpacked files are placed by the plugin.protected File
getZipFile(DbControl dc)
Get the file that is going to be unpacked by the plugin.protected PluginParameter<File>
getZipFileParameter(String label, String description)
Get a plugin parameter that asks for the file that is going to be unpacked.String
isInContext(GuiContext context, Object item)
Check if the plugin can be used on the specified object.boolean
requiresConfiguration()
Returns FALSE.void
run(Request request, Response response, ProgressReporter progress)
Run the plugin.boolean
supportsConfigurations()
Returns FALSE.-
Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin
cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, init, log, log, storeValue, storeValue, storeValues, validateRequestParameters
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.basedb.util.zip.FileUnpacker
getExtensions, getFormatName, getMimeTypes, unpack
-
-
-
-
Field Detail
-
guiContexts
private static final Set<GuiContext> guiContexts
The context is always [ FILE, ITEM].
-
permissions
private static final Set<Permissions> permissions
-
zipFileType
private static final ItemParameterType<File> zipFileType
The parameter type for file to unpack.
-
unpackType
private static final PathParameterType unpackType
The parameter type for unpack directory.
-
configureJob
private RequestInformation configureJob
-
signalHandler
private ThreadSignalHandler signalHandler
-
ZIP_FILE
protected static final String ZIP_FILE
The name of the parameter that asks for the file that is going to be unpacked.
-
UNPACK_DIRECTORY
protected static final String UNPACK_DIRECTORY
The name of the parameter that asks for the directory where the unpacked files are stored.
-
OVERWRITE
protected static final String OVERWRITE
The name of the parameter that asks if existing files should be overwritten or not.
-
-
Method Detail
-
getMainType
public Plugin.MainType getMainType()
Description copied from interface:Plugin
Get the type of the plugin. This method must always return the same value.- Specified by:
getMainType
in interfacePlugin
- Returns:
- One of the defined types
-
supportsConfigurations
public boolean supportsConfigurations()
Returns FALSE.- Specified by:
supportsConfigurations
in interfacePlugin
- Overrides:
supportsConfigurations
in classAbstractPlugin
- Returns:
- TRUE or FALSE
-
requiresConfiguration
public boolean requiresConfiguration()
Returns FALSE.- Specified by:
requiresConfiguration
in interfacePlugin
- Overrides:
requiresConfiguration
in classAbstractPlugin
- Returns:
- TRUE or FALSE
-
getPermissions
public Collection<Permissions> getPermissions()
Request create and write access to File:s and Directory:s.- Specified by:
getPermissions
in interfacePlugin
- Overrides:
getPermissions
in classAbstractPlugin
- Returns:
- A collection of permissions or null to not use permissions
-
run
public void run(Request request, Response response, ProgressReporter progress)
Description copied from interface:Plugin
Run the plugin. If a progress reporter object is passed it is recommended that the plugin makes use of it.- Specified by:
run
in interfacePlugin
- Parameters:
request
- Request object with the command and parametersresponse
- Response object in for the plugin to response throughprogress
- AProgressReporter
where the plugin can report its progess, can be null
-
getGuiContexts
public Set<GuiContext> getGuiContexts()
Description copied from interface:InteractivePlugin
Get a set containing all items that the plugin handles. Ie. if the plugin imports reporters, return a set containingItem.REPORTER
. This information is used by client applications to put the plugin in the proper place in the user interface.- Specified by:
getGuiContexts
in interfaceInteractivePlugin
- Returns:
- A
Set
containingItem
:s, or null if the plugin is not concerned about items
-
isInContext
public String isInContext(GuiContext context, Object item)
Description copied from interface:InteractivePlugin
Check if the plugin can be used on the specified object. The item is either aBasicItem
orBasicData
object, or null if called from a list context. A client application should only call this method for contexts matching one of the contexts in the set returned by theInteractivePlugin.getGuiContexts()
method. ForGuiContext.Type.ITEM
contexts an item of the correct type should be passed as a parameter.The plug-in can response with a null value indicating success, a warning-level message or throw an exception to indicate an error-level message. Client application should normally only show error-level messages to users, unless the user has requested to see warning messages.
NOTE! Before BASE 2.4 all messages were treated as error-level messages.
- Specified by:
isInContext
in interfaceInteractivePlugin
- Parameters:
context
- The current context of the client application, it is one of the values found in set returned byInteractivePlugin.getGuiContexts()
item
- The currently active item, it's type should match theGuiContext.getItem()
type, or null if the context is a list context- Returns:
Null
if the plugin can use that item, or a warning-level message explaining why the plugin can't be used
-
getRequestInformation
public RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException
Description copied from interface:InteractivePlugin
This method will return theRequestInformation
for a given command, i.e. the list of parameters and some nice help text.- Specified by:
getRequestInformation
in interfaceInteractivePlugin
- Parameters:
context
- The current context of the client application, it is one of the values found in set returned byInteractivePlugin.getGuiContexts()
command
- The command- Returns:
- The
RequestInformation
for the command - Throws:
BaseException
- if there is an error
-
configure
public void configure(GuiContext context, Request request, Response response)
Description copied from interface:InteractivePlugin
Configure the plugin. Hopefully the client is supplying values for the parameters specified byInteractivePlugin.getRequestInformation(GuiContext, String)
.- Specified by:
configure
in interfaceInteractivePlugin
- Parameters:
context
- The current context of the client application, it is one of the values found in set returned byInteractivePlugin.getGuiContexts()
request
- Request object with the command and parametersresponse
- Response object in for the plugin to response through
-
getSignalHandler
public SignalHandler getSignalHandler()
Description copied from interface:SignalTarget
Get the signal handler that is handling signals on behalf of this object. Multiple invokations of this method may receive the same or different objects. Null may be returned if, for some reason, the current object instance doesn't want to receive signals. Returning null is the same as not implementing this interface.- Specified by:
getSignalHandler
in interfaceSignalTarget
- Returns:
- A SignalHandler object, or null if the current instance doesn't support signals
-
getZipFileParameter
protected PluginParameter<File> getZipFileParameter(String label, String description)
Get a plugin parameter that asks for the file that is going to be unpacked.- Parameters:
label
- The parameter label, or null to use the default (File)description
- The parameter description, or null to use the default (The file to unpack.)
-
getZipFile
protected File getZipFile(DbControl dc)
Get the file that is going to be unpacked by the plugin. The file is only available in the execution phase if the plugin has saved it as a job parameter during the configuration of a job (this is the default)- Returns:
- The packed file or null
- See Also:
getZipFileParameter(String, String)
,getCurrentFile(DbControl)
-
getDirectoryParameter
protected PluginParameter<String> getDirectoryParameter(String label, String description)
Get a plugin parameter that asks for the directory where the unpacked files are stored.- Parameters:
label
- The parameter label, or null to use the default (Save in)description
- The parameter description, or null to use the default (The directory where the unpacked files should be saved.)
-
getCurrentDirectory
protected Directory getCurrentDirectory(DbControl dc)
Get the current directory or null there is no current or it can't be loaded. This method will first try to load the current file and use the file's directory as the current. If there is no current file, the current directory is loaded from the session context. The current directory is only available in the configuration phase.- Parameters:
dc
- A DbControl to use for database access- Returns:
- A directory or null
- Since:
- 2.4
- See Also:
getUnpackDirectory(DbControl)
-
getCurrentFile
protected File getCurrentFile(DbControl dc)
Get the current file or null there is no current or it can't be loaded. The current file is only available in the configuration phase.- Parameters:
dc
- A DbControl to use for database access- Returns:
- A file or null
- Since:
- 2.4
- See Also:
getZipFile(DbControl)
-
getUnpackDirectory
protected Directory getUnpackDirectory(DbControl dc)
Get the directory where the unpacked files are placed by the plugin. The directory is only available in the execution phase if the plugin has saved it as a job parameter during the configuration of a job.- Returns:
- The directory or null
- See Also:
getDirectoryParameter(String, String)
,getCurrentDirectory(DbControl)
-
getOverwriteParameter
protected PluginParameter<Boolean> getOverwriteParameter(String label, String description)
Get a plugin parameter that asks if existing files should be overwritten or not.- Parameters:
label
- The parameter label, or null to use the default (Overwrite)description
- The parameter description, or null to use the default (Specify if existing files should be overwritten or not.)
-
getOverwrite
protected boolean getOverwrite()
If existing file should be overwritten or not.- Returns:
- TRUE if files should be overwritten, FALSE otherwise
- See Also:
getOverwriteParameter(String, String)
-
getConfigureJobParameters
private RequestInformation getConfigureJobParameters(GuiContext context)
-
-