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;
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.ReportEngineMetaData;
30 import com.sun.star.report.ReportEngineParameterNames;
31 import com.sun.star.report.ReportJobFactory;
32 
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Set;
38 
39 import org.pentaho.reporting.libraries.base.util.HashNMap;
40 
41 
42 public class PentahoReportEngineMetaData
43         implements ReportEngineMetaData
44 {
45 
46     public static final String OPENDOCUMENT_TEXT = "application/vnd.oasis.opendocument.text";
47     public static final String OPENDOCUMENT_SPREADSHEET = "application/vnd.oasis.opendocument.spreadsheet";
48     public static final String OPENDOCUMENT_CHART = "application/vnd.oasis.opendocument.chart";
49     public final static String CONTENT_TYPE = "content-type";
50     public static final String DEBUG = "raw/text+xml";
51     private final Set mandatoryParameters;
52     private final Map parameterTypes;
53     private final HashNMap enumerationValues;
54 
PentahoReportEngineMetaData()55     public PentahoReportEngineMetaData()
56     {
57         mandatoryParameters = new HashSet();
58         mandatoryParameters.add(ReportEngineParameterNames.CONTENT_TYPE);
59         mandatoryParameters.add(ReportEngineParameterNames.INPUT_NAME);
60         mandatoryParameters.add(ReportEngineParameterNames.INPUT_REPOSITORY);
61         mandatoryParameters.add(ReportEngineParameterNames.OUTPUT_NAME);
62         mandatoryParameters.add(ReportEngineParameterNames.OUTPUT_REPOSITORY);
63         mandatoryParameters.add(ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY);
64         mandatoryParameters.add(ReportEngineParameterNames.IMAGE_SERVICE);
65         mandatoryParameters.add(ReportEngineParameterNames.INPUT_REPORTJOB_FACTORY);
66         mandatoryParameters.add(ReportEngineParameterNames.INPUT_MASTER_COLUMNS);
67         mandatoryParameters.add(ReportEngineParameterNames.INPUT_MASTER_VALUES);
68         mandatoryParameters.add(ReportEngineParameterNames.INPUT_DETAIL_COLUMNS);
69         mandatoryParameters.add(ReportEngineParameterNames.AUTHOR);
70         mandatoryParameters.add(ReportEngineParameterNames.TITLE);
71         mandatoryParameters.add(ReportEngineParameterNames.MAXROWS);
72 
73 
74         parameterTypes = new HashMap();
75         parameterTypes.put(ReportEngineParameterNames.CONTENT_TYPE, String.class);
76         parameterTypes.put(ReportEngineParameterNames.INPUT_NAME, String.class);
77         parameterTypes.put(ReportEngineParameterNames.OUTPUT_NAME, String.class);
78         parameterTypes.put(ReportEngineParameterNames.INPUT_REPOSITORY, InputRepository.class);
79         parameterTypes.put(ReportEngineParameterNames.OUTPUT_REPOSITORY, OutputRepository.class);
80         parameterTypes.put(ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY, DataSourceFactory.class);
81         parameterTypes.put(ReportEngineParameterNames.IMAGE_SERVICE, ImageService.class);
82         parameterTypes.put(ReportEngineParameterNames.INPUT_REPORTJOB_FACTORY, ReportJobFactory.class);
83         parameterTypes.put(ReportEngineParameterNames.INPUT_MASTER_COLUMNS, List.class);
84         parameterTypes.put(ReportEngineParameterNames.INPUT_MASTER_VALUES, List.class);
85         parameterTypes.put(ReportEngineParameterNames.INPUT_DETAIL_COLUMNS, List.class);
86         parameterTypes.put(ReportEngineParameterNames.AUTHOR, String.class);
87         parameterTypes.put(ReportEngineParameterNames.TITLE, String.class);
88         parameterTypes.put(ReportEngineParameterNames.MAXROWS, Integer.class);
89 
90         enumerationValues = new HashNMap();
91         enumerationValues.add(CONTENT_TYPE,
92                 PentahoReportEngineMetaData.OPENDOCUMENT_TEXT);
93         enumerationValues.add(CONTENT_TYPE,
94                 PentahoReportEngineMetaData.OPENDOCUMENT_SPREADSHEET);
95         enumerationValues.add(CONTENT_TYPE,
96                 PentahoReportEngineMetaData.OPENDOCUMENT_CHART);
97         enumerationValues.add(CONTENT_TYPE, PentahoReportEngineMetaData.DEBUG);
98     }
99 
getEnumerationValues(final String parameter)100     public Object[] getEnumerationValues(final String parameter)
101     {
102         return enumerationValues.toArray(parameter);
103     }
104 
getParameterType(final String parameter)105     public Class getParameterType(final String parameter)
106     {
107         return (Class) parameterTypes.get(parameter);
108     }
109 
isEnumeration(final String parameter)110     public boolean isEnumeration(final String parameter)
111     {
112         return enumerationValues.containsKey(parameter);
113     }
114 
115     /**
116      * Checks, whether a certain output type is available. Feed the mime-type of the output
117      * type in and you'll get a true or false back.
118      *
119      * @param mimeType
120      * @return true, if the output type is supported; false otherwise.
121      */
isOutputSupported(final String mimeType)122     public boolean isOutputSupported(final String mimeType)
123     {
124         return enumerationValues.containsValue(CONTENT_TYPE, mimeType.toLowerCase());
125     }
126 
127     /**
128      * Lists all supported output parameters for the given mime-type. This listing can be
129      * used to build a generic user interface for configuring a certain output.
130      *
131      * @param mimeType
132      * @return
133      */
getOutputParameters(final String mimeType)134     public String[] getOutputParameters(final String mimeType)
135     {
136         return new String[0];
137     }
138 
isMandatory(final String parameter)139     public boolean isMandatory(final String parameter)
140     {
141         return mandatoryParameters.contains(parameter);
142     }
143 }
144