Package com.inet.pdfc.presenter
Class BasePresenter
java.lang.Object
com.inet.pdfc.presenter.BasePresenter
- All Implemented Interfaces:
NamedExtension
- Direct Known Subclasses:
ConsolePresenter
,DifferencesImagePresenter
,ExportPresenter
,JsonPresenter
,ReportPresenter
A Presenter is responsible to 'present' the result of the comparison in some way.
Note: The presenter is only meant to present a result. If you want to get progress notifications for instance, please register a
Note: The presenter is stateful, not stateless. This means it cannot be used concurrently by multiple comparisons, but it can be used by subsequent comparisons.
This class the base class for a result presenter. It automatically registers to a model and should present the result
presented by the ResultModel
in some way.
There are multiple callback-methods which subclasses can override to react on the event or to present the result.
The presenter must react on errors which occur while reading or comparing the files, see
onError(ExceptionData, boolean, ERROR_SOURCE)
. Exceptions are not thrown by the PDFComparer
.
Note: The presenter is only meant to present a result. If you want to get progress notifications for instance, please register a
DataGeneratorListener
to the actual AbstractComparator
Note: The presenter is stateful, not stateless. This means it cannot be used concurrently by multiple comparisons, but it can be used by subsequent comparisons.
- Since:
- i-net PDFC 3.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Names the thread / task where the error occurred -
Field Summary
Modifier and TypeFieldDescriptionstatic final com.inet.logging.Logger
Default Logger for presenterstatic final int
The maximum length the filename of an exported file is allowed to have without extension.
If the names of the compared files plus the additional characters are too long, then the exported name is truncated to this length. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Returns whether the presenter is able to handle errors in a way to notify the user.Deprecated.createExportFilename
(String presenterType, String n1, String n2) Construct the default Export file name used for exports.
This is called bygetDefaultExportName(String)
inBasePresenter
with dummy parameters to determine how much characters will be added by this method.void
Detaches this presenter from a model.void
executeImmediately
(ResultModel model) Forces an execution of the presenter no matter the current model state.
Use this method to run a presenter for an already finished model.protected String
getDefaultExportName
(String presenterType) Returns the default export file name of the current comparison.
This method will truncate parts of the second compared file which are equal to the first one, so only the different part of the name remains.Return the last exception for this presenter.protected ResultModel
getModel()
Returns the model this presenter is registered toprotected BasePresenter
Returns the parent presenter.Return all exceptions for a this presenter.protected void
onClear()
Called upon comparison startup.protected abstract void
Called to indicate that a comparison has finished.protected void
Called whenever the referred model receives a data chunk.protected void
onError
(ExceptionData error, boolean interrupted, BasePresenter.ERROR_SOURCE source) Called in case of an error that occurred either in one of the parser threads or in the compare thread.
NOTE: This method is only called for exceptions which are notified to theResultModel
.protected void
Called whenever the filter conditions of the referenced model have changed.protected void
onFinish()
OPTIONAL: Called in case of batch comparison at the end of all comparisons of the batch run.protected void
onInit()
Called at the time the document informations have been set.protected void
onProgressUpdate
(float progress) Called whenever the comparison sends a progress state.void
setModel
(ResultModel newModel) Registers this presenter to a model.protected void
setParent
(BasePresenter parent) Sets the parent presenter for spawned presenters.spawn
(boolean spawnWithParent) Creates another presenter of the the same type as the current one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.inet.plugin.NamedExtension
getExtensionName
-
Field Details
-
MAX_FILENAME_LENGTH
public static final int MAX_FILENAME_LENGTHThe maximum length the filename of an exported file is allowed to have without extension.
If the names of the compared files plus the additional characters are too long, then the exported name is truncated to this length.- Since:
- i-net PDFC 3.0
- See Also:
-
LOGGER
public static final com.inet.logging.Logger LOGGERDefault Logger for presenter
-
-
Constructor Details
-
BasePresenter
public BasePresenter()
-
-
Method Details
-
configure
Deprecated.As of i-net PDFC 5.0, use insteadPDFComparer.setSettings(Settings)
orResultModel.getSettings()
Configures the presenter according to a configuration. The presenter will read the propertyPDFCProperty.MAX_ERRORS_PER_FILE
from the configuration.- Parameters:
configuration
- the configuration to read from, must not benull
- Returns:
- this instance for concatenation
- Since:
- i-net PDFC 3.2
-
onClear
Called upon comparison startup. This does not imply which data is available to the model, but most likely the model has been cleared at this point.- Throws:
Exception
- thrown in case the processing of the clear step fails- Since:
- i-net PDFC 3.0
-
onInit
Called at the time the document informations have been set.- Throws:
Exception
- thrown in case the processing of the init step fails- Since:
- i-net PDFC 3.0
-
onDataUpdate
Called whenever the referred model receives a data chunk. This does not imply that any differences are available yet as it is called as well for no-difference areas.- Throws:
Exception
- thrown in case the processing of the update step fails- Since:
- i-net PDFC 3.0
-
onComparisonDone
Called to indicate that a comparison has finished. This does not imply that any page data or differences are available.- Throws:
Exception
- thrown in case the processing of the finish step fails- Since:
- i-net PDFC 3.0
-
onFinish
protected void onFinish()OPTIONAL: Called in case of batch comparison at the end of all comparisons of the batch run. This method cannot be triggered by an event of any referenced result model. It's sole purpose is to serve as a callback for thePDFComparer.batchCompare(java.io.File, java.io.File)
method.
NOTE: This method only called once per batch compare and only for the root presenter, never for spawned ones.- Since:
- i-net PDFC 3.0
-
onError
Called in case of an error that occurred either in one of the parser threads or in the compare thread.
NOTE: This method is only called for exceptions which are notified to theResultModel
.- Parameters:
error
- the exceptioninterrupted
- indicates whether the comparison was interrupted due to this exception. Iftrue
there will be no further calls (e.g. onComparisonDone)source
- the source module of the exception.- Since:
- i-net PDFC 3.0
-
onFilterChange
Called whenever the filter conditions of the referenced model have changed. This method is not called automatically during a comparison but rather a reaction to a configuration change that can be applied to the model.- Throws:
Exception
- thrown in case the processing of the filter update fails- Since:
- i-net PDFC 3.0
-
onProgressUpdate
protected void onProgressUpdate(float progress) Called whenever the comparison sends a progress state. In some rare cases the same progress value may be sent multiple times.- Parameters:
progress
- the progress in percent, a value between 0 and 100, bounds included.- Since:
- i-net PDFC 4.0
-
executeImmediately
Forces an execution of the presenter no matter the current model state.
Use this method to run a presenter for an already finished model.- Parameters:
model
- the model to be presented, ifnull
the currently set model will be presented. This model will not be set persistently to the presenter, it will be detached at the end of this method- Throws:
IllegalStateException
- in case the no model has been set yetException
- thrown in case the processing of fails; this exception is published to the caller to allow a feedback to the user- Since:
- i-net PDFC 3.0
-
setModel
Registers this presenter to a model. If it already was registered to a model, the old model will be detached first.- Parameters:
newModel
- the new- Since:
- i-net PDFC 3.0
-
getModel
Returns the model this presenter is registered to- Returns:
- the model, is null until a comparison was started where this Presenter was added to.
- Since:
- i-net PDFC 3.0
-
detachFromModel
public void detachFromModel()Detaches this presenter from a model. Call this method if the presenter should no longer generate output for the referenced model.- Since:
- i-net PDFC 3.0
-
getDefaultExportName
Returns the default export file name of the current comparison.
This method will truncate parts of the second compared file which are equal to the first one, so only the different part of the name remains. Will also limit the finally returned name toMAX_FILENAME_LENGTH
characters by truncating both compared file's names again.
If you want to retain this behavior but want a different Exportname, overridecreateExportFilename(String, String, String)
which is called by the implementation of this method inBasePresenter
.- Parameters:
presenterType
- the identifier of the calling presenter, will be part of the export name, should not benull
- Returns:
- the export name WITHOUT SUFFIX, or
null
if the comparison was not started yet - Since:
- i-net PDFC 3.0
- See Also:
-
createExportFilename
Construct the default Export file name used for exports.
This is called bygetDefaultExportName(String)
inBasePresenter
with dummy parameters to determine how much characters will be added by this method. That is required to truncate the compared files names in order to return a filename which does not exceed a limit ofMAX_FILENAME_LENGTH
characters.
You can safely override this, but make sure that the returned String's length minus n1.length minus n2.length is constant for any n1 or n2 which are not empty strings.- Parameters:
presenterType
- the Sting passed togetDefaultExportName(String)
which describes the presentern1
- the possibly truncated name of the first file, or an empty string for the check for how many characters this methods addsn2
- the possibly truncated name of the second file, or an empty string for the check for how many characters this methods adds- Returns:
- the resulting Export file name, without an extension.
- Since:
- i-net PDFC 3.0
- See Also:
-
getLastPresenterException
Return the last exception for this presenter. The presenter runs independent and has no effect for the comparison or other presenters.- Returns:
- the last exception for this presenter or null if no exception available
- Since:
- 5.0
-
getPresenterExceptions
Return all exceptions for a this presenter. The presenter runs independent and has no effect on the comparison or other presenters.- Returns:
- all exceptions for a this presenter, empty list for no thrown exception
- Since:
- 5.0
-
spawn
Creates another presenter of the the same type as the current one. The spawned presenter may either have the same settings as the current one or it may be a child of the current one.- Parameters:
spawnWithParent
- if true, the presenter is allowed to keep a reference to it's parent to create a summary on onFinish()- Returns:
- a new presenter for the same batch comparison run as the current one
- Throws:
IllegalStateException
- in case the spawn was not successful- Since:
- i-net PDFC 4.0
-
setParent
Sets the parent presenter for spawned presenters. Can be used as an central instance to present a summary in batch comparisons- Parameters:
parent
- the parent presenter.- Since:
- 4.0
-
getParent
Returns the parent presenter. Can be used as an central instance to present a summary in batch comparisons- Returns:
- the parent or
null
- Since:
- 4.0
-
canInformUserOnErrors
protected boolean canInformUserOnErrors()Returns whether the presenter is able to handle errors in a way to notify the user. E.g. write the error to the log file/console or pop up an error dialog.- Returns:
true
ofonError(ExceptionData, boolean, ERROR_SOURCE)
will directly inform the user.- Since:
- 4.0
-
PDFComparer.setSettings(Settings)
orResultModel.getSettings()