The BASE web client has integrated support for unpacking of
compressed files. See Section 7.2.1, “Upload a new file”.
Behind the scenes, this support is provided by plug-ins. The standard
BASE distribution comes with support for ZIP files
and TAR files (
To add support for additional compressed formats you have to create a plug-in that
interface. The best way to do this is to extend the
implements all methods in the
interfaces. This leaves
you with the actual unpacking of the files as the only thing to implement.
|No support for configurations|
|The integrated upload in the web interface only works with plug-ins that does not require a configuration to run.|
public String getFormatName();
Return a short string naming the file format. For example:
ZIP files or
public Set<String> getExtensions();
Return a set of strings with the file extensions that
are most commonly used with the compressed file format.
[zip, jar]. Do not include
the dot in the extensions. The web client and the
will use this information to automatically guess which plug-in to
use for unpacking the files.
public Set<String> getMimeTypes();
Return a set of string with the MIME types that commonly used with
the compressed file format. For example:
This information is used by the
method to automatically guess which plug-in to use for unpacking
public int unpack(DbControl dc,
throws IOException, BaseException;
Unpack the files and store them in the BASE file system.
dir parameter is the root directory where
the unpacked files should be placed. If the compressed file
contains subdirectories the plug-in must create those subdirectories
unless they already exists.
overwrite parameter is
FALSE no existing file should be overwritten
unless the file is
OFFLINE or marked as
removed (do not forget to clear the removed attribute).
in parameter is the stream
containing the compressed data. The stream may come
directly from the web upload or from an existing
file in the BASE file system.
sourceFile parameter is the file
item representing the compressed file. This item may already be in
the database, or a new item that may or may not be saved in the database
at the end of the transaction. The information in this parameter
can be used to discover the options for file type, character set, MIME
type, etc. that was selected by the user in the upload dialog.
has a useful method that can be used for copying information.
progress parameter, if not
null, should be used to report the
progress back to the calling code. The plug-in should count
the number of bytes read from the
stream. If it is not possible by other means the stream can
be wrapped by a
object which has a
When the compressed file is uncompressed during the file upload from the web interface, the call sequence to the plug-in is slightly altered from the standard call sequence described in the section called “Executing a job”.
After the plug-in instance has been created, the
Plugin.init() method is called with
values for both the
unpack() method is called. The
Plugin.run() method is never called in this case.
BASE has support for compressing and downloading a set of selected files and/or
directories. This functionality is provided by a plug-in, the
PackedFileExporter. This plug-in doesn't do the actual
packing itself. This is delegated to classes implementing the
BASE ships with a number of packing methods, including ZIP and TAR. To
add support for other methods you have to provide an implementation
interface. Then, create a new configuration for the
and enter the name of your class in the configuration wizard.
FilePacker interface is not a regular
plug-in interface (ie. it is not a subinterface to
Plugin). This means that you don't have to
mess with configuration or job parameters. Another difference is that your
class must be installed in Tomcat's classpath (ie. in one of the
|This may be converted to an extension point in the future|
There are certain plans to convert the packing mechanism to an extension point in the future. The main reason is easier installation since code doesn't have to be installed in the WEB-INF/lib or WEB-INF/classes directory. See ticket #1600: Convert file packing plug-in system to an extension point for more information.
public String getDescription();
Return a short description the file format that is suitable for use
in dropdown lists in client applications. For example:
Zip-archive (.zip) or
public String getFileExtension();
Return the default file extension of the packed format. The returned
value should not include the dot. For example:
public String getMimeType();
Return the standard MIME type of the packed file format.
public void setOutputStream(OutputStream out)
Sets the outputstream that the packer should write the packed files to.
public void pack(String entryName,
Add another file or directory to the packed file. The
entryName is the name of the new entry, including
path information. The
in is the stream to read
the file data from. If
then the entry denotes a directory. The
gives the size in bytes of the file (zero for empty files or directories).
is that time the file was last modified or 0 if not known.
public void close()
Finish the packing. The packer should release any resources, flush
all data and close all output streams, including the
set in the