|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.plugin.AbstractPlugin net.sf.basedb.core.plugin.AbstractExporterPlugin
public abstract class AbstractExporterPlugin
An abstract base class for all exporter plugins that wish to implement
the 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin |
---|
Plugin.MainType |
Field Summary | |
---|---|
protected static PathParameterType |
optionalSaveAsType
|
protected static String |
OVERWRITE
Parameter name for the getOverwriteParameter(String, String) parameter. |
protected static BooleanParameterType |
overwriteType
|
protected static PathParameterType |
requiredSaveAsType
|
protected static String |
SAVE_AS
Parameter name for the getSaveAsParameter(String, String, String, boolean)
parameter. |
private File |
saveTo
|
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin |
---|
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc |
Constructor Summary | |
---|---|
protected |
AbstractExporterPlugin()
Create a new AbstractExporterPlugin . |
Method Summary | |
---|---|
protected void |
begin(DbControl dc)
Called just before the export starts. |
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. |
Plugin.MainType |
getMainType()
Get the type of the plugin. |
boolean |
getOverwrite()
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 |
getSaveAsPath(DbControl dc)
Get the configured path where the exported data should be saved. |
protected File |
getSaveTo()
Get the file object that the current export is writing to. |
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. |
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 the SAVE_AS parameter for the path to save
the exported data. |
Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin |
---|
checkInterrupted, cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, getPermissions, init, 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, getAbout, getPermissions, init, requiresConfiguration, supportsConfigurations |
Field Detail |
---|
protected static final PathParameterType optionalSaveAsType
protected static final PathParameterType requiredSaveAsType
protected static final BooleanParameterType overwriteType
private File saveTo
protected static final String SAVE_AS
getSaveAsParameter(String, String, String, boolean)
parameter.
protected static final String OVERWRITE
getOverwriteParameter(String, String)
parameter.
Constructor Detail |
---|
protected AbstractExporterPlugin()
AbstractExporterPlugin
.
Method Detail |
---|
public Plugin.MainType getMainType()
Plugin
getMainType
in interface Plugin
public void run(Request request, Response response, ProgressReporter progress)
SAVE_AS
parameter for the path to save
the exported data. If the file doesn't exists it is created.
If the file exists the OVERWRITE
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)
run
in interface Plugin
request
- Request object with the command and parametersresponse
- Response object in for the plugin to response
throughprogress
- A ProgressReporter
where the plugin can report
its progess, can be nullpublic final void doExport(ExportOutputStream out, ProgressReporter progress) throws IOException
begin(DbControl)
performExport(ExportOutputStream, ProgressReporter)
end(boolean)
(after the DbControl has been committed)
doExport
in interface ImmediateDownloadExporter
out
- The output stream that the exported data should be written toprogress
- An optional progress reporter, may be null
IOException
- If there is an error writing to the export streamprotected void begin(DbControl dc)
dc
- The DbControl that is used to write to the database.
A subclass may use this read from the database as wellend(boolean)
protected File getSaveTo()
protected abstract void performExport(ExportOutputStream out, ProgressReporter progress) throws IOException
ImmediateDownloadExporter.doExport(ExportOutputStream, ProgressReporter)
method.
out
- Output stream to write the exported data toprogress
- An optional progress reporter
IOException
protected void end(boolean success)
begin(DbControl)
method here.
success
- TRUE if the file was parsed successfully, FALSE otherwisebegin(DbControl)
protected String getSuccessMessage()
178 reporters exported successfully
.
The default implementation always return null.
protected PluginParameter<String> getSaveAsParameter(String label, String description, String defaultValue, boolean required)
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 optionalprotected Path getSaveAsPath(DbControl dc)
dc
- A DbControl which is needed to find the currently logged in user
if the path starts with '~/' = Home directory of logged in user
protected PluginParameter<Boolean> getOverwriteParameter(String label, String description)
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.)public boolean getOverwrite()
getOverwriteParameter(String, String)
protected boolean pathCanBeUsed(String strPath, boolean overwrite)
strPath
- The file path to be checked.overwrite
- TRUE If it is allowed to overwrite the file, FALSE otherwise.
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |