fr.opensagres.xdocreport.document
Class AbstractXDocReport

java.lang.Object
  extended by fr.opensagres.xdocreport.document.AbstractXDocReport
All Implemented Interfaces:
IXDocReport, Serializable
Direct Known Subclasses:
DocxReport, ODPReport, ODSReport, ODTReport, PPTXReport

public abstract class AbstractXDocReport
extends Object
implements IXDocReport

Abstract class for IXDocReport to implement to manage docx, odt...

See Also:
Serialized Form

Constructor Summary
protected AbstractXDocReport()
           
 
Method Summary
 void addPreprocessor(String entryName, IXDocPreprocessor preprocessor)
          Register a processor for the entry name.
 void clearData(String key)
          Clear data.
 void convert(IContext context, Options options, OutputStream out)
          Generate report and Convert it to another format (PDF, XHTML, etc).
 void convert(Map<String,Object> contextMap, Options options, OutputStream out)
          Generate report and Convert it to another format (PDF, XHTML, etc).
 IContext createContext()
          Create an empty context to register Java model.
 IContext createContext(Map<String,Object> contextMap)
          Create a new instance of IContext to put the Java model.
 FieldsMetadata createFieldsMetadata()
          Create fields metadata.
protected abstract  IImageRegistry createImageRegistry(IEntryReaderProvider readerProvider, IEntryWriterProvider writerProvider, IEntryOutputStreamProvider outputStreamProvider)
          Create an image registry.
protected  void doPostprocessIfNeeded(XDocArchive outputArchive)
           
 void dump(IContext context, DumperOptions options, OutputStream out)
          Dump
 void dump(IContext context, InputStream documentIn, DumperOptions options, OutputStream out)
          Dump
 void extractFields(FieldsExtractor extractor)
          Extract declared fields which use syntax of the template egine of the report.
 void extractFields(FieldsExtractor extractor, ITemplateEngine templateEngine)
          Extract declared fields which use syntax of the given template egine of the report.
 IConverter getConverter(Options options)
          Returns converter for the report and options.
<T> T
getData(String key)
          Returns custom data.
protected abstract  String[] getDefaultXMLEntries()
          Returns default entries which define XML document to merge with Java model with template engine for odt, docx...
 IDumper getDumper(DumperOptions options)
          Returns the dumper for the given options.
 FieldsMetadata getFieldsMetadata()
          Returns fields metadata used to manage lazy loop for table row.
 String getId()
          Returns the id of the IXDocReport.
 long getLastModified()
          Returns the last modified time when the report is loaded.
 XDocArchive getOriginalDocumentArchive()
          Returns the original zipped XML document (odt, docx...) and null if : no load was done.
 XDocArchive getPreprocessedDocumentArchive()
          Returns the preprocessed zipped XML document (odt, docx...) and null if no load was done.
 ITemplateEngine getTemplateEngine()
          Returns template engine (velocity, freemarker..) to use to merge Java model with the XML files of the from entries of the zipped XML Document (odt, docx...) defined by getXMLEntries().
 String[] getXMLEntries()
          Returns XML entries which define XML document to merge with Java model with template engine.
 boolean isPreprocessed()
          Returns true if report was processed and false otherwise.
 void load(InputStream sourceStream)
          Load XML document (odt, docx...) from input stream.
protected  void onAfterPreprocessing(Map<String,Object> sharedContext, XDocArchive preprocessedArchive)
          On after preprocessing.
protected  void onAfterProcessTemplateEngine(IContext context, XDocArchive outputArchive)
          On after process template engine.
protected  void onBeforePreprocessing(Map<String,Object> sharedContext, XDocArchive preprocessedArchive)
          On before preprocessing.
protected  void onBeforeProcessTemplateEngine(IContext context, XDocArchive outputArchive)
          On before process template engine.
 void preprocess()
          Force the preprocessing step.
 void process(IContext context, OutputStream out)
          Merge the docx, odt document with Java model from the context and register the result to the output stream.
 void process(IContext context, String entryName, OutputStream out)
          Generate report by merging Java model frm the context with XML Document (odt, docx...) preprocessed and store the result into output stream.
 void process(Map<String,Object> contextMap, OutputStream out)
          Merge the docx, odt document with Java model from the context Map and register the result to the output stream.
 void process(Map<String,Object> contextMap, String entryName, OutputStream out)
          Merge the docx, odt document with Java model from the context Map and register the entryName transformed to the output stream.
protected abstract  void registerPreprocessors()
          Register preprocessors.
 void removeAllPreprocessors()
          Clear processor.
 void removePreprocessor(String entryName)
          Remove processor for the entry name.
 void save(ProcessState processState, OutputStream out)
          Save original|preprocessed XML document archive in the given output stream.
 void saveEntry(String entryName, ProcessState processState, OutputStream out)
          Save original|preprocessed entryName from XML document archive in the given output stream.
 void setCacheOriginalDocument(boolean cacheOriginalDocument)
          Set cache or not for original document archive.
 void setData(String key, Object value)
          Returns XML entries which define XML document to merge with Java model with template engine.
 void setDocumentArchive(XDocArchive documentArchive)
          Returns the zipped XML document (odt, docx...).
 void setFieldsMetadata(FieldsMetadata fieldsMetadata)
          Set fields metadata used to manage lazy loop for table row.
 void setId(String id)
          Set the id of the IXDocReport.
 void setTemplateEngine(ITemplateEngine templateEngine)
          Register template engine (velocity, freemarker..) to use to merge Java model with the XML files of the from entries of the zipped XML Document (odt, docx...) defined by getXMLEntries().
 void setXMLEntries(String[] xmlEntries)
          Set XML entries which define XML document to merge with Java model with template engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.opensagres.xdocreport.document.IXDocReport
getKind, getMimeMapping
 

Constructor Detail

AbstractXDocReport

protected AbstractXDocReport()
Method Detail

getId

public String getId()
Description copied from interface: IXDocReport
Returns the id of the IXDocReport. This id is used to cache an instance of IXDocReport with {@link XDocReportRegistry#loadReport(InputStream) and get instance from cache with

Specified by:
getId in interface IXDocReport
Returns:
the id of the IXDocReport

setId

public void setId(String id)
Description copied from interface: IXDocReport
Set the id of the IXDocReport. This id is used to cache an instance of IXDocReport with {@link XDocReportRegistry#loadReport(InputStream) and get instance from cache with

Specified by:
setId in interface IXDocReport
Parameters:
id - of the IXDocReport

load

public void load(InputStream sourceStream)
          throws IOException,
                 XDocReportException
Description copied from interface: IXDocReport
Load XML document (odt, docx...) from input stream.

Specified by:
load in interface IXDocReport
Parameters:
sourceStream - stream of the XML Document zip (odt, docx...).
Throws:
IOException - when XML Document zip (odt, docx...) cannot be read.
XDocReportException - when preprocessing with IXDocPreprocessor cannot be done.

setDocumentArchive

public void setDocumentArchive(XDocArchive documentArchive)
                        throws IOException,
                               XDocReportException
Description copied from interface: IXDocReport
Returns the zipped XML document (odt, docx...).

Specified by:
setDocumentArchive in interface IXDocReport
Parameters:
documentArchive - XDocArchive.
Throws:
XDocReportException - when preprocessing with IXDocPreprocessor cannot be done.
IOException

getOriginalDocumentArchive

public XDocArchive getOriginalDocumentArchive()
Description copied from interface: IXDocReport
Returns the original zipped XML document (odt, docx...) and null if :

Specified by:
getOriginalDocumentArchive in interface IXDocReport
Returns:

getPreprocessedDocumentArchive

public XDocArchive getPreprocessedDocumentArchive()
Description copied from interface: IXDocReport
Returns the preprocessed zipped XML document (odt, docx...) and null if no load was done.

Specified by:
getPreprocessedDocumentArchive in interface IXDocReport
Returns:

getTemplateEngine

public ITemplateEngine getTemplateEngine()
Returns template engine (velocity, freemarker..) to use to merge Java model with the XML files of the from entries of the zipped XML Document (odt, docx...) defined by getXMLEntries().

Specified by:
getTemplateEngine in interface IXDocReport
Returns:

setTemplateEngine

public void setTemplateEngine(ITemplateEngine templateEngine)
Register template engine (velocity, freemarker..) to use to merge Java model with the XML files of the from entries of the zipped XML Document (odt, docx...) defined by getXMLEntries().

Specified by:
setTemplateEngine in interface IXDocReport

addPreprocessor

public void addPreprocessor(String entryName,
                            IXDocPreprocessor preprocessor)
Register a processor for the entry name.

Specified by:
addPreprocessor in interface IXDocReport
Parameters:
entryName -
preprocessor -

removePreprocessor

public void removePreprocessor(String entryName)
Remove processor for the entry name.

Specified by:
removePreprocessor in interface IXDocReport
Parameters:
entryName -

removeAllPreprocessors

public void removeAllPreprocessors()
Clear processor.

Specified by:
removeAllPreprocessors in interface IXDocReport

setFieldsMetadata

public void setFieldsMetadata(FieldsMetadata fieldsMetadata)
Set fields metadata used to manage lazy loop for table row.

Specified by:
setFieldsMetadata in interface IXDocReport

getFieldsMetadata

public FieldsMetadata getFieldsMetadata()
Returns fields metadata used to manage lazy loop for table row.

Specified by:
getFieldsMetadata in interface IXDocReport
Returns:

createFieldsMetadata

public FieldsMetadata createFieldsMetadata()
Create fields metadata.

Specified by:
createFieldsMetadata in interface IXDocReport
Returns:

preprocess

public void preprocess()
                throws XDocReportException,
                       IOException
Description copied from interface: IXDocReport
Force the preprocessing step.

Specified by:
preprocess in interface IXDocReport
Throws:
XDocReportException
IOException

onBeforePreprocessing

protected void onBeforePreprocessing(Map<String,Object> sharedContext,
                                     XDocArchive preprocessedArchive)
                              throws XDocReportException
On before preprocessing.

Parameters:
sharedContext -
preprocessedArchive -
Throws:
XDocReportException

onAfterPreprocessing

protected void onAfterPreprocessing(Map<String,Object> sharedContext,
                                    XDocArchive preprocessedArchive)
                             throws XDocReportException
On after preprocessing.

Parameters:
sharedContext -
preprocessedArchive -
Throws:
XDocReportException

getXMLEntries

public String[] getXMLEntries()
Returns XML entries which define XML document to merge with Java model with template engine.

Returns:

setXMLEntries

public void setXMLEntries(String[] xmlEntries)
Set XML entries which define XML document to merge with Java model with template engine.

Parameters:
xmlEntries -

createContext

public IContext createContext()
                       throws XDocReportException
Create an empty context to register Java model.

Specified by:
createContext in interface IXDocReport
Returns:
Throws:
XDocReportException

createContext

public IContext createContext(Map<String,Object> contextMap)
                       throws XDocReportException
Description copied from interface: IXDocReport
Create a new instance of IContext to put the Java model.

Specified by:
createContext in interface IXDocReport
Returns:
Throws:
XDocReportException

process

public void process(Map<String,Object> contextMap,
                    OutputStream out)
             throws XDocReportException,
                    IOException
Description copied from interface: IXDocReport
Merge the docx, odt document with Java model from the context Map and register the result to the output stream.

Specified by:
process in interface IXDocReport
out - output stream where merge must be saved.
Throws:
XDocReportException
IOException

process

public void process(Map<String,Object> contextMap,
                    String entryName,
                    OutputStream out)
             throws XDocReportException,
                    IOException
Description copied from interface: IXDocReport
Merge the docx, odt document with Java model from the context Map and register the entryName transformed to the output stream.

Specified by:
process in interface IXDocReport
entryName - entry name
Throws:
XDocReportException
IOException

process

public void process(IContext context,
                    OutputStream out)
             throws XDocReportException,
                    IOException
Description copied from interface: IXDocReport
Merge the docx, odt document with Java model from the context and register the result to the output stream.

Specified by:
process in interface IXDocReport
Parameters:
context - of the Java model.
out - output stream where merge must be saved.
Throws:
XDocReportException
IOException

process

public void process(IContext context,
                    String entryName,
                    OutputStream out)
             throws XDocReportException,
                    IOException
Generate report by merging Java model frm the context with XML Document (odt, docx...) preprocessed and store the result into output stream.

Specified by:
process in interface IXDocReport
Parameters:
context - of the Java model.
entryName - entry name
Throws:
XDocReportException
IOException

doPostprocessIfNeeded

protected void doPostprocessIfNeeded(XDocArchive outputArchive)

save

public void save(ProcessState processState,
                 OutputStream out)
          throws IOException,
                 XDocReportException
Description copied from interface: IXDocReport
Save original|preprocessed XML document archive in the given output stream.

Specified by:
save in interface IXDocReport
Throws:
IOException
XDocReportException

saveEntry

public void saveEntry(String entryName,
                      ProcessState processState,
                      OutputStream out)
               throws IOException,
                      XDocReportException
Description copied from interface: IXDocReport
Save original|preprocessed entryName from XML document archive in the given output stream.

Specified by:
saveEntry in interface IXDocReport
Throws:
IOException
XDocReportException

extractFields

public void extractFields(FieldsExtractor extractor)
                   throws XDocReportException,
                          IOException
Description copied from interface: IXDocReport
Extract declared fields which use syntax of the template egine of the report.

Specified by:
extractFields in interface IXDocReport
Parameters:
extractor - the fields extractor.
Throws:
XDocReportException
IOException

extractFields

public void extractFields(FieldsExtractor extractor,
                          ITemplateEngine templateEngine)
                   throws XDocReportException,
                          IOException
Description copied from interface: IXDocReport
Extract declared fields which use syntax of the given template egine of the report.

Specified by:
extractFields in interface IXDocReport
Parameters:
extractor - the fields extractor.
templateEngine - the template engine.
Throws:
XDocReportException
IOException

getConverter

public IConverter getConverter(Options options)
                        throws XDocConverterException
Description copied from interface: IXDocReport
Returns converter for the report and options.

Specified by:
getConverter in interface IXDocReport
Returns:
Throws:
XDocConverterException

convert

public void convert(Map<String,Object> contextMap,
                    Options options,
                    OutputStream out)
             throws XDocReportException,
                    XDocConverterException,
                    IOException
Description copied from interface: IXDocReport
Generate report and Convert it to another format (PDF, XHTML, etc).

Specified by:
convert in interface IXDocReport
Throws:
XDocReportException
XDocConverterException
IOException

convert

public void convert(IContext context,
                    Options options,
                    OutputStream out)
             throws XDocReportException,
                    XDocConverterException,
                    IOException
Description copied from interface: IXDocReport
Generate report and Convert it to another format (PDF, XHTML, etc).

Specified by:
convert in interface IXDocReport
Throws:
XDocReportException
XDocConverterException
IOException

onBeforeProcessTemplateEngine

protected void onBeforeProcessTemplateEngine(IContext context,
                                             XDocArchive outputArchive)
                                      throws XDocReportException
On before process template engine.

Parameters:
context -
outputArchive -
Throws:
XDocReportException

onAfterProcessTemplateEngine

protected void onAfterProcessTemplateEngine(IContext context,
                                            XDocArchive outputArchive)
                                     throws XDocReportException
On after process template engine.

Parameters:
context -
outputArchive -
Throws:
XDocReportException

getDefaultXMLEntries

protected abstract String[] getDefaultXMLEntries()
Returns default entries which define XML document to merge with Java model with template engine for odt, docx...

Returns:

setData

public void setData(String key,
                    Object value)
Returns XML entries which define XML document to merge with Java model with template engine. If custom XML entries is not defined, getDefaultXMLEntries() are used.

Specified by:
setData in interface IXDocReport

getData

public <T> T getData(String key)
Description copied from interface: IXDocReport
Returns custom data.

Specified by:
getData in interface IXDocReport
Returns:

clearData

public void clearData(String key)
Description copied from interface: IXDocReport
Clear data.

Specified by:
clearData in interface IXDocReport

setCacheOriginalDocument

public void setCacheOriginalDocument(boolean cacheOriginalDocument)
Description copied from interface: IXDocReport
Set cache or not for original document archive.

Specified by:
setCacheOriginalDocument in interface IXDocReport

registerPreprocessors

protected abstract void registerPreprocessors()
Register preprocessors.


isPreprocessed

public boolean isPreprocessed()
Returns true if report was processed and false otherwise.

Specified by:
isPreprocessed in interface IXDocReport
Returns:

getLastModified

public long getLastModified()
Returns the last modified time when the report is loaded.

Specified by:
getLastModified in interface IXDocReport
Returns:

createImageRegistry

protected abstract IImageRegistry createImageRegistry(IEntryReaderProvider readerProvider,
                                                      IEntryWriterProvider writerProvider,
                                                      IEntryOutputStreamProvider outputStreamProvider)
Create an image registry.

Returns:

dump

public void dump(IContext context,
                 DumperOptions options,
                 OutputStream out)
          throws IOException,
                 XDocReportException
Description copied from interface: IXDocReport
Dump

Specified by:
dump in interface IXDocReport
Throws:
IOException
XDocReportException

dump

public void dump(IContext context,
                 InputStream documentIn,
                 DumperOptions options,
                 OutputStream out)
          throws IOException,
                 XDocReportException
Description copied from interface: IXDocReport
Dump

Specified by:
dump in interface IXDocReport
Throws:
IOException
XDocReportException

getDumper

public IDumper getDumper(DumperOptions options)
                  throws XDocReportException
Description copied from interface: IXDocReport
Returns the dumper for the given options.

Specified by:
getDumper in interface IXDocReport
Returns:
Throws:
XDocReportException


Copyright © 2013. All rights reserved.