Source Code Cross Referenced for ChartHelper.java in  » Report » pentaho-report » org » pentaho » ui » 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.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 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. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Apr 17, 2006 
014:         * @author James Dixon
015:         */
016:
017:        package org.pentaho.ui;
018:
019:        import java.io.File;
020:        import java.io.OutputStream;
021:        import java.util.ArrayList;
022:        import java.util.StringTokenizer;
023:
024:        import org.dom4j.Document;
025:        import org.dom4j.Node;
026:        import org.pentaho.commons.connection.IPentahoConnection;
027:        import org.pentaho.commons.connection.IPentahoResultSet;
028:        import org.pentaho.core.runtime.IRuntimeContext;
029:        import org.pentaho.core.services.BaseRequestHandler;
030:        import org.pentaho.core.session.IPentahoSession;
031:        import org.pentaho.core.solution.ActionResource;
032:        import org.pentaho.core.solution.HttpRequestParameterProvider;
033:        import org.pentaho.core.solution.IActionResource;
034:        import org.pentaho.core.solution.IParameterProvider;
035:        import org.pentaho.core.solution.SimpleOutputHandler;
036:        import org.pentaho.core.system.PentahoSystem;
037:        import org.pentaho.core.ui.SimpleUrlFactory;
038:        import org.pentaho.core.util.TemplateUtil;
039:        import org.pentaho.core.util.UIUtil;
040:        import org.pentaho.data.connection.sql.SQLConnection;
041:        import org.pentaho.messages.Messages;
042:        import org.pentaho.plugin.jfreechart.ChartDefinition;
043:        import org.pentaho.plugin.jfreechart.JFreeChartEngine;
044:        import org.pentaho.ui.component.DashboardWidgetComponent;
045:        import org.pentaho.ui.component.charting.AbstractChartComponent;
046:        import org.pentaho.ui.component.charting.AbstractJFreeChartComponent;
047:        import org.pentaho.ui.component.charting.CategoryDatasetChartComponent;
048:        import org.pentaho.ui.component.charting.DialChartComponent;
049:        import org.pentaho.ui.component.charting.PieDatasetChartComponent;
050:        import org.pentaho.ui.component.charting.TimeSeriesCollectionChartComponent;
051:        import org.pentaho.ui.component.charting.XYSeriesCollectionChartComponent;
052:        import org.pentaho.ui.component.charting.XYZSeriesCollectionChartComponent;
053:        import org.pentaho.util.logging.ILogger;
054:
055:        /**
056:         * This class provides wrapper functions to make it easier to execute action
057:         * sequences and generate a widget. 
058:         */
059:        public class ChartHelper {
060:
061:            /**
062:             * doChart generates the images and html necessary to render various charts within a web page.
063:             * 
064:             * @param solutionName the solution name
065:             * @param actionPath the action path
066:             * @param chartName the xml file describing the chart
067:             * @param parameterProvider the collection of parameters to customize the chart
068:             * @param outputStream the output string buffer for the content
069:             * @param userSession the user session object
070:             * @param messages a collection to store error and logging messages
071:             * @param logger logging object
072:             * 
073:             * @return true if successful
074:             */
075:            public static boolean doChart(String solutionName,
076:                    String actionPath, String chartName,
077:                    IParameterProvider parameterProvider,
078:                    StringBuffer outputStream, IPentahoSession userSession,
079:                    ArrayList messages, ILogger logger) {
080:
081:                boolean result = true;
082:                String content = null;
083:                StringBuffer messageBuffer = new StringBuffer();
084:
085:                if (logger == null) {
086:                    // No logger? The usersession extends ILogger, use it for logging
087:                    logger = userSession;
088:                }
089:
090:                // Retrieve all parameters from parameter provider
091:
092:                String outerParams = parameterProvider.getStringParameter(
093:                        "outer-params", null); //$NON-NLS-1$
094:                String innerParam = parameterProvider.getStringParameter(
095:                        "inner-param", null); //$NON-NLS-1$
096:
097:                String urlDrillTemplate = parameterProvider.getStringParameter(
098:                        "drill-url", null); //$NON-NLS-1$
099:                String imageUrl = parameterProvider.getStringParameter(
100:                        "image-url", null); //$NON-NLS-1$
101:
102:                // Very likely null; allow API users to continue to pass the dial value via parameters 
103:                String dialValue = parameterProvider.getStringParameter(
104:                        "value", null); //$NON-NLS-1$
105:
106:                if (imageUrl == null) {
107:                    imageUrl = PentahoSystem.getApplicationContext()
108:                            .getBaseUrl();
109:                }
110:
111:                if (urlDrillTemplate == null) {
112:                    urlDrillTemplate = ""; //$NON-NLS-1$
113:                }
114:
115:                int width = (int) parameterProvider.getLongParameter(
116:                        "image-width", 150); //$NON-NLS-1$
117:                int height = (int) parameterProvider.getLongParameter(
118:                        "image-height", 150); //$NON-NLS-1$
119:
120:                SimpleUrlFactory urlFactory = new SimpleUrlFactory(
121:                        urlDrillTemplate);
122:
123:                // Determine the type of chart we are building; these values can come from the chart xml definition, or 
124:                // from the parameter provider. Try the parameter provider first, for performance reasons. 
125:
126:                String chartTypeStr = parameterProvider.getStringParameter(
127:                        ChartDefinition.TYPE_NODE_NAME, null);
128:                String datasetType = ChartDefinition.CATAGORY_DATASET_STR;
129:                String definitionPath = solutionName + File.separator
130:                        + actionPath + File.separator + chartName;
131:
132:                if ((chartTypeStr == null) || (chartTypeStr.length() == 0)) {
133:
134:                    // load the XML document that defines the chart
135:                    ActionResource resource = new ActionResource(chartName,
136:                            IActionResource.SOLUTION_FILE_RESOURCE, "text/xml", //$NON-NLS-1$
137:                            definitionPath);
138:
139:                    try {
140:                        // attempt to get the chart type and possibly data type from the xml doc
141:                        Document chartDefinition = AbstractJFreeChartComponent
142:                                .getResourceAsDocument(userSession, resource);
143:                        Node chartAttributes = chartDefinition
144:                                .selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME); //$NON-NLS-1$
145:                        chartTypeStr = chartAttributes.selectSingleNode(
146:                                ChartDefinition.TYPE_NODE_NAME).getText();
147:                        Node datasetTypeNode = chartAttributes
148:                                .selectSingleNode(ChartDefinition.DATASET_TYPE_NODE_NAME);
149:                        if (datasetTypeNode != null) {
150:                            datasetType = datasetTypeNode.getText();
151:                        }
152:
153:                    } catch (Exception e) {
154:
155:                        logger
156:                                .error(
157:                                        Messages
158:                                                .getErrorString("ChartHelper.ERROR_0001_IO_PROBLEM_GETTING_CHART_TYPE"), e); //$NON-NLS-1$
159:                        UIUtil
160:                                .formatErrorMessage(
161:                                        "text/html", Messages.getString("ChartHelper.ERROR_0001_IO_PROBLEM_GETTING_CHART_TYPE"), messages, messageBuffer); //$NON-NLS-1$ //$NON-NLS-2$
162:                        content = messageBuffer.toString();
163:                        result = false;
164:                    }
165:                }
166:
167:                // Check again - do we have a chart type now? If not, bail out, we have no idea what to try to generate
168:                if ((chartTypeStr == null) || (chartTypeStr.length() == 0)) {
169:
170:                    logger
171:                            .error(Messages
172:                                    .getString("ChartHelper.ERROR_0002_COULD_NOT_DETERMINE_CHART_TYPE")); //$NON-NLS-1$
173:                    UIUtil
174:                            .formatErrorMessage(
175:                                    "text/html", Messages.getString("ChartHelper.ERROR_0002_COULD_NOT_DETERMINE_CHART_TYPE"), messages, messageBuffer); //$NON-NLS-1$ //$NON-NLS-2$
176:                    content = messageBuffer.toString();
177:                    result = false;
178:                }
179:
180:                if (!result) {
181:                    outputStream.append(content);
182:                    return result;
183:                }
184:
185:                int chartType = JFreeChartEngine.getChartType(chartTypeStr);
186:                AbstractJFreeChartComponent chartComponent = null;
187:
188:                try {
189:                    // Some charts are determined by the dataset that is passed in; check these first...
190:                    if (datasetType
191:                            .equalsIgnoreCase(ChartDefinition.TIME_SERIES_COLLECTION_STR)) {
192:                        chartComponent = new TimeSeriesCollectionChartComponent(
193:                                chartType, definitionPath, width, height,
194:                                urlFactory, messages);
195:                    } else if (datasetType
196:                            .equalsIgnoreCase(ChartDefinition.XY_SERIES_COLLECTION_STR)) {
197:                        chartComponent = new XYSeriesCollectionChartComponent(
198:                                chartType, definitionPath, width, height,
199:                                urlFactory, messages);
200:                    } else if (datasetType
201:                            .equalsIgnoreCase(ChartDefinition.XYZ_SERIES_COLLECTION_STR)) {
202:                        chartComponent = new XYZSeriesCollectionChartComponent(
203:                                chartType, definitionPath, width, height,
204:                                urlFactory, messages);
205:                    }
206:
207:                    // Didn't find a dataset, so try to create the component based on chart type. 
208:                    if (chartComponent == null) {
209:                        switch (chartType) {
210:                        case JFreeChartEngine.BAR_CHART_TYPE:
211:                        case JFreeChartEngine.AREA_CHART_TYPE:
212:                        case JFreeChartEngine.BAR_LINE_CHART_TYPE:
213:                        case JFreeChartEngine.LINE_CHART_TYPE:
214:                        case JFreeChartEngine.DIFFERENCE_CHART_TYPE:
215:                        case JFreeChartEngine.DOT_CHART_TYPE:
216:                        case JFreeChartEngine.STEP_AREA_CHART_TYPE:
217:                        case JFreeChartEngine.STEP_CHART_TYPE:
218:                        case JFreeChartEngine.PIE_GRID_CHART_TYPE:
219:
220:                            chartComponent = new CategoryDatasetChartComponent(
221:                                    chartType, definitionPath, width, height,
222:                                    urlFactory, messages);
223:                            break;
224:
225:                        case JFreeChartEngine.PIE_CHART_TYPE:
226:
227:                            chartComponent = new PieDatasetChartComponent(
228:                                    chartType, definitionPath, width, height,
229:                                    urlFactory, messages);
230:                            break;
231:
232:                        case JFreeChartEngine.DIAL_CHART_TYPE:
233:
234:                            chartComponent = new DialChartComponent(chartType,
235:                                    definitionPath, width, height, urlFactory,
236:                                    messages);
237:                            if (dialValue != null) {
238:                                ((DialChartComponent) chartComponent)
239:                                        .setValue(Double.parseDouble(dialValue));
240:                            }
241:                            break;
242:
243:                        case JFreeChartEngine.BUBBLE_CHART_TYPE:
244:
245:                            chartComponent = new XYZSeriesCollectionChartComponent(
246:                                    chartType, definitionPath, width, height,
247:                                    urlFactory, messages);
248:                            break;
249:
250:                        case JFreeChartEngine.UNDEFINED_CHART_TYPE:
251:                        default:
252:                            // Unsupported chart type, bail out
253:                            logger
254:                                    .error(Messages
255:                                            .getString(
256:                                                    "ChartHelper.ERROR_0003_INVALID_CHART_TYPE", chartTypeStr, Integer.toString(chartType))); //$NON-NLS-1$
257:                            UIUtil
258:                                    .formatErrorMessage(
259:                                            "text/html", Messages.getString("ChartHelper.ERROR_0003_INVALID_CHART_TYPE", //$NON-NLS-1$ //$NON-NLS-2$
260:                                                            chartTypeStr,
261:                                                            Integer
262:                                                                    .toString(chartType)),
263:                                            messages, messageBuffer);
264:                            content = messageBuffer.toString();
265:                            result = false;
266:
267:                        }
268:                    }
269:
270:                    if (result && (chartComponent != null)) {
271:                        try {
272:
273:                            chartComponent.setLoggingLevel(logger
274:                                    .getLoggingLevel());
275:                            chartComponent.validate(userSession, null);
276:                            chartComponent.setDataAction(definitionPath);
277:                            chartComponent.setUrlTemplate(urlDrillTemplate);
278:
279:                            String seriesName = parameterProvider
280:                                    .getStringParameter("series-name", null); //$NON-NLS-1$
281:                            if (chartComponent instanceof  CategoryDatasetChartComponent) {
282:                                ((CategoryDatasetChartComponent) chartComponent)
283:                                        .setSeriesName(seriesName);
284:                            }
285:
286:                            // WARNING!!! This is an atypical way to access data for the chart... these parameters and their
287:                            // usage are undocumented, and only left in here to support older solutions that may be using them.
288:                            // *************** START QUESTIONABLE CODE ********************************************************
289:
290:                            String connectionName = parameterProvider
291:                                    .getStringParameter("connection", null); //$NON-NLS-1$
292:                            String query = parameterProvider
293:                                    .getStringParameter("query", null); //$NON-NLS-1$
294:                            String dataAction = parameterProvider
295:                                    .getStringParameter("data-process", null); //$NON-NLS-1$
296:
297:                            IPentahoConnection connection = null;
298:                            try {
299:                                chartComponent.setParamName(innerParam);
300:                                chartComponent
301:                                        .setParameterProvider(
302:                                                HttpRequestParameterProvider.SCOPE_REQUEST,
303:                                                parameterProvider);
304:                                if (connectionName != null && query != null) {
305:                                    connection = new SQLConnection(
306:                                            connectionName, logger);
307:
308:                                    try {
309:                                        query = TemplateUtil
310:                                                .applyTemplate(
311:                                                        query,
312:                                                        TemplateUtil
313:                                                                .parametersToProperties(parameterProvider),
314:                                                        null);
315:                                        IPentahoResultSet results = connection
316:                                                .executeQuery(query);
317:                                        chartComponent.setValues(results);
318:                                    } finally {
319:                                    }
320:
321:                                    chartComponent
322:                                            .setUrlTemplate(urlDrillTemplate);
323:                                    if (outerParams != null) {
324:                                        StringTokenizer tokenizer = new StringTokenizer(
325:                                                outerParams, ";"); //$NON-NLS-1$
326:                                        while (tokenizer.hasMoreTokens()) {
327:                                            chartComponent
328:                                                    .addOuterParamName(tokenizer
329:                                                            .nextToken());
330:                                        }
331:                                    }
332:                                } else if (dataAction != null) {
333:                                    PentahoSystem.ActionInfo actionInfo = PentahoSystem
334:                                            .parseActionString(dataAction);
335:                                    if (actionInfo != null) {
336:                                        chartComponent
337:                                                .setDataAction(
338:                                                        actionInfo
339:                                                                .getSolutionName(),
340:                                                        actionInfo.getPath(),
341:                                                        actionInfo
342:                                                                .getActionName(),
343:                                                        "rule-result"); //$NON-NLS-1$
344:                                    }
345:                                }
346:                                // ***************** END QUESTIONABLE CODE ********************************************************
347:
348:                                content = chartComponent
349:                                        .getContent("text/html"); //$NON-NLS-1$
350:
351:                            } finally {
352:                                if (connection != null) {
353:                                    connection.close();
354:                                }
355:                            }
356:
357:                        } catch (Throwable e) {
358:                            logger
359:                                    .error(
360:                                            Messages
361:                                                    .getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), e); //$NON-NLS-1$
362:                        }
363:                    } // end of if(result)
364:
365:                    try {
366:                        if (content == null) {
367:                            UIUtil
368:                                    .formatErrorMessage(
369:                                            "text/html", Messages.getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, messageBuffer); //$NON-NLS-1$ //$NON-NLS-2$
370:                            content = messageBuffer.toString();
371:                            result = false;
372:                        }
373:                        outputStream.append(content);
374:                    } catch (Exception e) {
375:                        logger
376:                                .error(
377:                                        Messages
378:                                                .getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), e); //$NON-NLS-1$
379:                    }
380:
381:                } finally {
382:                    if (chartComponent != null)
383:                        chartComponent.dispose();
384:                }
385:                return result;
386:            }
387:
388:            /**
389:             * doPieChart generates the images and html necessary to render pie charts.
390:             * It provides a simple wrapper around the class 
391:             * org.pentaho.ui.component.charting.PieDatasetChartComponent
392:             * 
393:             * @param solutionName the solution name
394:             * @param actionPath the action path
395:             * @param chartName the xml file describing the chart
396:             * @param parameterProvider the collection of parameters to customize the chart
397:             * @param outputStream the output string buffer for the content
398:             * @param userSession the user session object
399:             * @param messages a collection to store error and logging messages
400:             * @param logger logging object
401:             * 
402:             * @return true if successful
403:             * @deprecated use doChart instead
404:             */
405:            public static boolean doPieChart(String solutionName,
406:                    String actionPath, String chartName,
407:                    IParameterProvider parameterProvider,
408:                    StringBuffer outputStream, IPentahoSession userSession,
409:                    ArrayList messages, ILogger logger) {
410:
411:                boolean result = true;
412:                String outerParams = parameterProvider.getStringParameter(
413:                        "outer-params", null); //$NON-NLS-1$
414:                String innerParam = parameterProvider.getStringParameter(
415:                        "inner-param", null); //$NON-NLS-1$
416:
417:                String urlDrillTemplate = parameterProvider.getStringParameter(
418:                        "drill-url", null); //$NON-NLS-1$
419:                String imageUrl = parameterProvider.getStringParameter(
420:                        "image-url", null); //$NON-NLS-1$
421:                if (imageUrl == null) {
422:                    imageUrl = PentahoSystem.getApplicationContext()
423:                            .getBaseUrl();
424:                }
425:
426:                if (urlDrillTemplate == null) {
427:                    urlDrillTemplate = ""; //$NON-NLS-1$
428:                }
429:
430:                int width = (int) parameterProvider.getLongParameter(
431:                        "image-width", 150); //$NON-NLS-1$
432:                int height = (int) parameterProvider.getLongParameter(
433:                        "image-height", 150); //$NON-NLS-1$
434:
435:                SimpleUrlFactory urlFactory = new SimpleUrlFactory(
436:                        urlDrillTemplate);
437:
438:                PieDatasetChartComponent chartComponent = null;
439:                try {
440:                    String chartDefinitionStr = solutionName + File.separator
441:                            + actionPath + File.separator + chartName;
442:                    chartComponent = new PieDatasetChartComponent(
443:                            JFreeChartEngine.PIE_CHART_TYPE,
444:                            chartDefinitionStr, width, height, urlFactory,
445:                            messages);
446:                    if (logger != null) {
447:                        chartComponent
448:                                .setLoggingLevel(logger.getLoggingLevel());
449:                    }
450:                    chartComponent.validate(userSession, null);
451:                    chartComponent.setUrlTemplate(urlDrillTemplate);
452:                    if (outerParams != null) {
453:                        StringTokenizer tokenizer = new StringTokenizer(
454:                                outerParams, ";"); //$NON-NLS-1$
455:                        while (tokenizer.hasMoreTokens()) {
456:                            chartComponent.addOuterParamName(tokenizer
457:                                    .nextToken());
458:                        }
459:                    }
460:                    chartComponent.setParamName(innerParam);
461:
462:                    chartComponent.setDataAction(chartDefinitionStr);
463:
464:                    chartComponent.setParameterProvider(
465:                            HttpRequestParameterProvider.SCOPE_REQUEST,
466:                            parameterProvider);
467:
468:                    String content = chartComponent.getContent("text/html"); //$NON-NLS-1$
469:
470:                    if (content == null || content.equals("")) { //$NON-NLS-1$
471:                        content = " "; //$NON-NLS-1$
472:                    }
473:                    if (content == null) {
474:                        StringBuffer buffer = new StringBuffer();
475:                        UIUtil
476:                                .formatErrorMessage(
477:                                        "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
478:                        content = buffer.toString();
479:                        result = false;
480:                    }
481:
482:                    outputStream.append(content);
483:
484:                } finally {
485:                    if (chartComponent != null)
486:                        chartComponent.dispose();
487:                }
488:                return result;
489:
490:            }
491:
492:            /**
493:             * doDial generates the images and html necessary to render dials.  It 
494:             * provides a simple wrapper around the class 
495:             * org.pentaho.ui.component.DashboardWidgetComponent
496:             * 
497:             * @param solutionName the solution name
498:             * @param actionPath the action path
499:             * @param chartName the xml file describing the chart
500:             * @param parameterProvider the collection of parameters to customize the chart
501:             * @param outputStream the output string buffer for the content
502:             * @param userSession the user session object
503:             * @param messages a collection to store error and logging messages
504:             * @param logger logging object
505:             * 
506:             * @return true if successful
507:             * @deprecated use doChart() instead
508:             */
509:            public static boolean doDial(String solutionName,
510:                    String actionPath, String chartName,
511:                    IParameterProvider parameterProvider,
512:                    StringBuffer outputStream, IPentahoSession userSession,
513:                    ArrayList messages, ILogger logger) {
514:
515:                boolean result = true;
516:                String linkUrl = parameterProvider.getStringParameter(
517:                        "drill-url", null); //$NON-NLS-1$
518:                String imageUrl = parameterProvider.getStringParameter(
519:                        "image-url", null); //$NON-NLS-1$
520:                if (imageUrl == null) {
521:                    imageUrl = PentahoSystem.getApplicationContext()
522:                            .getBaseUrl();
523:                }
524:
525:                if (linkUrl == null) {
526:                    linkUrl = ""; //$NON-NLS-1$
527:                }
528:
529:                int width = (int) parameterProvider.getLongParameter(
530:                        "image-width", 150); //$NON-NLS-1$
531:                int height = (int) parameterProvider.getLongParameter(
532:                        "image-height", 150); //$NON-NLS-1$
533:
534:                SimpleUrlFactory urlFactory = new SimpleUrlFactory(linkUrl);
535:
536:                DashboardWidgetComponent widget = null;
537:                try {
538:                    widget = new DashboardWidgetComponent(
539:                            DashboardWidgetComponent.TYPE_DIAL, solutionName
540:                                    + File.separator + actionPath
541:                                    + File.separator + chartName, width,
542:                            height, urlFactory, messages);
543:                    if (logger != null) {
544:                        widget.setLoggingLevel(logger.getLoggingLevel());
545:                    }
546:                    widget.validate(userSession, null);
547:
548:                    widget.setParameterProvider(
549:                            HttpRequestParameterProvider.SCOPE_REQUEST,
550:                            parameterProvider);
551:
552:                    double value = Double.parseDouble(parameterProvider
553:                            .getStringParameter("value", "0")); //$NON-NLS-1$ //$NON-NLS-2$
554:                    widget.setValue(value);
555:
556:                    String title = parameterProvider.getStringParameter(
557:                            "title", ""); //$NON-NLS-1$ //$NON-NLS-2$
558:                    widget.setTitle(title);
559:
560:                    String content = widget.getContent("text/html"); //$NON-NLS-1$
561:
562:                    if (content == null) {
563:                        StringBuffer buffer = new StringBuffer();
564:                        UIUtil
565:                                .formatErrorMessage(
566:                                        "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
567:                        content = buffer.toString();
568:                        result = false;
569:                    }
570:
571:                    if (content == null || content.equals("")) { //$NON-NLS-1$
572:                        content = " "; //$NON-NLS-1$
573:                    }
574:                    outputStream.append(content);
575:
576:                } finally {
577:                    if (widget != null)
578:                        widget.dispose();
579:                }
580:                return result;
581:
582:            }
583:
584:            /**
585:             * doAction executes an action within the bi platform and returns true if successful. 
586:             *     
587:             * @param solutionName the solution name
588:             * @param actionPath the action path
589:             * @param actionName the action name
590:             * @param processId the process id
591:             * @param parameterProvider the collection of parameters to customize the chart
592:             * @param userSession the user session object
593:             * @param messages a collection to store error and logging messages
594:             * @param logger logging object
595:             * 
596:             * @return the runtime context
597:             */
598:            public static boolean doAction(String solutionName,
599:                    String actionPath, String actionName, String processId,
600:                    IParameterProvider parameterProvider,
601:                    OutputStream outputStream, IPentahoSession userSession,
602:                    ArrayList messages, ILogger logger) {
603:
604:                SimpleOutputHandler outputHandler = new SimpleOutputHandler(
605:                        outputStream, false);
606:                BaseRequestHandler requestHandler = new BaseRequestHandler(
607:                        userSession, null, outputHandler, parameterProvider,
608:                        null);
609:
610:                requestHandler.setProcessId(processId);
611:                requestHandler.setAction(actionPath, actionName);
612:                requestHandler.setSolutionName(solutionName);
613:
614:                IRuntimeContext runtime = null;
615:                int status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
616:                try {
617:                    runtime = requestHandler.handleActionRequest(0, 0);
618:                    if (runtime != null) {
619:                        status = runtime.getStatus();
620:                    }
621:                } finally {
622:                    if (runtime != null) {
623:                        runtime.dispose();
624:                    }
625:                }
626:                return status == IRuntimeContext.RUNTIME_STATUS_SUCCESS;
627:            }
628:
629:            /**
630:             * doAction executes an action within the bi platform and returns the runtime context.
631:             * 
632:             * @param solutionName the solution name
633:             * @param actionPath the action path
634:             * @param actionName the action name
635:             * @param processId the process id
636:             * @param parameterProvider the collection of parameters to customize the chart
637:             * @param userSession the user session object
638:             * @param messages a collection to store error and logging messages
639:             * @param logger logging object
640:             * 
641:             * @return the runtime context
642:             */
643:            public static IRuntimeContext doAction(String solutionName,
644:                    String actionPath, String actionName, String processId,
645:                    IParameterProvider parameterProvider,
646:                    IPentahoSession userSession, ArrayList messages,
647:                    ILogger logger) {
648:
649:                SimpleOutputHandler outputHandler = new SimpleOutputHandler(
650:                        (OutputStream) null, false);
651:                BaseRequestHandler requestHandler = new BaseRequestHandler(
652:                        userSession, null, outputHandler, parameterProvider,
653:                        null);
654:
655:                requestHandler.setProcessId(processId);
656:                requestHandler.setAction(actionPath, actionName);
657:                requestHandler.setSolutionName(solutionName);
658:
659:                IRuntimeContext runtime = null;
660:                try {
661:                    runtime = requestHandler.handleActionRequest(0, 0);
662:                } catch (Throwable t) {
663:                }
664:                return runtime;
665:            }
666:
667:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.