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; 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.JobProperties; 29 import com.sun.star.report.OutputRepository; 30 import com.sun.star.report.ReportEngineParameterNames; 31 import com.sun.star.report.ReportExecutionException; 32 import com.sun.star.report.ReportJobDefinition; 33 import com.sun.star.report.pentaho.DefaultNameGenerator; 34 import com.sun.star.report.pentaho.PentahoReportEngine; 35 import com.sun.star.report.pentaho.PentahoReportEngineMetaData; 36 37 import java.io.IOException; 38 39 import java.util.List; 40 41 import org.apache.commons.logging.Log; 42 import org.apache.commons.logging.LogFactory; 43 44 /** 45 * 46 * @author Ocke Janssen 47 */ 48 public class OleProducer 49 { 50 51 private static final Log LOGGER = LogFactory.getLog(OleProducer.class); 52 private final InputRepository inputRepository; 53 private final OutputRepository outputRepository; 54 private final DefaultNameGenerator nameGenerator; 55 private final DataSourceFactory dataSourceFactory; 56 private final ImageService imageService; 57 private final Integer maxRows; 58 OleProducer(final InputRepository inputRepository, final OutputRepository outputRepository, final ImageService imageService, final DataSourceFactory dataSourceFactory, final Integer maxRows)59 public OleProducer(final InputRepository inputRepository, 60 final OutputRepository outputRepository, final ImageService imageService, final DataSourceFactory dataSourceFactory, final Integer maxRows) 61 { 62 if (inputRepository == null) 63 { 64 throw new NullPointerException(); 65 } 66 if (outputRepository == null) 67 { 68 throw new NullPointerException(); 69 } 70 71 this.inputRepository = inputRepository; 72 this.outputRepository = outputRepository; 73 this.nameGenerator = new DefaultNameGenerator(outputRepository); 74 this.dataSourceFactory = dataSourceFactory; 75 this.imageService = imageService; 76 this.maxRows = maxRows; 77 } 78 produceOle(final String source, final List masterColumns, final List masterValues, final List detailColumns)79 String produceOle(final String source, final List masterColumns, final List masterValues, final List detailColumns) 80 { 81 InputRepository subInputRepository = null; 82 OutputRepository subOutputRepository = null; 83 String output = ""; 84 try 85 { 86 subInputRepository = inputRepository.openInputRepository(source); 87 output = nameGenerator.generateStorageName("Object", null); 88 subOutputRepository = outputRepository.openOutputRepository(output, PentahoReportEngineMetaData.OPENDOCUMENT_CHART); 89 try 90 { 91 92 final PentahoReportEngine engine = new PentahoReportEngine(); 93 final ReportJobDefinition definition = engine.createJobDefinition(); 94 final JobProperties procParms = definition.getProcessingParameters(); 95 96 procParms.setProperty(ReportEngineParameterNames.INPUT_REPOSITORY, subInputRepository); 97 procParms.setProperty(ReportEngineParameterNames.OUTPUT_REPOSITORY, subOutputRepository); 98 procParms.setProperty(ReportEngineParameterNames.INPUT_NAME, "content.xml"); 99 procParms.setProperty(ReportEngineParameterNames.OUTPUT_NAME, "content.xml"); 100 procParms.setProperty(ReportEngineParameterNames.CONTENT_TYPE, PentahoReportEngineMetaData.OPENDOCUMENT_CHART); 101 procParms.setProperty(ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY, dataSourceFactory); 102 procParms.setProperty(ReportEngineParameterNames.INPUT_MASTER_COLUMNS, masterColumns); 103 procParms.setProperty(ReportEngineParameterNames.INPUT_MASTER_VALUES, masterValues); 104 procParms.setProperty(ReportEngineParameterNames.INPUT_DETAIL_COLUMNS, detailColumns); 105 procParms.setProperty(ReportEngineParameterNames.IMAGE_SERVICE, imageService); 106 procParms.setProperty(ReportEngineParameterNames.MAXROWS, maxRows); 107 108 engine.createJob(definition).execute(); 109 } 110 catch (ReportExecutionException ex) 111 { 112 LOGGER.error("ReportProcessing failed", ex); 113 } 114 catch (IOException ex) 115 { 116 LOGGER.error("ReportProcessing failed", ex); 117 } 118 } 119 catch (IOException ex) 120 { 121 LOGGER.error("ReportProcessing failed", ex); 122 } finally 123 { 124 if (subInputRepository != null) 125 { 126 subInputRepository.closeInputRepository(); 127 } 128 if (subOutputRepository != null) 129 { 130 subOutputRepository.closeOutputRepository(); 131 } 132 } 133 return output; 134 } 135 } 136