2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org
.libreoffice
.report
.pentaho
.output
;
20 import org
.libreoffice
.report
.DataSourceFactory
;
21 import org
.libreoffice
.report
.ImageService
;
22 import org
.libreoffice
.report
.InputRepository
;
23 import org
.libreoffice
.report
.JobProperties
;
24 import org
.libreoffice
.report
.OutputRepository
;
25 import org
.libreoffice
.report
.ReportEngineParameterNames
;
26 import org
.libreoffice
.report
.ReportExecutionException
;
27 import org
.libreoffice
.report
.ReportJobDefinition
;
28 import org
.libreoffice
.report
.pentaho
.DefaultNameGenerator
;
29 import org
.libreoffice
.report
.pentaho
.PentahoReportEngine
;
30 import org
.libreoffice
.report
.pentaho
.PentahoReportEngineMetaData
;
32 import java
.io
.IOException
;
34 import java
.util
.List
;
35 import java
.util
.logging
.Logger
;
37 public class OleProducer
40 private static final Logger LOGGER
= Logger
.getLogger(OleProducer
.class.getName());
41 private final InputRepository inputRepository
;
42 private final OutputRepository outputRepository
;
43 private final DefaultNameGenerator nameGenerator
;
44 private final DataSourceFactory dataSourceFactory
;
45 private final ImageService imageService
;
46 private final Integer maxRows
;
48 public OleProducer(final InputRepository inputRepository
,
49 final OutputRepository outputRepository
, final ImageService imageService
, final DataSourceFactory dataSourceFactory
, final Integer maxRows
)
51 if (inputRepository
== null)
53 throw new NullPointerException();
55 if (outputRepository
== null)
57 throw new NullPointerException();
60 this.inputRepository
= inputRepository
;
61 this.outputRepository
= outputRepository
;
62 this.nameGenerator
= new DefaultNameGenerator(outputRepository
);
63 this.dataSourceFactory
= dataSourceFactory
;
64 this.imageService
= imageService
;
65 this.maxRows
= maxRows
;
68 String
produceOle(final String source
, final List masterColumns
, final List masterValues
, final List detailColumns
)
70 InputRepository subInputRepository
= null;
71 OutputRepository subOutputRepository
= null;
75 subInputRepository
= inputRepository
.openInputRepository(source
);
76 output
= nameGenerator
.generateStorageName("Object", null);
77 subOutputRepository
= outputRepository
.openOutputRepository(output
, PentahoReportEngineMetaData
.OPENDOCUMENT_CHART
);
81 final PentahoReportEngine engine
= new PentahoReportEngine();
82 final ReportJobDefinition definition
= engine
.createJobDefinition();
83 final JobProperties procParms
= definition
.getProcessingParameters();
85 procParms
.setProperty(ReportEngineParameterNames
.INPUT_REPOSITORY
, subInputRepository
);
86 procParms
.setProperty(ReportEngineParameterNames
.OUTPUT_REPOSITORY
, subOutputRepository
);
87 procParms
.setProperty(ReportEngineParameterNames
.INPUT_NAME
, "content.xml");
88 procParms
.setProperty(ReportEngineParameterNames
.OUTPUT_NAME
, "content.xml");
89 procParms
.setProperty(ReportEngineParameterNames
.CONTENT_TYPE
, PentahoReportEngineMetaData
.OPENDOCUMENT_CHART
);
90 procParms
.setProperty(ReportEngineParameterNames
.INPUT_DATASOURCE_FACTORY
, dataSourceFactory
);
91 procParms
.setProperty(ReportEngineParameterNames
.INPUT_MASTER_COLUMNS
, masterColumns
);
92 procParms
.setProperty(ReportEngineParameterNames
.INPUT_MASTER_VALUES
, masterValues
);
93 procParms
.setProperty(ReportEngineParameterNames
.INPUT_DETAIL_COLUMNS
, detailColumns
);
94 procParms
.setProperty(ReportEngineParameterNames
.IMAGE_SERVICE
, imageService
);
95 procParms
.setProperty(ReportEngineParameterNames
.MAXROWS
, maxRows
);
97 engine
.createJob(definition
).execute();
99 catch (ReportExecutionException ex
)
101 LOGGER
.severe("ReportProcessing failed: " + ex
);
103 catch (IOException ex
)
105 LOGGER
.severe("ReportProcessing failed: " + ex
);
108 catch (IOException ex
)
110 LOGGER
.severe("ReportProcessing failed: " + ex
);
113 if (subInputRepository
!= null)
115 subInputRepository
.closeInputRepository();
117 if (subOutputRepository
!= null)
119 subOutputRepository
.closeOutputRepository();