Class AbstractExporterPlugin
- All Implemented Interfaces:
ImmediateDownloadExporter
,Plugin
- Direct Known Subclasses:
BaseFileExporterPlugin
,GalExporter
,HelpExporter
,PackedFileExporter
,PlateMappingExporter
,PluginConfigurationExporter
,SimpleExport
ImmediateDownloadExporter
interface. This class implements
that interface, but you have to implement the performExport(ExportOutputStream, ProgressReporter)
instead which has the same requirements as the ImmediateDownloadExporter.doExport(ExportOutputStream, ProgressReporter)
method.
This class also implements the run(Request, Response, ProgressReporter)
method
but if you want to use it you must use the parameters for the file path and
overwrite option as they are defined in this class. Use the getSaveAsParameter(String, String, String, boolean)
and getOverwriteParameter(String, String)
to generate the parameter
objects and then the getSaveAsPath(DbControl)
and getOverwrite()
to get values entered by the user.
This class doesn't override any methods of the InteractivePlugin
interface. It is your responsibility to ask for the correct parameters
and save them to the job. See the HelpExporter
implementation forexample code.
- Version:
- 2.2
- 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 TypeFieldDescriptionprotected static final PathParameterType
protected static final String
Parameter name for thegetOverwriteParameter(String, String)
parameter.protected static final BooleanParameterType
protected static final PathParameterType
protected static final String
Parameter name for thegetSaveAsParameter(String, String, String, boolean)
parameter.private File
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc
-
Constructor Summary
ModifierConstructorDescriptionprotected
Create a newAbstractExporterPlugin
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called just before the export starts.final void
doExport
(ExportOutputStream out, ProgressReporter progress) Implements immediate downloading.protected void
end
(boolean success) Called just after everything has been committed to the database, or immediately after an error has ocurred.Get the type of the plugin.boolean
Get the configured value for the overwrite parameter.protected PluginParameter<Boolean>
getOverwriteParameter
(String label, String description) Get a plugin parameter that asks if existing files can be overwritten or not.protected PluginParameter<String>
getSaveAsParameter
(String label, String description, String defaultValue, boolean required) Get a plugin parameter that asks for the path to a file where the exported data should be saved.protected Path
Get the configured path where the exported data should be saved.protected File
Get the file object that the current export is writing to.protected String
Called if the export was successful to let the subclass generate a simple message that is sent back to the core and user interface.protected boolean
pathCanBeUsed
(String strPath, boolean overwrite) See if file path already exists and if it's allowed to overwrite it.protected abstract void
performExport
(ExportOutputStream out, ProgressReporter progress) Perform the export.void
run
(Request request, Response response, ProgressReporter progress) Checks theSAVE_AS
parameter for the path to save the exported data.Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin
cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, getPermissions, init, isLogging, log, log, requiresConfiguration, storeValue, storeValue, storeValues, supportsConfigurations, 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, getPermissions, init, requiresConfiguration, supportsConfigurations
-
Field Details
-
optionalSaveAsType
-
requiredSaveAsType
-
overwriteType
-
saveTo
-
SAVE_AS
Parameter name for thegetSaveAsParameter(String, String, String, boolean)
parameter.- See Also:
-
OVERWRITE
Parameter name for thegetOverwriteParameter(String, String)
parameter.- See Also:
-
-
Constructor Details
-
AbstractExporterPlugin
protected AbstractExporterPlugin()Create a newAbstractExporterPlugin
.
-
-
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:
- MainType.EXPORT
-
run
Checks theSAVE_AS
parameter for the path to save the exported data. If the file doesn't exists it is created. If the file exists theOVERWRITE
parameter is checked if overwriting is ok. Files marked for deletion will always be overwritten. If no path has been specified an error response is sent.Then, the subclass is called to generate the export. The following methods are called:
begin(DbControl)
performExport(ExportOutputStream, ProgressReporter)
end(boolean)
(after the DbControl has been committed)getSuccessMessage()
(only if no error ocurred)
- 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
-
doExport
Implements immediate downloading. Calls the subclass methods in the following order:begin(DbControl)
performExport(ExportOutputStream, ProgressReporter)
end(boolean)
(after the DbControl has been committed)
- Specified by:
doExport
in interfaceImmediateDownloadExporter
- Parameters:
out
- The output stream that the exported data should be written toprogress
- An optional progress reporter, may be null- Throws:
IOException
- If there is an error writing to the export stream
-
begin
Called just before the export starts. A subclass may override this method if it needs to initialise some resources.- 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:
-
getSaveTo
Get the file object that the current export is writing to. This method may return a file object that already exists in the database, a new file that is saved when the transaction is committed or null if the export is a 'download immediately' export.- Returns:
- A file object or null
- Since:
- 2.7
-
performExport
protected abstract void performExport(ExportOutputStream out, ProgressReporter progress) throws IOException Perform the export. This method replaces theImmediateDownloadExporter.doExport(ExportOutputStream, ProgressReporter)
method.- Parameters:
out
- Output stream to write the exported data toprogress
- An optional progress reporter- Throws:
IOException
-
end
protected void end(boolean success) 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 thebegin(DbControl)
method here.- Parameters:
success
- TRUE if the file was parsed successfully, FALSE otherwise- See Also:
-
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. An example message might by:178 reporters exported successfully
. The default implementation always return null. -
getSaveAsParameter
protected PluginParameter<String> getSaveAsParameter(String label, String description, String defaultValue, boolean required) Get a plugin parameter that asks for the path to a file where the exported data should be saved. If no path is specified by the user the data will be downloaded immediately.- Parameters:
label
- The parameter label, or null to use the default (Save as)description
- The parameter description, or null to use the default (The path to the file where the exported data should be placed. Leave empty to download immediately.)defaultValue
- A default filename, or null to not use any defaultrequired
- If the parameter is required or optional
-
getSaveAsPath
Get the configured path where the exported data should be saved.- Parameters:
dc
- A DbControl which is needed to find the currently logged in user if the path starts with '~/' = Home directory of logged in user- Returns:
- A path or null if no path has been specified
-
getOverwriteParameter
Get a plugin parameter that asks if existing files can 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 (If it is allowed to overwrite an existing file or not.)
-
getOverwrite
public boolean getOverwrite()Get the configured value for the overwrite parameter.- Returns:
- A boolean, if no values has been specified false is returned
- See Also:
-
pathCanBeUsed
See if file path already exists and if it's allowed to overwrite it.- Parameters:
strPath
- The file path to be checked.overwrite
- TRUE If it is allowed to overwrite the file, FALSE otherwise.- Returns:
- FALSE If the file path exists and isn't allowed to be overwritten or TRUE otherwise.
-