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
A subclass may override any of the methods in this class if it has different needs.
Version:
2.0
Author:
nicklas
Last modified
$Date: 2012-09-14 09:28:35 +0200 (fr, 14 sep 2012) $
  • Field Details

  • Constructor Details

    • AbstractFileUnpacker

      public AbstractFileUnpacker()
  • Method Details

    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • getConfigureJobParameters

      private RequestInformation getConfigureJobParameters(GuiContext context)