Interface IXDocReport
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractXDocReport
XML Document reporting used to load XML document (odt, docx...) and generate reporting by merging it with Java data
model by using a template engine
ITemplateEngine.
To generate reporting, here steps to follow :
- Create an XML Document (docx with MS Word, odt with Open Office) by writing your fields with syntax wich
depends on template engine :
- with Freemarker : you can write Hello ${name}! in your docx, odt document.
- with Velocity : you can write Hello $name! in your docx, odt document.
- Create an instance of
IXDocReportswitch the type of the document:- for docx :
IXDocReport report = new fr.opensagres.xdocreport.document.docx.DocXReport(); - for odt :
IXDocReport report = new fr.opensagres.xdocreport.document.odt.ODTReport();
- for docx :
- Initialize template engine by using
setTemplateEngine(ITemplateEngine)to set the template engine (Velocity, Freemarker..) to use :- for freemarker :
report.setTemplateEngine(net.sourceforge.rtf.template.freemarker.FreemarkerTemplateEngine.DEFAULT); - for velocity :
report.setTemplateEngine(net.sourceforge.rtf.template.velocity.VelocityTemplateEngine.DEFAULT);
- for freemarker :
- Load XML Document (odt, docx) by using
load(InputStream). - Prepare your Java model by calling
createContext()and put your Java model withIContext.put(String, Object). For instance :IContext context = report.createContext(); context.put("name", "word"); - Merge the docx, odt document with Java model by calling
process(IContext, OutputStream). For instance :
This method call will generate myfile.odt file wich will contains Hello word!report.process(context, new FileOutputStream(new File("myfile.odt")));
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPreprocessor(String entryName, IXDocPreprocessor preprocessor) Register a processor for the entry name.voidClear data.voidconvert(fr.opensagres.xdocreport.template.IContext context, fr.opensagres.xdocreport.converter.Options options, OutputStream out) Generate report and Convert it to another format (PDF, XHTML, etc).voidconvert(Map<String, Object> contextMap, fr.opensagres.xdocreport.converter.Options options, OutputStream out) Generate report and Convert it to another format (PDF, XHTML, etc).fr.opensagres.xdocreport.template.IContextCreate a new instance ofIContextto put the Java model.fr.opensagres.xdocreport.template.IContextcreateContext(Map<String, Object> contextMap) Create a new instance ofIContextto put the Java model.fr.opensagres.xdocreport.template.formatter.FieldsMetadataCreate fields metadata.voiddump(fr.opensagres.xdocreport.template.IContext context, DumperOptions options, OutputStream out) Dumpvoiddump(fr.opensagres.xdocreport.template.IContext context, InputStream document, DumperOptions options, OutputStream out) DumpvoidextractFields(fr.opensagres.xdocreport.template.FieldsExtractor extractor) Extract declared fields which use syntax of the template egine of the report.voidextractFields(fr.opensagres.xdocreport.template.FieldsExtractor extractor, fr.opensagres.xdocreport.template.ITemplateEngine templateEngine) Extract declared fields which use syntax of the given template egine of the report.fr.opensagres.xdocreport.converter.IConvertergetConverter(fr.opensagres.xdocreport.converter.Options options) Returns converter for the report and options.<T> TReturns custom data.getDumper(DumperOptions options) Returns the dumper for the given options.fr.opensagres.xdocreport.template.formatter.FieldsMetadataReturns fields metadata used to manage lazy loop for table row.getId()Returns the id of theIXDocReport.getKind()Returns the kind of the report (ODT, docx...).longReturns the last modified time when the report is loaded.fr.opensagres.xdocreport.converter.MimeMappingReturns mime mapping switch the kind of the report (odt, docx...).fr.opensagres.xdocreport.core.io.XDocArchiveReturns the original zipped XML document (odt, docx...) and null if : no load was done. cache for original document is false (seesetCacheOriginalDocument(boolean).fr.opensagres.xdocreport.core.io.XDocArchiveReturns the preprocessed zipped XML document (odt, docx...) and null if no load was done.fr.opensagres.xdocreport.template.ITemplateEngineReturns the template engine (Velocity, Freemarker..) to use switch the syntax used in the XML document.booleanReturns true if report was processed and false otherwise.voidload(InputStream sourceStream) Load XML document (odt, docx...) from input stream.voidForce the preprocessing step.voidprocess(fr.opensagres.xdocreport.template.IContext context, OutputStream out) Merge the docx, odt document with Java model from the context and register the result to the output stream.voidprocess(fr.opensagres.xdocreport.template.IContext context, String entryName, OutputStream outputStream) Merge the docx, odt document with Java model from the context and register the entryName transformed to the output stream.voidprocess(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.voidMerge the docx, odt document with Java model from the context Map and register the entryName transformed to the output stream.voidClear processor.voidremovePreprocessor(String entryName) Remove processor for the entry name.voidsave(ProcessState processState, OutputStream out) Save original|preprocessed XML document archive in the given output stream.voidsaveEntry(String entryName, ProcessState processState, OutputStream out) Save original|preprocessed entryName from XML document archive in the given output stream.voidsetCacheOriginalDocument(boolean cacheOriginalDocument) Set cache or not for original document archive.voidStore custom data.voidsetDocumentArchive(fr.opensagres.xdocreport.core.io.XDocArchive documentArchive) Returns the zipped XML document (odt, docx...).voidsetFieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata metadata) Set fields metadat used to manage lazy loop in table row.voidSet the id of theIXDocReport.voidsetTemplateEngine(fr.opensagres.xdocreport.template.ITemplateEngine templateEngine) Set the template engine (Velocity, Freemarker..) to use switch the syntax used in the XML document.
-
Method Details
-
getKind
String getKind()Returns the kind of the report (ODT, docx...).- Returns:
-
getId
String getId()Returns the id of theIXDocReport. This id is used to cache an instance ofIXDocReportwithand get instance from cache with -
setId
Set the id of theIXDocReport. This id is used to cache an instance ofIXDocReportwithand get instance from cache with -
load
void load(InputStream sourceStream) throws IOException, fr.opensagres.xdocreport.core.XDocReportException Load XML document (odt, docx...) from input stream.- Parameters:
sourceStream- stream of the XML Document zip (odt, docx...).- Throws:
IOException- when XML Document zip (odt, docx...) cannot be read.fr.opensagres.xdocreport.core.XDocReportException- when preprocessing withIXDocPreprocessorcannot be done.
-
save
void save(ProcessState processState, OutputStream out) throws IOException, fr.opensagres.xdocreport.core.XDocReportException Save original|preprocessed XML document archive in the given output stream.- Parameters:
out-- Throws:
IOExceptionfr.opensagres.xdocreport.core.XDocReportException
-
saveEntry
void saveEntry(String entryName, ProcessState processState, OutputStream out) throws IOException, fr.opensagres.xdocreport.core.XDocReportException Save original|preprocessed entryName from XML document archive in the given output stream.- Parameters:
out-- Throws:
IOExceptionfr.opensagres.xdocreport.core.XDocReportException
-
setDocumentArchive
void setDocumentArchive(fr.opensagres.xdocreport.core.io.XDocArchive documentArchive) throws IOException, fr.opensagres.xdocreport.core.XDocReportException Returns the zipped XML document (odt, docx...).- Parameters:
documentArchive-XDocArchive.- Throws:
fr.opensagres.xdocreport.core.XDocReportException- when preprocessing withIXDocPreprocessorcannot be done.IOException
-
getOriginalDocumentArchive
fr.opensagres.xdocreport.core.io.XDocArchive getOriginalDocumentArchive()Returns the original zipped XML document (odt, docx...) and null if :- no load was done.
- cache for original document is false (see
setCacheOriginalDocument(boolean).
- Returns:
-
getPreprocessedDocumentArchive
fr.opensagres.xdocreport.core.io.XDocArchive getPreprocessedDocumentArchive()Returns the preprocessed zipped XML document (odt, docx...) and null if no load was done.- Returns:
-
setTemplateEngine
void setTemplateEngine(fr.opensagres.xdocreport.template.ITemplateEngine templateEngine) Set the template engine (Velocity, Freemarker..) to use switch the syntax used in the XML document.- Parameters:
templateEngine-
-
getTemplateEngine
fr.opensagres.xdocreport.template.ITemplateEngine getTemplateEngine()Returns the template engine (Velocity, Freemarker..) to use switch the syntax used in the XML document.- Returns:
-
setFieldsMetadata
void setFieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata metadata) Set fields metadat used to manage lazy loop in table row.- Parameters:
metadata-
-
createContext
fr.opensagres.xdocreport.template.IContext createContext() throws fr.opensagres.xdocreport.core.XDocReportExceptionCreate a new instance ofIContextto put the Java model.- Returns:
- Throws:
fr.opensagres.xdocreport.core.XDocReportException
-
createContext
fr.opensagres.xdocreport.template.IContext createContext(Map<String, Object> contextMap) throws fr.opensagres.xdocreport.core.XDocReportExceptionCreate a new instance ofIContextto put the Java model.- Returns:
- Throws:
fr.opensagres.xdocreport.core.XDocReportException
-
process
void process(fr.opensagres.xdocreport.template.IContext context, OutputStream out) throws fr.opensagres.xdocreport.core.XDocReportException, IOException Merge the docx, odt document with Java model from the context and register the result to the output stream.- Parameters:
context- of the Java model.out- output stream where merge must be saved.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
process
void process(Map<String, Object> contextMap, OutputStream out) throws fr.opensagres.xdocreport.core.XDocReportException, IOExceptionMerge the docx, odt document with Java model from the context Map and register the result to the output stream.- Parameters:
context- of the Java model.out- output stream where merge must be saved.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
process
void process(fr.opensagres.xdocreport.template.IContext context, String entryName, OutputStream outputStream) throws fr.opensagres.xdocreport.core.XDocReportException, IOException Merge the docx, odt document with Java model from the context and register the entryName transformed to the output stream.- Parameters:
context- of the Java model.entryName- entry nameout- output stream where merge must be saved.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
process
void process(Map<String, Object> contextMap, String entryName, OutputStream outputStream) throws fr.opensagres.xdocreport.core.XDocReportException, IOExceptionMerge the docx, odt document with Java model from the context Map and register the entryName transformed to the output stream.- Parameters:
context- of the Java model.entryName- entry nameout- output stream where merge must be saved.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
getConverter
fr.opensagres.xdocreport.converter.IConverter getConverter(fr.opensagres.xdocreport.converter.Options options) throws fr.opensagres.xdocreport.converter.XDocConverterException Returns converter for the report and options.- Parameters:
options-- Returns:
- Throws:
fr.opensagres.xdocreport.converter.XDocConverterException
-
convert
void convert(fr.opensagres.xdocreport.template.IContext context, fr.opensagres.xdocreport.converter.Options options, OutputStream out) throws fr.opensagres.xdocreport.core.XDocReportException, fr.opensagres.xdocreport.converter.XDocConverterException, IOException Generate report and Convert it to another format (PDF, XHTML, etc).- Parameters:
context-options-out-- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionfr.opensagres.xdocreport.converter.XDocConverterExceptionIOException
-
convert
void convert(Map<String, Object> contextMap, fr.opensagres.xdocreport.converter.Options options, OutputStream out) throws fr.opensagres.xdocreport.core.XDocReportException, fr.opensagres.xdocreport.converter.XDocConverterException, IOExceptionGenerate report and Convert it to another format (PDF, XHTML, etc).- Parameters:
contextMap-options-out-- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionfr.opensagres.xdocreport.converter.XDocConverterExceptionIOException
-
getMimeMapping
fr.opensagres.xdocreport.converter.MimeMapping getMimeMapping()Returns mime mapping switch the kind of the report (odt, docx...).- Returns:
-
setData
Store custom data.- Parameters:
key-value-
-
clearData
Clear data.- Parameters:
string-
-
getData
Returns custom data.- Parameters:
key-- Returns:
-
extractFields
void extractFields(fr.opensagres.xdocreport.template.FieldsExtractor extractor, fr.opensagres.xdocreport.template.ITemplateEngine templateEngine) throws fr.opensagres.xdocreport.core.XDocReportException, IOException Extract declared fields which use syntax of the given template egine of the report.- Parameters:
extractor- the fields extractor.templateEngine- the template engine.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
extractFields
void extractFields(fr.opensagres.xdocreport.template.FieldsExtractor extractor) throws fr.opensagres.xdocreport.core.XDocReportException, IOException Extract declared fields which use syntax of the template egine of the report.- Parameters:
extractor- the fields extractor.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
setCacheOriginalDocument
void setCacheOriginalDocument(boolean cacheOriginalDocument) Set cache or not for original document archive.- Parameters:
cache-
-
isPreprocessed
boolean isPreprocessed()Returns true if report was processed and false otherwise.- Returns:
-
getLastModified
long getLastModified()Returns the last modified time when the report is loaded.- Returns:
-
getFieldsMetadata
fr.opensagres.xdocreport.template.formatter.FieldsMetadata getFieldsMetadata()Returns fields metadata used to manage lazy loop for table row.- Returns:
-
createFieldsMetadata
fr.opensagres.xdocreport.template.formatter.FieldsMetadata createFieldsMetadata()Create fields metadata.- Returns:
-
addPreprocessor
Register a processor for the entry name.- Parameters:
entryName-preprocessor-
-
removePreprocessor
Remove processor for the entry name.- Parameters:
entryName-
-
removeAllPreprocessors
void removeAllPreprocessors()Clear processor. -
preprocess
Force the preprocessing step.- Throws:
fr.opensagres.xdocreport.core.XDocReportExceptionIOException
-
getDumper
Returns the dumper for the given options.- Parameters:
options-- Returns:
- Throws:
fr.opensagres.xdocreport.core.XDocReportException
-
dump
void dump(fr.opensagres.xdocreport.template.IContext context, InputStream document, DumperOptions options, OutputStream out) throws IOException, fr.opensagres.xdocreport.core.XDocReportException Dump- Parameters:
context-kind-options-- Throws:
IOExceptionfr.opensagres.xdocreport.core.XDocReportException
-
dump
void dump(fr.opensagres.xdocreport.template.IContext context, DumperOptions options, OutputStream out) throws IOException, fr.opensagres.xdocreport.core.XDocReportException Dump- Parameters:
context-kind-options-- Throws:
IOExceptionfr.opensagres.xdocreport.core.XDocReportException
-