Interface IXDocReport

All Superinterfaces:
Serializable
All Known Implementing Classes:
AbstractXDocReport

public interface IXDocReport extends Serializable
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 :

  1. 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.
  2. Create an instance of IXDocReport switch 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();
  3. 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);
  4. Load XML Document (odt, docx) by using load(InputStream).
  5. Prepare your Java model by calling createContext() and put your Java model with IContext.put(String, Object). For instance :

    IContext context = report.createContext(); context.put("name", "word");

  6. Merge the docx, odt document with Java model by calling process(IContext, OutputStream). For instance :

    report.process(context, new FileOutputStream(new File("myfile.odt")));

    This method call will generate myfile.odt file wich will contains Hello word!

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPreprocessor(String entryName, IXDocPreprocessor preprocessor)
    Register a processor for the entry name.
    void
    Clear data.
    void
    convert(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).
    void
    convert(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.IContext
    Create a new instance of IContext to put the Java model.
    fr.opensagres.xdocreport.template.IContext
    Create a new instance of IContext to put the Java model.
    fr.opensagres.xdocreport.template.formatter.FieldsMetadata
    Create fields metadata.
    void
    dump(fr.opensagres.xdocreport.template.IContext context, DumperOptions options, OutputStream out)
    Dump
    void
    dump(fr.opensagres.xdocreport.template.IContext context, InputStream document, DumperOptions options, OutputStream out)
    Dump
    void
    extractFields(fr.opensagres.xdocreport.template.FieldsExtractor extractor)
    Extract declared fields which use syntax of the template egine of the report.
    void
    extractFields(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.IConverter
    getConverter(fr.opensagres.xdocreport.converter.Options options)
    Returns converter for the report and options.
    <T> T
    Returns custom data.
    Returns the dumper for the given options.
    fr.opensagres.xdocreport.template.formatter.FieldsMetadata
    Returns fields metadata used to manage lazy loop for table row.
    Returns the id of the IXDocReport.
    Returns the kind of the report (ODT, docx...).
    long
    Returns the last modified time when the report is loaded.
    fr.opensagres.xdocreport.converter.MimeMapping
    Returns mime mapping switch the kind of the report (odt, docx...).
    fr.opensagres.xdocreport.core.io.XDocArchive
    Returns the original zipped XML document (odt, docx...) and null if : no load was done. cache for original document is false (see setCacheOriginalDocument(boolean).
    fr.opensagres.xdocreport.core.io.XDocArchive
    Returns the preprocessed zipped XML document (odt, docx...) and null if no load was done.
    fr.opensagres.xdocreport.template.ITemplateEngine
    Returns the template engine (Velocity, Freemarker..) to use switch the syntax used in the XML document.
    boolean
    Returns true if report was processed and false otherwise.
    void
    load(InputStream sourceStream)
    Load XML document (odt, docx...) from input stream.
    void
    Force the preprocessing step.
    void
    process(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.
    void
    process(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.
    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 outputStream)
    Merge the docx, odt document with Java model from the context Map and register the entryName transformed to the output stream.
    void
    Clear processor.
    void
    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)
    Store custom data.
    void
    setDocumentArchive(fr.opensagres.xdocreport.core.io.XDocArchive documentArchive)
    Returns the zipped XML document (odt, docx...).
    void
    setFieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata metadata)
    Set fields metadat used to manage lazy loop in table row.
    void
    Set the id of the IXDocReport.
    void
    setTemplateEngine(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 the IXDocReport. This id is used to cache an instance of IXDocReport with and get instance from cache with
    • setId

      void setId(String id)
      Set the id of the IXDocReport. This id is used to cache an instance of IXDocReport with and 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 with IXDocPreprocessor cannot 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:
      IOException
      fr.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:
      IOException
      fr.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 with IXDocPreprocessor cannot be done.
      IOException
    • getOriginalDocumentArchive

      fr.opensagres.xdocreport.core.io.XDocArchive getOriginalDocumentArchive()
      Returns the original zipped XML document (odt, docx...) and null if :
      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.XDocReportException
      Create a new instance of IContext to 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.XDocReportException
      Create a new instance of IContext to 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.XDocReportException
      IOException
    • process

      void process(Map<String,Object> contextMap, OutputStream out) throws fr.opensagres.xdocreport.core.XDocReportException, IOException
      Merge 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.XDocReportException
      IOException
    • 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 name
      out - output stream where merge must be saved.
      Throws:
      fr.opensagres.xdocreport.core.XDocReportException
      IOException
    • process

      void process(Map<String,Object> contextMap, String entryName, OutputStream outputStream) throws fr.opensagres.xdocreport.core.XDocReportException, IOException
      Merge 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 name
      out - output stream where merge must be saved.
      Throws:
      fr.opensagres.xdocreport.core.XDocReportException
      IOException
    • 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.XDocReportException
      fr.opensagres.xdocreport.converter.XDocConverterException
      IOException
    • 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, IOException
      Generate report and Convert it to another format (PDF, XHTML, etc).
      Parameters:
      contextMap -
      options -
      out -
      Throws:
      fr.opensagres.xdocreport.core.XDocReportException
      fr.opensagres.xdocreport.converter.XDocConverterException
      IOException
    • getMimeMapping

      fr.opensagres.xdocreport.converter.MimeMapping getMimeMapping()
      Returns mime mapping switch the kind of the report (odt, docx...).
      Returns:
    • setData

      void setData(String key, Object value)
      Store custom data.
      Parameters:
      key -
      value -
    • clearData

      void clearData(String key)
      Clear data.
      Parameters:
      string -
    • getData

      <T> T getData(String key)
      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.XDocReportException
      IOException
    • 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.XDocReportException
      IOException
    • 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

      void addPreprocessor(String entryName, IXDocPreprocessor preprocessor)
      Register a processor for the entry name.
      Parameters:
      entryName -
      preprocessor -
    • removePreprocessor

      void removePreprocessor(String entryName)
      Remove processor for the entry name.
      Parameters:
      entryName -
    • removeAllPreprocessors

      void removeAllPreprocessors()
      Clear processor.
    • preprocess

      void preprocess() throws fr.opensagres.xdocreport.core.XDocReportException, IOException
      Force the preprocessing step.
      Throws:
      fr.opensagres.xdocreport.core.XDocReportException
      IOException
    • getDumper

      IDumper getDumper(DumperOptions options) throws fr.opensagres.xdocreport.core.XDocReportException
      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:
      IOException
      fr.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:
      IOException
      fr.opensagres.xdocreport.core.XDocReportException