2.17.2: 2011-06-17

net.sf.basedb.plugins
Class PackedFileExporter

java.lang.Object
  extended by net.sf.basedb.core.plugin.AbstractPlugin
      extended by net.sf.basedb.core.plugin.AbstractExporterPlugin
          extended by net.sf.basedb.plugins.PackedFileExporter
All Implemented Interfaces:
ImmediateDownloadExporter, InteractivePlugin, Plugin, SignalTarget

public class PackedFileExporter
extends AbstractExporterPlugin
implements InteractivePlugin, SignalTarget

Plug-in that packs one or more selected files and directories into a single file. The actual packing is performed by classes implementing the FilePacker interface. To add new formats, create a class that implements the interface and, register the new class with a PluginConfiguration item.

The compressed file can either be downloaded immediately to the local computer or stored into BASE's file system.

Version:
2.4
Author:
Martin, Nicklas
Last modified
$Date: 2007-07-11 15:45:01 +0200 (Mon, 02 Jul 2007) $

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin
Plugin.MainType
 
Field Summary
private static About about
           
private  RequestInformation configureJob
           
private  RequestInformation configurePlugin
           
private  DbControl dc
           
private static GuiContext directoryGui
           
private static GuiContext fileGui
           
private static Set<GuiContext> guiContexts
           
private  int numFiles
           
private  PluginParameter<String> packerParameter
           
private static Set<Permissions> permissions
           
private  PluginParameter<Boolean> removeFilesParameter
           
private  List<Integer> selectedDirs
           
private  List<Integer> selectedFiles
           
private  List<Nameable> selectedFilesAndDirs
           
private  ThreadSignalHandler signalHandler
           
private  long totalBytes
           
 
Fields inherited from class net.sf.basedb.core.plugin.AbstractExporterPlugin
optionalSaveAsType, OVERWRITE, overwriteType, requiredSaveAsType, SAVE_AS
 
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc
 
Constructor Summary
PackedFileExporter()
          Create new instance.
 
Method Summary
protected  void begin(DbControl dc)
          Called just before the export starts.
 void configure(GuiContext context, Request request, Response response)
          Configure the plugin.
protected  void end(boolean success)
          Called just after everything has been committed to the database, or immediately after an error has ocurred.
private  String generateDefaultName(FilePacker packer, Directory rootDir, Collection<Nameable> selectedItems)
          Generate a default name without a path for the packed file.
private  String generateDefaultPath(FilePacker packer, Directory rootDir, Collection<Nameable> selectedItems)
          Generate a default path for the packed file.
 About getAbout()
          Get information about the plugin, such as name, version, authors, etc.
private  RequestInformation getConfigureJobParameters(GuiContext context, Boolean requireFile)
           
private  RequestInformation getConfigurePluginParameters()
           
 Set<GuiContext> getGuiContexts()
          Get a set containing all items that the plugin handles.
private  FilePacker getPacker()
          Get the FilePacker that has been configured in the current configuration.
private  FilePacker getPacker(String packerClass)
          Create a FilePacker from the given class.
 Collection<Permissions> getPermissions()
          Request create and delete 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  String getSuccessMessage()
          Called if the export was successful to let the subclass generate a simple message that is sent back to the core and user interface.
 String isInContext(GuiContext context, Object item)
          Check that at least one file or directory has been selected.
private  void loadFiles(DbControl dc, Collection<Nameable> loadedFiles, Directory directory)
          Load files and subdirectories in the given directory.
private  void loadFilesAndDirectories(DbControl dc, Collection<Nameable> loadedFiles, Collection<Integer> files, Collection<Integer> directories, boolean recursive)
          Load specified files and directories and put them in loadedFiles.
protected  void performExport(ExportOutputStream out, ProgressReporter progress)
          Perform the export.
 boolean requiresConfiguration()
          Returns FALSE, since that is how the plugins used to work before this method was introduced.
 boolean supportsConfigurations()
          Returns TRUE, since that is how the plugins used to work before this method was introduced.
 
Methods inherited from class net.sf.basedb.core.plugin.AbstractExporterPlugin
doExport, getMainType, getOverwrite, getOverwriteParameter, getSaveAsParameter, getSaveAsPath, getSaveTo, pathCanBeUsed, run
 
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.core.plugin.Plugin
done, getMainType, init, run
 

Field Detail

about

private static final About about

fileGui

private static final GuiContext fileGui

directoryGui

private static final GuiContext directoryGui

guiContexts

private static final Set<GuiContext> guiContexts

permissions

private static final Set<Permissions> permissions

configureJob

private RequestInformation configureJob

configurePlugin

private RequestInformation configurePlugin

removeFilesParameter

private PluginParameter<Boolean> removeFilesParameter

packerParameter

private PluginParameter<String> packerParameter

numFiles

private int numFiles

totalBytes

private long totalBytes

selectedFiles

private List<Integer> selectedFiles

selectedDirs

private List<Integer> selectedDirs

selectedFilesAndDirs

private List<Nameable> selectedFilesAndDirs

signalHandler

private ThreadSignalHandler signalHandler

dc

private DbControl dc
Constructor Detail

PackedFileExporter

public PackedFileExporter()
Create new instance.

Method Detail

getAbout

public About getAbout()
Description copied from interface: Plugin
Get information about the plugin, such as name, version, authors, etc.

Specified by:
getAbout in interface Plugin
Returns:
An About object

supportsConfigurations

public boolean supportsConfigurations()
Description copied from class: AbstractPlugin
Returns TRUE, since that is how the plugins used to work before this method was introduced.

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

requiresConfiguration

public boolean requiresConfiguration()
Description copied from class: AbstractPlugin
Returns FALSE, since that is how the plugins used to work before this method was introduced.

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

getPermissions

public Collection<Permissions> getPermissions()
Request create and delete 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

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)
Check that at least one file or directory has been selected.

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

begin

protected void begin(DbControl dc)
Description copied from class: AbstractExporterPlugin
Called just before the export starts. A subclass may override this method if it needs to initialise some resources.

Overrides:
begin in class AbstractExporterPlugin
Parameters:
dc - The DbControl that is used to write to the database. A subclass may use this read from the database as well
See Also:
AbstractExporterPlugin.end(boolean)

performExport

protected void performExport(ExportOutputStream out,
                             ProgressReporter progress)
                      throws IOException
Description copied from class: AbstractExporterPlugin
Perform the export. This method replaces the ImmediateDownloadExporter.doExport(ExportOutputStream, ProgressReporter) method.

Specified by:
performExport in class AbstractExporterPlugin
Parameters:
out - Output stream to write the exported data to
progress - An optional progress reporter
Throws:
IOException

end

protected void end(boolean success)
Description copied from class: AbstractExporterPlugin
Called just after everything has been committed to the database, or immediately after an error has ocurred. A subclass should clean up any resources aquired in the AbstractExporterPlugin.begin(DbControl) method here.

Overrides:
end in class AbstractExporterPlugin
Parameters:
success - TRUE if the file was parsed successfully, FALSE otherwise
See Also:
AbstractExporterPlugin.begin(DbControl)

getSuccessMessage

protected String getSuccessMessage()
Description copied from class: AbstractExporterPlugin
Called if the export was successful to let the subclass generate a simple message that is sent back to the core and user interface. An example message might by: 178 reporters exported successfully. The default implementation always return null.

Overrides:
getSuccessMessage in class AbstractExporterPlugin

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

getConfigureJobParameters

private RequestInformation getConfigureJobParameters(GuiContext context,
                                                     Boolean requireFile)

getConfigurePluginParameters

private RequestInformation getConfigurePluginParameters()

loadFilesAndDirectories

private void loadFilesAndDirectories(DbControl dc,
                                     Collection<Nameable> loadedFiles,
                                     Collection<Integer> files,
                                     Collection<Integer> directories,
                                     boolean recursive)
Load specified files and directories and put them in loadedFiles. This method also calculates the total size of all files and stores it in totalBytes.

Parameters:
dc - The DbControl to use for loading
loadedFiles - The files and directories will be added to this collection
files - The ID of the files to load
directories - The ID of the directories to load
recursive - If we should recurse into subdirectories or not

loadFiles

private void loadFiles(DbControl dc,
                       Collection<Nameable> loadedFiles,
                       Directory directory)
Load files and subdirectories in the given directory.

Parameters:
dc - The DbControl to use for loading
loadedFiles - The files and directories will be added to this collection
directory - The parent directory

getPacker

private FilePacker getPacker()
Get the FilePacker that has been configured in the current configuration.


getPacker

private FilePacker getPacker(String packerClass)
                      throws Exception
Create a FilePacker from the given class.

Parameters:
packerClass - The class name of a class that implements FilePacker
Throws:
Exception

generateDefaultPath

private String generateDefaultPath(FilePacker packer,
                                   Directory rootDir,
                                   Collection<Nameable> selectedItems)
Generate a default path for the packed file. If the selection contains only one file or directory, the name of that item is used, otherwise the name of the root directory is used. The file extension from FilePacker.getFileExtension() is automatically appeneded.

Parameters:
packer - The current FilePacker
rootDir - The root directory
selectedItems - The selected items (not including subdirectories)

generateDefaultName

private String generateDefaultName(FilePacker packer,
                                   Directory rootDir,
                                   Collection<Nameable> selectedItems)
Generate a default name without a path for the packed file.

See Also:
generateDefaultPath(FilePacker, Directory, Collection)

2.17.2: 2011-06-17