Java源码示例:fr.opensagres.xdocreport.template.TemplateEngineKind

示例1
public void writeAsOdt(Invoice invoice, OutputStream out) {
    Locale.setDefault(new Locale("fi"));
    invoice = repo.findBy(invoice.getId());
    invoice.getInvoiceRows().size();
    invoice.getInvoicer().getBankAccount();
    invoice.getInvoicer().getBankAccount();
    invoice.getInvoicer().getEmail();
    invoice.getInvoicer().getAddress();
    invoice.getInvoicer().getPhone();

    try {
        // 1) Load ODT file by filling Velocity template engine and cache
        // it to the registry
        InputStream in = getTemplate(invoice.getInvoicer());
        IXDocReport report = XDocReportRegistry.getRegistry().
                loadReport(in, TemplateEngineKind.Freemarker);

        FieldsMetadata metadata = report.createFieldsMetadata();
        metadata.load("r", InvoiceRow.class, true);

        IContext ctx = report.createContext();
        ctx.put("invoice", invoice);
        ctx.put("to", invoice.getTo());
        ctx.put("r", invoice.getInvoiceRows());
        ctx.
                put("sender", invoicerRepo.findBy(invoice.getInvoicer().
                                getId()));

        // 4) Generate report by merging Java model with the ODT
        report.process(ctx, out);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
示例2
public synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap) throws PDFGenerationException {
    try {
        final IXDocReport report = xDocReportRegistry.loadReport(resource.getInputStream(), TemplateEngineKind.Freemarker);

        final IContext context = report.createContext();
        context.putMap(contextMap);

        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final Options options = Options.getTo(PDF).via(XWPF);
        report.convert(context, options, byteArrayOutputStream);

        return byteArrayOutputStream.toByteArray();
    } catch (IOException | XDocReportException e) {
        throw new PDFGenerationException(e);
    }
}
 
示例3
public void writeAsPdf(Invoice invoice, OutputStream out) {
    Locale.setDefault(new Locale("fi"));
    invoice = repo.findBy(invoice.getId());
    
    try {
        
        // Get template stream (either the default or overridden by the user)
        InputStream in = getTemplate(invoice.getInvoicer());

        // Prepare the IXDocReport instance based on the template, using
        // Freemarker template engine
        IXDocReport report = XDocReportRegistry.getRegistry().
                loadReport(in, TemplateEngineKind.Freemarker);
        
        // Define what we want to do (PDF file from ODF template)
        Options options = Options.getTo(ConverterTypeTo.PDF).via(
                ConverterTypeVia.ODFDOM);

        // Add properties to the context
        IContext ctx = report.createContext();
        ctx.put("invoice", invoice);
        ctx.put("to", invoice.getTo());
        ctx.put("sender", invoice.getInvoicer());
        // instruct XDocReport to inspect InvoiceRow entity as well
        // which is given as list and iterated in a table
        FieldsMetadata metadata = report.createFieldsMetadata();
        metadata.load("r", InvoiceRow.class, true);
        ctx.put("r", invoice.getInvoiceRows());
        
        // Write the PDF file to output stream
        report.convert(ctx, options, out);
        out.close();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
示例4
@Override
protected String getTemplateEngineKind( String reportId, HttpServletRequest request )
{
    if ( ODT_PROJECT_WITH_VELOCITY_LIST.equals( reportId ) || DOCX_PROJECT_WITH_VELOCITY_LIST.equals( reportId ) )
    {
        return TemplateEngineKind.Velocity.name();
    }
    return super.getTemplateEngineKind( reportId, request );
}
 
示例5
public DefaultReportController( String reportId, TemplateEngineKind templateEngineKind,
                                DocumentKind converterTypeFrom )
{
    super( templateEngineKind, converterTypeFrom );
    this.reportId = reportId;
    this.source = null;
}
 
示例6
@Override
protected String getTemplateEngineKind( String reportId, HttpServletRequest request )
{
    if ( ODT_HELLO_WORD_WITH_VELOCITY.equals( reportId ) )
    {
        return TemplateEngineKind.Velocity.name();
    }
    return super.getTemplateEngineKind( reportId, request );
}
 
示例7
@Override
protected String getTemplateEngineKind( String reportId, HttpServletRequest request )
{
    if ( ODT_PROJECT_WITH_VELOCITY_LIST.equals( reportId ) || DOCX_PROJECT_WITH_VELOCITY_LIST.equals( reportId ) )
    {
        return TemplateEngineKind.Velocity.name();
    }
    return super.getTemplateEngineKind( reportId, request );
}
 
示例8
public static void main( String[] args )
{
    try
    {
        FieldsMetadata metadata = new FieldsMetadata( TemplateEngineKind.Velocity );
        metadata.load( "project", ProjectWithImage.class );
        metadata.load( "developers", DeveloperWithImage.class, true );
        metadata.saveXML( System.out );
    }
    catch ( Exception e )
    {
        e.printStackTrace();
    }
}
 
示例9
public static void main( String[] args )
{
    try
    {
        FieldsMetadata metadata = new FieldsMetadata( TemplateEngineKind.Velocity );
        metadata.load( "project", ProjectWithImage.class );
        metadata.load( "developers", DeveloperWithImage.class, true );
        metadata.saveXML( System.out );
    }
    catch ( Exception e )
    {
        e.printStackTrace();
    }
}
 
示例10
public static void main( String[] args )
{
    try
    {
        FieldsMetadata metadata = new FieldsMetadata( TemplateEngineKind.Freemarker );
        metadata.load( "project", ProjectWithImage.class );
        metadata.load( "developers", DeveloperWithImage.class, true );
        metadata.saveXML( System.out );
    }
    catch ( Exception e )
    {
        e.printStackTrace();
    }
}
 
示例11
public static void main( String[] args )
{
    try
    {
        FieldsMetadata metadata = new FieldsMetadata( TemplateEngineKind.Freemarker );
        metadata.load( "project", ProjectWithImage.class );
        metadata.load( "developers", DeveloperWithImage.class, true );
        metadata.saveXML( System.out );
    }
    catch ( Exception e )
    {
        e.printStackTrace();
    }
}
 
示例12
public ODTProjectWithVelocityListController()
{
    super( TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例13
public DocxProjectWithVelocityListController()
{
    super( TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例14
public DocxBig()
{
    super( "DocxBig.docx", TemplateEngineKind.Velocity, DocumentKind.DOCX );
}
 
示例15
public ODTHelloWorldWithVelocity()
{
    super( "ODTHelloWorldWithVelocity.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例16
public ODTLettreRelance()
{
    super( "ODTLettreRelance.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例17
public DocXHelloWorldWithFreemarker()
{
    super( "DocXHelloWorldWithFreemarker.docx", TemplateEngineKind.Freemarker, DocumentKind.DOCX );
}
 
示例18
public ODTStructures()
{
    super( "ODTStructures.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例19
public DocxStructures()
{
    super( "DocxStructures.docx", TemplateEngineKind.Velocity, DocumentKind.DOCX );
}
 
示例20
public DocxLettreRelance()
{
    super( "DocxLettreRelance.docx", TemplateEngineKind.Velocity, DocumentKind.DOCX );
}
 
示例21
public ODTProjectWithVelocity()
{
    super( "ODTProjectWithVelocity.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例22
public ODTHelloWorldWithFreemarker()
{
    super( "ODTHelloWorldWithFreemarker.odt", TemplateEngineKind.Freemarker, DocumentKind.ODT );
}
 
示例23
public ODTBig()
{
    super( "ODTBig.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例24
public ODTProjectWithFreemarker()
{
    super( "ODTProjectWithFreemarker.odt", TemplateEngineKind.Freemarker, DocumentKind.ODT );
}
 
示例25
public DocXHelloWorldWithVelocity()
{
    super( "DocXHelloWorldWithVelocity.docx", TemplateEngineKind.Velocity, DocumentKind.DOCX );
}
 
示例26
public ODTCV()
{
    super( "ODTCV.odt", TemplateEngineKind.Velocity, DocumentKind.ODT );
}
 
示例27
public DocxCV()
{
    super( "DocxCV.docx", TemplateEngineKind.Velocity, DocumentKind.DOCX );
}
 
示例28
public ODTTextStylingWithFreemarker()
{
    super( "ODTTextStylingWithFreemarker.odt", TemplateEngineKind.Freemarker, DocumentKind.ODT );
}
 
示例29
public DocxTextStylingWithFreemarker()
{
    super( "DocxTextStylingWithFreemarker.docx", TemplateEngineKind.Freemarker, DocumentKind.DOCX );
}
 
示例30
public HelloWorldController()
{
    super( TemplateEngineKind.Velocity, DocumentKind.ODT );
}