2.17.2: 2011-06-17

net.sf.basedb.util.zip
Class AbstractFileUnpacker

java.lang.Object
  extended by net.sf.basedb.core.plugin.AbstractPlugin
      extended by net.sf.basedb.util.zip.AbstractFileUnpacker
All Implemented Interfaces:
InteractivePlugin, Plugin, SignalTarget, FileUnpacker
Direct Known Subclasses:
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:

A subclass may override any of the methods in this class if it has different needs.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2010-11-08 14:49:35 +0100 (Mon, 08 Nov 2010) $

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin
Plugin.MainType
 
Field Summary
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
AbstractFileUnpacker()
           
 
Method Summary
 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 the RequestInformation 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
checkInterrupted, 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
 
Methods inherited from interface net.sf.basedb.core.plugin.Plugin
done, getAbout, init
 

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.

See Also:
getZipFileParameter(String, String), Constant Field Values

UNPACK_DIRECTORY

protected static final String UNPACK_DIRECTORY
The name of the parameter that asks for the directory where the unpacked files are stored.

See Also:
getZipFileParameter(String, String), Constant Field Values

OVERWRITE

protected static final String OVERWRITE
The name of the parameter that asks if existing files should be overwritten or not.

See Also:
getOverwriteParameter(String, String), Constant Field Values
Constructor Detail

AbstractFileUnpacker

public AbstractFileUnpacker()
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 interface Plugin
Returns:
One of the defined types

supportsConfigurations

public boolean supportsConfigurations()
Returns FALSE.

Specified by:
supportsConfigurations in interface Plugin
Overrides:
supportsConfigurations in class AbstractPlugin
Returns:
TRUE or FALSE

requiresConfiguration

public boolean requiresConfiguration()
Returns FALSE.

Specified by:
requiresConfiguration in interface Plugin
Overrides:
requiresConfiguration in class AbstractPlugin
Returns:
TRUE or FALSE

getPermissions

public Collection<Permissions> getPermissions()
Request create and write access to File:s and Directory:s.

Specified by:
getPermissions in interface Plugin
Overrides:
getPermissions in class AbstractPlugin
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 interface Plugin
Parameters:
request - Request object with the command and parameters
response - Response object in for the plugin to response through
progress - A ProgressReporter 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 containing Item.REPORTER. This information is used by client applications to put the plugin in the proper place in the user interface.

Specified by:
getGuiContexts in interface InteractivePlugin
Returns:
A Set containing Item: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 a BasicItem or BasicData 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 the InteractivePlugin.getGuiContexts() method. For GuiContext.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 interface InteractivePlugin
Parameters:
context - The current context of the client application, it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
item - The currently active item, it's type should match the GuiContext.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 the RequestInformation for a given command, i.e. the list of parameters and some nice help text.

Specified by:
getRequestInformation in interface InteractivePlugin
Parameters:
context - The current context of the client application, it is one of the values found in set returned by InteractivePlugin.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 by InteractivePlugin.getRequestInformation(GuiContext, String).

Specified by:
configure in interface InteractivePlugin
Parameters:
context - The current context of the client application, it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
request - Request object with the command and parameters
response - 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 interface SignalTarget
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)

2.17.2: 2011-06-17