1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.output.spreadsheet;
24 
25 import com.sun.star.report.DataSourceFactory;
26 import com.sun.star.report.ImageService;
27 import com.sun.star.report.InputRepository;
28 import com.sun.star.report.OutputRepository;
29 import com.sun.star.report.pentaho.PentahoFormulaContext;
30 
31 import org.jfree.report.DataSourceException;
32 import org.jfree.report.ReportDataFactoryException;
33 import org.jfree.report.ReportProcessingException;
34 import org.jfree.report.data.ReportContextImpl;
35 import org.jfree.report.flow.AbstractReportProcessor;
36 import org.jfree.report.flow.ReportContext;
37 import org.jfree.report.flow.ReportJob;
38 import org.jfree.report.flow.ReportStructureRoot;
39 import org.jfree.report.flow.ReportTarget;
40 
41 import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
42 
43 /**
44  * @author Michael D'Amour
45  */
46 public class SpreadsheetRawReportProcessor extends AbstractReportProcessor
47 {
48 
49     private final OutputRepository outputRepository;
50     private final String targetName;
51     private final InputRepository inputRepository;
52     private final ImageService imageService;
53     private final DataSourceFactory dataSourceFactory;
54 
SpreadsheetRawReportProcessor(final InputRepository inputRepository, final OutputRepository outputRepository, final String targetName, final ImageService imageService, final DataSourceFactory dataSourceFactory)55     public SpreadsheetRawReportProcessor(final InputRepository inputRepository,
56             final OutputRepository outputRepository,
57             final String targetName,
58             final ImageService imageService,
59             final DataSourceFactory dataSourceFactory)
60     {
61         if (outputRepository == null)
62         {
63             throw new NullPointerException();
64         }
65         if (targetName == null)
66         {
67             throw new NullPointerException();
68         }
69         if (imageService == null)
70         {
71             throw new NullPointerException();
72         }
73         if (inputRepository == null)
74         {
75             throw new NullPointerException();
76         }
77         if (dataSourceFactory == null)
78         {
79             throw new NullPointerException();
80         }
81 
82         this.targetName = targetName;
83         this.inputRepository = inputRepository;
84         this.outputRepository = outputRepository;
85         this.imageService = imageService;
86         this.dataSourceFactory = dataSourceFactory;
87     }
88 
createReportTarget(final ReportJob job)89     protected ReportTarget createReportTarget(final ReportJob job) throws ReportProcessingException
90     {
91         final ReportStructureRoot report = job.getReportStructureRoot();
92         final ResourceManager resourceManager = report.getResourceManager();
93         return new SpreadsheetRawReportTarget(job, resourceManager, report.getBaseResource(), inputRepository, outputRepository, targetName, imageService, dataSourceFactory);
94     }
95 
processReport(final ReportJob job)96     public void processReport(final ReportJob job) throws ReportDataFactoryException, DataSourceException,
97             ReportProcessingException
98     {
99         final ReportTarget reportTarget = createReportTarget(job);
100         // first run: collect table cell sizes for all tables
101         processReportRun(job, reportTarget);
102         // second run: uses table cell data to output a single uniform table
103         processReportRun(job, reportTarget);
104     }
105 
createReportContext(final ReportJob job, final ReportTarget target)106     protected ReportContext createReportContext(final ReportJob job,
107             final ReportTarget target)
108     {
109         final ReportContext context = super.createReportContext(job, target);
110         if (context instanceof ReportContextImpl)
111         {
112             final ReportContextImpl impl = (ReportContextImpl) context;
113             impl.setFormulaContext(new PentahoFormulaContext(impl.getFormulaContext(), job.getConfiguration()));
114         }
115         return context;
116     }
117 }
118