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 the
FileUnpacker
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 the FileUnpacker
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
Modifier and TypeFieldDescriptionprivate RequestInformation
private static final Set<GuiContext>
The context is always [ FILE, ITEM].protected static final String
The name of the parameter that asks if existing files should be overwritten or not.private static final Set<Permissions>
private ThreadSignalHandler
protected static final String
The name of the parameter that asks for the directory where the unpacked files are stored.private static final PathParameterType
The parameter type for unpack directory.protected static final String
The name of the parameter that asks for the file that is going to be unpacked.private static final ItemParameterType<File>
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(GuiContext context, Request request, Response response) Configure the plugin.private RequestInformation
getConfigureJobParameters
(GuiContext context) protected Directory
Get the current directory or null there is no current or it can't be loaded.protected File
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.Get a set containing all items that the plugin handles.Get the type of the plugin.protected boolean
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.Request create and write access to File:s and Directory:s.getRequestInformation
(GuiContext context, String command) This method will return theRequestInformation
for a given command, i.e.Get the signal handler that is handling signals on behalf of this object.protected Directory
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.isInContext
(GuiContext context, Object item) Check if the plugin can be used on the specified object.boolean
Returns FALSE.void
run
(Request request, Response response, ProgressReporter progress) Run the plugin.boolean
Returns FALSE.Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin
cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, init, isLogging, 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 Details
-
guiContexts
The context is always [ FILE, ITEM]. -
permissions
-
zipFileType
The parameter type for file to unpack. -
unpackType
The parameter type for unpack directory. -
configureJob
-
signalHandler
-
ZIP_FILE
The name of the parameter that asks for the file that is going to be unpacked. -
UNPACK_DIRECTORY
The name of the parameter that asks for the directory where the unpacked files are stored. -
OVERWRITE
The name of the parameter that asks if existing files should be overwritten or not.
-
-
Constructor Details
-
AbstractFileUnpacker
public AbstractFileUnpacker()
-
-
Method Details
-
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
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
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
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
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
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
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
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
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:
-
getDirectoryParameter
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
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:
-
getCurrentFile
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:
-
getUnpackDirectory
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:
-
getOverwriteParameter
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:
-
getConfigureJobParameters
-