Package com.storedobject.office
Class ODT<T>
java.lang.Object
com.storedobject.office.ODT<T>
- Type Parameters:
T- The type of the iterator element that is being processed. If no iterator is set, this is not applicable.
- All Implemented Interfaces:
Executable,ContentProducer,ContentType,RequiresTransactionManager,Closeable,AutoCloseable,Runnable
- Direct Known Subclasses:
AbstractODTReport
The ODT class is a representation of an Open Document Template (ODT) document processor.
It provides various constructors and methods to handle template-based document generation
using ODT format. The class extends core functionality from content-producing and closeable
interfaces to streamline the process of managing document content.
If an iterator is set, the output will be generated for each element of the iterator.
- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a document.static classRepresents an abstract base class for document elements.static final classRepresents an image element within a document.static final classRepresents a table row of a table that can be copied directly or added with array variables to the output.static final classRepresents a section within a document structure in the context of document processing.static final classRepresents a hierarchical structure of sections, where each section has a name, a reference to its parent section, and a list of child sections.static final classRepresents a table in the context of open document template (ODT) processing.static final classRepresents a cell within a table.static final classRepresents a single row within a table structure in the context of document processing.static classRepresents a text element that can contain one or more sections and tables. -
Constructor Summary
ConstructorsConstructorDescriptionODT()Default constructor for the ODT class.ODT(Device device, StreamData streamData, Object filler) Constructor for the ODT class.Constructor for the ODT class.Constructor for creating an ODT instance with a specific template and filler object.ODT(StreamData streamData) Constructor for creating an ODT object with the given content and optional filler.ODT(StreamData streamData, Object filler) Constructor for the ODT class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final InputStreamRetrieves the content of this ODT instance as an InputStream.final StringRetrieves the content type of the current instance, determining if it is a PDF or ODT based on the outmode set.final DeviceRetrieves the current device associated with the ODT instance.Retrieves the exception stored in this instance.final StringRetrieves the file extension based on the current output mode.Retrieves the name of the file associated with the current ODT instance.Get the list of section names in the document.final TransactionManagerRetrieves theTransactionManagerinstance associated with the current context.final booleanDetermines if the current output mode is set to raw output (that is pure ODT format, not PDF/HTML).voidLogs the provided object.voidproduce()Produces the necessary output based on the current state and properties of the object.voidready()Waits for the associated countdown latch to reach the zero state, blocking the current thread until the latch is counted down or the thread is interrupted.voidreportingIteratorValue(T value) Deprecated.voidsetExcludeImages(boolean excludeImages) Sets the flag to exclude images from processing.voidSets the filler object to the specified value.final voidsetImageCustomizer(BiConsumer<Filler<?>, ODT.Image> imageCustomizer) Sets a customizer for images that enables tailored modifications or adjustments during their generation.final voidsetIterator(Iterator<T> iterator) Sets the iterator to the specified value.final voidConfigures the output to be in HTML format.final voidConfigures the output format of the system as PDF.final voidsetRawOutput(boolean rawOutput) Sets the raw output mode for the ODT instance.final voidsetReportingObject(T object) Sets the reporting object for this instance.final voidsetSectionCustomizer(BiConsumer<Filler<?>, ODT.Section> sectionCustomizer) Sets a customizer for sections that enables tailored modifications or adjustments during their generation.final voidsetTableCustomizer(BiConsumer<Filler<?>, ODT.Table> tableCustomizer) Sets a customizer for tables that enables tailored modifications or adjustments during their generation.voidsetTemplate(Id templateId) Sets the template for the ODT object based on the provided template identifier.voidsetTemplate(StreamData template) Sets the template for the ODT object using the provided StreamData.final voidsetTransactionManager(TransactionManager transactionManager) Sets the transaction manager to be used by this instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.storedobject.core.ContentProducer
abort, execute, extractContent, getEntity, getError, getStreamData, getStreamDataProvider, getSystemEntity, saveTo, saveTo, saveTo, saveToMethods inherited from interface com.storedobject.core.ContentType
getLink, getMimeType, isAudio, isHTML, isImage, isLink, isMedia, isPDF, isText, isVideoMethods inherited from interface com.storedobject.common.Executable
act, run
-
Constructor Details
-
ODT
public ODT()Default constructor for the ODT class. This constructor initializes an empty ODT instance with no specific stream data or filler. It delegates to the constructor that accepts a `StreamData` and a filler by passing `null` for both parameters. -
ODT
Constructor for the ODT class. Initializes the ODT object with a template identifier and an optional filler object.- Parameters:
templateId- The identifier of the stream data containing an ODT file template.
-
ODT
-
ODT
Constructor for creating an ODT object with the given content and optional filler.- Parameters:
streamData- Stream data containing the content to initialize the ODT object.
-
ODT
Constructor for the ODT class. Initializes the template using the provided StreamData and configures the internal state.- Parameters:
streamData- Stream data containing the template for the ODT file.filler- Object used to provide additional data or configuration for the ODT file creation.
-
ODT
Constructor for the ODT class. Initializes the template using the provided StreamData and configures the internal state.- Parameters:
streamData- Stream data containing the template for the ODT file.filler- Object used to provide additional data or configuration for the ODT file creation.
-
-
Method Details
-
getDevice
Retrieves the current device associated with the ODT instance.- Returns:
- The
Deviceobject representing the current device, ornullif no device is set.
-
setTemplate
Sets the template for the ODT object using the provided StreamData.- Parameters:
template- The StreamData object representing the template to be used.
-
setTemplate
Sets the template for the ODT object based on the provided template identifier. If the provided identifier is null, the template is cleared. Otherwise, the template is retrieved from the stored object system using the given identifier.- Parameters:
templateId- The identifier of the template (StreamData) to be set. It represents the unique ID of the template in the stored object system.
-
setRawOutput
public final void setRawOutput(boolean rawOutput) Sets the raw output mode for the ODT instance. By default, the output format is PDF. In raw mode, the output format is ODT itself.- Parameters:
rawOutput- A boolean flag indicating whether raw output mode should be enabled (true) or disabled (false).
-
isRawOutput
public final boolean isRawOutput()Determines if the current output mode is set to raw output (that is pure ODT format, not PDF/HTML).- Returns:
trueif the output mode is raw, otherwisefalse.
-
setOutputAsHTML
public final void setOutputAsHTML()Configures the output to be in HTML format. This method sets the internal flag to mark that the output should be generated or treated as HTML. -
setOutputAsPDF
public final void setOutputAsPDF()Configures the output format of the system as PDF. This method ensures that the output is not generated as HTML and disables raw output formatting. -
setExcludeImages
public void setExcludeImages(boolean excludeImages) Sets the flag to exclude images from processing.- Parameters:
excludeImages- a boolean value wheretrueindicates that images should be excluded, andfalseindicates that images should be included.
-
getContent
Retrieves the content of this ODT instance as an InputStream. This method returns the content that was generated or loaded for this ODT object. If no content has been generated and an error occurred, an IOException is thrown.- Specified by:
getContentin interfaceContentProducer- Returns:
- An InputStream containing the content of this ODT instance.
- Throws:
IOException- If no content is available due to an error.
-
getContentType
Retrieves the content type of the current instance, determining if it is a PDF or ODT based on the outmode set.- Specified by:
getContentTypein interfaceContentType- Returns:
- A string representing the MIME type of the content. This will be "application/pdf" if PDF properties are set and "application/vnd.oasis.opendocument.text" otherwise.
-
getFileExtension
Retrieves the file extension based on the current output mode.- Specified by:
getFileExtensionin interfaceContentProducer- Returns:
- The file extension as a string, either "odt" or "pdf".
-
getFileName
Retrieves the name of the file associated with the current ODT instance.- Specified by:
getFileNamein interfaceContentProducer- Returns:
- The name of the file as a String, or null if the file name is not available.
-
setTransactionManager
Sets the transaction manager to be used by this instance.- Specified by:
setTransactionManagerin interfaceRequiresTransactionManager- Parameters:
transactionManager- TheTransactionManagerinstance to be set. It manages transactions and ensures proper transaction handling within the context of this class.
-
getTransactionManager
Retrieves theTransactionManagerinstance associated with the current context. If theTransactionManageris not already initialized, it attempts to initialize it by getting the device, accessing its server, and retrieving itsTransactionManager.- Specified by:
getTransactionManagerin interfaceContentProducer- Specified by:
getTransactionManagerin interfaceRequiresTransactionManager- Returns:
- The
TransactionManagerassociated with the current context, ornullif it cannot be initialized.
-
getException
Retrieves the exception stored in this instance.- Returns:
- the Throwable object representing the stored exception
-
setIterator
Sets the iterator to the specified value. If an iterator is set, the output will be generated for each element in the iterator. When each element is processed, the methodreportingIteratorValue(Object)will be called.- Parameters:
iterator- the iterator to be assigned. Must implementIterator<T>.
-
setReportingObject
Sets the reporting object for this instance.- Parameters:
object- The reporting object to set. It can be of any typeT.
-
setSectionCustomizer
Sets a customizer for sections that enables tailored modifications or adjustments during their generation. The customizer is represented as aBiConsumerthat accepts aFillerinstance and anODT.Section.- Parameters:
sectionCustomizer- ABiConsumerthat defines the customization logic for sections. The first parameter is theFillerinstance associated with the operation, and the second parameter is theODT.Sectionto be customized.
-
setTableCustomizer
Sets a customizer for tables that enables tailored modifications or adjustments during their generation. The customizer is represented as aBiConsumerthat accepts aFillerinstance and anODT.Table.- Parameters:
tableCustomizer- ABiConsumerthat defines the customization logic for tables. The first parameter is theFillerinstance associated with the operation, and the second parameter is theODT.Tableto be customized.
-
setImageCustomizer
Sets a customizer for images that enables tailored modifications or adjustments during their generation. The customizer is represented as aBiConsumerthat accepts aFillerinstance and anODT.Image.- Parameters:
imageCustomizer- ABiConsumerthat defines the customization logic for images. The first parameter is theFillerinstance associated with the operation, and the second parameter is theODT.Imageto be customized.
-
reportingIteratorValue
Deprecated.UseFiller.getReportingObject()to retrieve the current iteration value.Reports the current value of the iterator during processing. This will be called for each element of the iterator just before processing the element.- Parameters:
value- The current value retrieved from the iterator to be processed.
-
produce
public void produce()Produces the necessary output based on the current state and properties of the object. This method ensures thread-safe execution, manages state, and triggers the appropriate processing depending on the presence of specific properties.Key behavior: - Initializes a filler object if not already initialized. - Early exit occurs if an error condition is detected. - Ensures thread-safe execution by acquiring a lock and managing the execution state. - Creates an InputOutputStream to handle data processing. - Sets a data listener to notify when the process is ready. - Processes raw or PDF data in a separate virtual thread based on the presence of specific properties.
Thread management and state synchronization are essential to this method's proper execution.- Specified by:
producein interfaceContentProducer
-
ready
public void ready()Waits for the associated countdown latch to reach the zero state, blocking the current thread until the latch is counted down or the thread is interrupted. This method overrides the default implementation of the `ready` method. If the thread is interrupted while waiting, the interruption is silently ignored and execution continues.- Specified by:
readyin interfaceContentProducer
-
log
Logs the provided object. If a device is available, the logging will be delegated to the device. Otherwise, if the object is an instance of Throwable, it will be logged via the ApplicationServer.- Parameters:
anything- The object to be logged. It can be any object, including instances of Throwable.
-
setFiller
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getSectionNames
Get the list of section names in the document.- Returns:
- List of section names.
-
Filler.getReportingObject()to retrieve the current iteration value.