Source Code Cross Referenced for XActionHelper.java in  » Report » pentaho-report » org » pentaho » reportdesigner » crm » report » reportexporter » jfreereport » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.pentaho.reportdesigner.crm.report.reportexporter.jfreereport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 Pentaho Corporation.  All rights reserved.
003:         * This software was developed by Pentaho Corporation and is provided under the terms
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005:         * this file except in compliance with the license. If you need a copy of the license,
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007:         *
008:         * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
010:         * the license for the specific language governing your rights and limitations.
011:         *
012:         * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013:         */
014:        package org.pentaho.reportdesigner.crm.report.reportexporter.jfreereport;
015:
016:        import org.jetbrains.annotations.NotNull;
017:        import org.pentaho.actionsequence.dom.ActionOutput;
018:        import org.pentaho.actionsequence.dom.ActionSequenceDocument;
019:        import org.pentaho.actionsequence.dom.ActionSequenceInput;
020:        import org.pentaho.actionsequence.dom.ActionSequenceOutput;
021:        import org.pentaho.actionsequence.dom.actions.JFreeReportAction;
022:        import org.pentaho.actionsequence.dom.actions.MQLAction;
023:        import org.pentaho.actionsequence.dom.actions.MdxConnectionAction;
024:        import org.pentaho.actionsequence.dom.actions.MdxQueryAction;
025:        import org.pentaho.actionsequence.dom.actions.SecureFilterAction;
026:        import org.pentaho.actionsequence.dom.actions.SqlQueryAction;
027:        import org.pentaho.actionsequence.dom.actions.XQueryAction;
028:        import org.pentaho.reportdesigner.crm.report.datasetplugin.multidataset.MultiDataSetReportElement;
029:        import org.pentaho.reportdesigner.crm.report.datasetplugin.multidataset.Query;
030:        import org.pentaho.reportdesigner.crm.report.model.ReportElement;
031:        import org.pentaho.reportdesigner.crm.report.model.dataset.DataSetsReportElement;
032:
033:        import javax.swing.table.DefaultTableModel;
034:        import java.io.File;
035:        import java.util.ArrayList;
036:        import java.util.regex.Matcher;
037:        import java.util.regex.Pattern;
038:
039:        /**
040:         * User: Martin Date: 04.08.2006 Time: 11:14:14
041:         */
042:        @SuppressWarnings({"ALL"})
043:        public class XActionHelper {
044:
045:            private XActionHelper() {
046:            }
047:
048:            /**
049:             * convert ${NAME} to ${PREPAREDLATER:NAME}
050:             *
051:             * @param text report designer syntax
052:             * @return action sequence syntax
053:             */
054:            private static String convertProperties(String text) {
055:                StringBuffer buf = new StringBuffer(text.length() + 200);
056:                Pattern pattern = Pattern.compile("\\$\\{([^${}]+)\\}");
057:                Matcher matcher = pattern.matcher(text);
058:                while (matcher.find()) {
059:                    String varName = matcher.group(1);
060:                    matcher.appendReplacement(buf, "{PREPARELATER:" + varName
061:                            + "}");
062:                }
063:                matcher.appendTail(buf);
064:                return buf.toString();
065:            }
066:
067:            /**
068:             * setup the action sequence
069:             *
070:             * @param reportTitle
071:             * @param reportDescription
072:             * @param type
073:             * @param jFreeReportFileName
074:             * @return
075:             */
076:            private static ActionSequenceDocument initActionSequenceDoc(
077:                    String reportTitle, String reportDescription, String type,
078:                    String jFreeReportFileName) {
079:                ActionSequenceDocument actionSequenceDocument = new ActionSequenceDocument();
080:                actionSequenceDocument.setTitle(reportTitle);
081:                actionSequenceDocument.setVersion("1");
082:                actionSequenceDocument.setAuthor("Report Designer");
083:                actionSequenceDocument.setDescription(reportDescription);
084:                actionSequenceDocument.setIconLocation("PentahoReporting.png");
085:                actionSequenceDocument.setHelp("Choose Report Output Format.");
086:                actionSequenceDocument.setResultType("report");
087:                ActionSequenceInput outputType = actionSequenceDocument
088:                        .createInput("outputType",
089:                                ActionSequenceDocument.STRING_TYPE);
090:                outputType.setDefaultValue(type);
091:                outputType.addSource(
092:                        ActionSequenceDocument.REQUEST_INPUT_SOURCE, "type");
093:                ActionSequenceInput outputTypeList = actionSequenceDocument
094:                        .createInput("outputTypeList",
095:                                ActionSequenceDocument.PROPERTY_MAP_LIST_TYPE);
096:                outputTypeList.addSource(
097:                        ActionSequenceDocument.RUNTIME_INPUT_SOURCE,
098:                        "outputTypeList");
099:                DefaultTableModel defaultTableModel = new DefaultTableModel();
100:                defaultTableModel.addColumn("report-output-desc");
101:                defaultTableModel.addColumn("report-output-type-id");
102:                defaultTableModel.addRow(new String[] { "PDF", "pdf" });
103:                defaultTableModel.addRow(new String[] { "Excel", "xls" });
104:                defaultTableModel.addRow(new String[] { "Word", "rtf" });
105:                defaultTableModel.addRow(new String[] { "Web Page", "html" });
106:                defaultTableModel.addRow(new String[] {
107:                        "Comma Separated Value", "csv" });
108:                outputTypeList.setDefaultValue(defaultTableModel, true);
109:                actionSequenceDocument.createResource("report-definition",
110:                        "solution-file", jFreeReportFileName, "text/xml");
111:                SecureFilterAction secureFilterAction = new SecureFilterAction();
112:                actionSequenceDocument.add(secureFilterAction);
113:                secureFilterAction
114:                        .setDescription("Prompt for Report Export Type");
115:                secureFilterAction.addInputParam("outputTypeList",
116:                        "property-map-list");
117:                secureFilterAction.addInputParam("outputType", "string");
118:                secureFilterAction.setComponentDefinitionAttribute(
119:                        "selections/outputType", "style", "radio");
120:                secureFilterAction.setComponentDefinition(
121:                        "selections/outputType/title", "Choose Report Format");
122:                secureFilterAction.setComponentDefinition(
123:                        "selections/outputType/filter", "outputTypeList");
124:                secureFilterAction.setComponentDefinitionAttribute(
125:                        "selections/outputType/filter", "value-col-name",
126:                        "report-output-type-id");
127:                secureFilterAction.setComponentDefinitionAttribute(
128:                        "selections/outputType/filter", "display-col-name",
129:                        "report-output-desc");
130:                return actionSequenceDocument;
131:            }
132:
133:            /**
134:             * complete the processing of the action sequence
135:             *
136:             * @param actionSequenceDocument
137:             * @param mainResultSet
138:             * @param queries
139:             */
140:            private static void finishProcessing(
141:                    ActionSequenceDocument actionSequenceDocument,
142:                    ActionOutput mainResultSet, ArrayList<Query> queries) {
143:                ActionSequenceInput outputType = actionSequenceDocument
144:                        .getInput("outputType");
145:                JFreeReportAction jfreeReportAction = new JFreeReportAction();
146:                actionSequenceDocument.add(jfreeReportAction);
147:                jfreeReportAction.setDescription("report");
148:                jfreeReportAction.setOutputTypeParam(outputType);
149:                jfreeReportAction.setDataParam(mainResultSet);
150:                jfreeReportAction.setOutputReportName("content");
151:                for (int i = 1; i < queries.size(); i++) {
152:                    Query query = queries.get(i);
153:                    jfreeReportAction.setInputParam(query.getQueryName(), query
154:                            .getQueryName());
155:                }
156:                ActionSequenceOutput output = actionSequenceDocument
157:                        .createOutput("content",
158:                                ActionSequenceDocument.CONTENT_TYPE);
159:                output.addDestination(
160:                        ActionSequenceDocument.RESPONSE_OUTPUT_DESTINATION,
161:                        "content");
162:            }
163:
164:            @NotNull
165:            public static String getXActionFile(@NotNull
166:            String xactionFileName, @NotNull
167:            String publishSolutionPath, @NotNull
168:            String reportTitle, @NotNull
169:            String reportDescription, @NotNull
170:            String type, @NotNull
171:            String jFreeReportFileName, boolean useJNDI,
172:                    DataSetsReportElement dataSetsReportElement) {
173:                ActionSequenceDocument actionSequenceDocument = initActionSequenceDoc(
174:                        reportTitle, reportDescription, type,
175:                        jFreeReportFileName);
176:                ArrayList<MultiDataSetReportElement> dataSets = new ArrayList<MultiDataSetReportElement>();
177:                ArrayList<Query> queries = new ArrayList<Query>();
178:                // add the "default" query first
179:                for (ReportElement reportElement : dataSetsReportElement
180:                        .getChildren()) {
181:                    if (reportElement instanceof  MultiDataSetReportElement) {
182:                        MultiDataSetReportElement multiDataSetReportElement = (MultiDataSetReportElement) reportElement;
183:                        Query query = multiDataSetReportElement.getQueries()
184:                                .get(0);
185:                        if (query.getQueryName().equalsIgnoreCase("default")) {
186:                            dataSets.add(multiDataSetReportElement);
187:                            queries.add(query);
188:                        }
189:                    }
190:                }
191:                // now add the rest of the queries (not default)
192:                for (ReportElement reportElement : dataSetsReportElement
193:                        .getChildren()) {
194:                    if (reportElement instanceof  MultiDataSetReportElement) {
195:                        MultiDataSetReportElement multiDataSetReportElement = (MultiDataSetReportElement) reportElement;
196:                        Query query = multiDataSetReportElement.getQueries()
197:                                .get(0);
198:                        if (!query.getQueryName().equalsIgnoreCase("default")) {
199:                            dataSets.add(multiDataSetReportElement);
200:                            queries.add(query);
201:                        }
202:                    }
203:                }
204:
205:                ActionOutput mainActionOutput = null;
206:                for (int i = 0; i < dataSets.size(); i++) {
207:                    MultiDataSetReportElement dataSet = dataSets.get(i);
208:                    Query query = dataSet.getQueries().get(0);
209:                    // setup sql connection component
210:                    if (dataSet.getConnectionType() == MultiDataSetReportElement.ConnectionType.JNDI) {
211:                        //
212:                        // handle JNDI based connections
213:                        //
214:                        if (dataSet.isUseMondrianCubeDefinition()) {
215:                            //
216:                            // handle mondrian
217:                            //
218:                            String mondrianCubeDefinitionSolutionPath = (new File(
219:                                    dataSet.getMondrianCubeDefinitionFile()))
220:                                    .getName();
221:                            actionSequenceDocument.createResource(
222:                                    "catalog" + i, "solution-file",
223:                                    mondrianCubeDefinitionSolutionPath,
224:                                    "text/xml");
225:                            // add mdx connection component
226:                            MdxConnectionAction mdxConnectionAction = new MdxConnectionAction();
227:                            actionSequenceDocument.add(mdxConnectionAction);
228:                            mdxConnectionAction.setOutputConnectionName("conn"
229:                                    + i);
230:                            mdxConnectionAction
231:                                    .setMdxConnectionString(mondrianCubeDefinitionSolutionPath);
232:                            mdxConnectionAction.addResourceParam("catalog",
233:                                    "catalog" + i);
234:                            mdxConnectionAction.setLocation("mondrian");
235:                            if (useJNDI) {
236:                                mdxConnectionAction.setJndi(dataSet
237:                                        .getSelectedJNDIDataSource()
238:                                        .getJndiName());
239:                            } else {
240:                                mdxConnectionAction.setDriver(dataSet
241:                                        .getSelectedJNDIDataSource()
242:                                        .getDriverClass());
243:                                mdxConnectionAction.setUserId(dataSet
244:                                        .getSelectedJNDIDataSource()
245:                                        .getUsername());
246:                                mdxConnectionAction.setPassword(dataSet
247:                                        .getSelectedJNDIDataSource()
248:                                        .getPassword());
249:                                mdxConnectionAction.setConnection(dataSet
250:                                        .getSelectedJNDIDataSource()
251:                                        .getConnectionString());
252:                            }
253:                            // add mdx query component
254:                            MdxQueryAction mainMdxLookupRule = new MdxQueryAction();
255:                            actionSequenceDocument.add(mainMdxLookupRule);
256:                            mainMdxLookupRule
257:                                    .setMdxConnectionParam(mdxConnectionAction
258:                                            .getOutputConnectionParam());
259:                            if (query.getQueryName().equals("default")) {
260:                                mainActionOutput = mainMdxLookupRule
261:                                        .getOutputResultSetParam();
262:                                mainMdxLookupRule.setQuery(query.getQuery());
263:                            } else {
264:                                mainMdxLookupRule
265:                                        .setOutputPreparedStatementName(query
266:                                                .getQueryName());
267:                                String preparedSubquery = convertProperties(query
268:                                        .getQuery());
269:                                mainMdxLookupRule.setQuery(preparedSubquery);
270:                            }
271:                        } else {
272:                            //
273:                            // handle sql
274:                            //
275:                            SqlQueryAction sqlLookupRule = new SqlQueryAction();
276:                            actionSequenceDocument.add(sqlLookupRule);
277:                            if (useJNDI) {
278:                                sqlLookupRule.setJndi(dataSet
279:                                        .getSelectedJNDIDataSource()
280:                                        .getJndiName());
281:                            } else {
282:                                sqlLookupRule.setDriver(dataSet
283:                                        .getSelectedJNDIDataSource()
284:                                        .getDriverClass());
285:                                sqlLookupRule.setUserId(dataSet
286:                                        .getSelectedJNDIDataSource()
287:                                        .getUsername());
288:                                sqlLookupRule.setPassword(dataSet
289:                                        .getSelectedJNDIDataSource()
290:                                        .getPassword());
291:                                sqlLookupRule.setDbUrl(dataSet
292:                                        .getSelectedJNDIDataSource()
293:                                        .getConnectionString());
294:                            }
295:                            // if the dataset name is "default" it will override the existing "default" dataset
296:                            if (query.getQueryName().equals("default")) {
297:                                mainActionOutput = sqlLookupRule
298:                                        .getOutputResultSetParam();
299:                                sqlLookupRule.setQuery(query.getQuery());
300:                            } else {
301:                                sqlLookupRule
302:                                        .setOutputPreparedStatementName(query
303:                                                .getQueryName());
304:                                String preparedSubquery = convertProperties(query
305:                                        .getQuery());
306:                                sqlLookupRule.setQuery(preparedSubquery);
307:                            }
308:                        }
309:                    } else if (dataSet.getConnectionType() == MultiDataSetReportElement.ConnectionType.XQuery) {
310:                        //
311:                        // handle xquery
312:                        //
313:                        File xQueryDataFile = new File(dataSet
314:                                .getXQueryDataFile());
315:                        actionSequenceDocument.createResource("document" + i,
316:                                "solution-file", xQueryDataFile.getName(),
317:                                "text/xml");
318:                        XQueryAction xqueryAction = new XQueryAction();
319:                        actionSequenceDocument.add(xqueryAction);
320:                        xqueryAction.setOutputResultSetName("list");
321:                        xqueryAction.addResourceParam("document", "document"
322:                                + i);
323:                        if (query.getQueryName().equals("default")) {
324:                            mainActionOutput = xqueryAction
325:                                    .getOutputResultSetParam();
326:                            xqueryAction.setQuery(query.getQuery());
327:                            xqueryAction.setInputValue("live", "false");
328:                        } else {
329:                            xqueryAction.setOutputPreparedStatementName(query
330:                                    .getQueryName());
331:                            // need to replace ${NAME} with {PREPARELATER:NAME}
332:                            String preparedSubquery = convertProperties(query
333:                                    .getQuery());
334:                            xqueryAction.setQuery(preparedSubquery);
335:                        }
336:                    } else if (dataSet.getConnectionType() == MultiDataSetReportElement.ConnectionType.MQL) {
337:                        //
338:                        // handle MQL
339:                        //
340:                        MQLAction mqlAction = new MQLAction();
341:                        actionSequenceDocument.add(mqlAction);
342:                        mqlAction.setOutputResultSetName("list");
343:                        if (query.getQueryName().equals("default")) {
344:                            mainActionOutput = mqlAction
345:                                    .getOutputResultSetParam();
346:                            String mqlquery = query.getQuery().replaceAll(
347:                                    "domain_id.*domain_id",
348:                                    "domain_id>" + publishSolutionPath
349:                                            + "</domain_id");
350:                            mqlAction.setQuery(mqlquery);
351:                        } else {
352:                            // out not supported!
353:                            // mqlAction.setOutputPreparedStatementName(query.getQueryName());
354:                            // need to replace ${NAME} with {PREPARELATER:NAME}
355:                            // String preparedSubquery = convertProperties(query.getQuery());
356:                            mqlAction.setQuery(query.getQuery());
357:                        }
358:                    }
359:                }
360:                finishProcessing(actionSequenceDocument, mainActionOutput,
361:                        queries);
362:                return actionSequenceDocument.toString();
363:            }
364:        }
w___w__w__.___ja__v__a2___s_.co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.