Java源码示例:fr.opensagres.xdocreport.document.registry.XDocReportRegistry

示例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
private void doDownload( HttpServletRequest request, HttpServletResponse response )
    throws IOException, ServletException
{
    String reportId = getReportId( request );
    if ( StringUtils.isNotEmpty( reportId ) )
    {
        DefaultReportController defaultReport = DefaultReportRegistry.INSTANCE.getReportController( reportId );
        if ( defaultReport != null )
        {
            // Get mime mapping
            MimeMapping mimeMapping = null;
            try
            {
                mimeMapping = XDocReportRegistry.getRegistry().getMimeMapping( defaultReport.getFileExtension() );
            }
            catch ( XDocReportException e )
            {
            }
            prepareHTTPResponse( reportId, mimeMapping, request, response );
            IOUtils.copy( defaultReport.getSourceStream(), response.getOutputStream() );
        }
    }
}
 
示例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 IXDocReport loadReport( String reportId, XDocReportRegistry registry, HttpServletRequest request )
    throws IOException, XDocReportException
{
    IXDocReport report = super.loadReport( reportId, registry, request );
    report.setData( LOADED_REPORT_DATE_KEY, Calendar.getInstance().getTime() );
    return report;
}
 
示例5
private boolean existsReport( String reportId )
{
    if ( XDocReportRegistry.getRegistry().existsReport( reportId ) )
    {
        return true;
    }
    return DefaultReportRegistry.INSTANCE.getReportController( reportId ) != null;
}
 
示例6
@Override
public void upload( BinaryData data )
    throws ResourcesException
{

    String resourceId = data.getResourceId();
    String reportId = getReportId( resourceId );

    LOGGER.info( "*****************************************" );
    LOGGER.info( "Start upload resourceId=" + resourceId + ", reportId=" + reportId );

    IXDocReport report = XDocReportRegistry.getRegistry().getReport( reportId );
    if ( report != null )
    {
        try
        {

            report.load( new ByteArrayInputStream( data.getContent() ) );
            LOGGER.info( "*****************************************" );
            LOGGER.info( "End upload resourceId=" + resourceId + ", reportId=" + reportId + " with IXDocReport" );
        }
        catch ( Exception e )
        {
            LOGGER.log( Level.SEVERE, "End upload error resourceId=" + ", reportId=" + reportId
                + " with IXDocReport", e );
            LOGGER.info( "*****************************************" );
            throw new ResourcesException( e );
        }
    }
    else
    {
        DefaultReportController controller = DefaultReportRegistry.INSTANCE.getReportController( reportId );
        if ( controller != null )
        {

            controller.setSource( data.getContent() );

            LOGGER.info( "*****************************************" );
            LOGGER.info( "End upload resourceId=" + resourceId + ", reportId=" + reportId + " with IXDocReport" );
        }
        else
        {
            LOGGER.info( "*****************************************" );
            LOGGER.severe( "End upload resourceId=" + resourceId + ", reportId=" + reportId + " with error" );

            throw new ResourcesException( "Impossible to find report for id=" + reportId );
        }
    }
    LOGGER.info( "*****************************************" );
    LOGGER.info( "End upload resourceId=" + resourceId + ", reportId=" + reportId );
}
 
示例7
@Override
protected XDocReportRegistry getRegistryForUpload( HttpServletRequest request )
{
    return super.getRegistryFromHTTPSession( request );
}
 
示例8
@PostConstruct
public void initialize() {
    xDocReportRegistry = XDocReportRegistry.getRegistry();
    xDocReportRegistry.initialize();
}