FlashChartHelper.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.pentaho.ui |
![]() |
![]() |
Pentaho |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Copyright 2006 Pentaho Corporation. All rights reserved.
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
* BI Platform. The Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*
* @created Apr 17, 2006
* @author James Dixon
*/
package org.pentaho.ui;
import java.io.File;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.pentaho.core.session.IPentahoSession;
import org.pentaho.core.solution.HttpRequestParameterProvider;
import org.pentaho.core.solution.IParameterProvider;
import org.pentaho.core.system.PentahoSystem;
import org.pentaho.core.ui.SimpleUrlFactory;
import org.pentaho.core.util.UIUtil;
import org.pentaho.messages.Messages;
import org.pentaho.ui.component.charting.FlashChartComponent;
import org.pentaho.util.logging.ILogger;
/**
* This class provides wrapper functions to make it easier to generate flash
* charts within a dashboard environment.
*/
public class FlashChartHelper {
/**
* doFlashChart generates a flash media player chart. It provides a simple
* wrapper around the com.pentaho.ui.charting.FlashChartComponent
*
* @param solutionName the solution name
* @param actionPath the action path
* @param chartName the xml file describing the chart
* @param parameterProvider the collection of parameters to customize the chart
* @param outputStream the output string buffer for the content
* @param userSession the user session object
* @param messages a collection to store error and logging messages
* @param logger logging object
*
* @return true if successful
*/
public static boolean doFlashChart(String solutionName, String actionPath, String chartName,
IParameterProvider parameterProvider, StringBuffer outputStream, IPentahoSession userSession, ArrayList messages,
ILogger logger) {
boolean result = true;
String outerParams = parameterProvider.getStringParameter("outer-params", null); //$NON-NLS-1$
String innerParam = parameterProvider.getStringParameter("inner-param", null); //$NON-NLS-1$
String urlDrillTemplate = parameterProvider.getStringParameter("drill-url", null); //$NON-NLS-1$
String imageUrl = parameterProvider.getStringParameter("image-url", null); //$NON-NLS-1$
if (imageUrl == null) {
imageUrl = PentahoSystem.getApplicationContext().getBaseUrl();
}
if (urlDrillTemplate == null) {
urlDrillTemplate = ""; //$NON-NLS-1$
}
int width = (int) parameterProvider.getLongParameter("image-width", 150); //$NON-NLS-1$
int height = (int) parameterProvider.getLongParameter("image-height", 150); //$NON-NLS-1$
int topX = (int) parameterProvider.getLongParameter("topX", -1); //$NON-NLS-1$
SimpleUrlFactory urlFactory = new SimpleUrlFactory(urlDrillTemplate);
FlashChartComponent chartComponent = null;
try {
String chartDefinitionStr = solutionName + File.separator + actionPath + File.separator + chartName;
chartComponent = new FlashChartComponent(chartDefinitionStr, width, height, urlFactory, messages);
if (logger != null) {
chartComponent.setLoggingLevel(logger.getLoggingLevel());
}
chartComponent.validate(userSession, null);
chartComponent.setUrlTemplate(urlDrillTemplate);
if (outerParams != null) {
StringTokenizer tokenizer = new StringTokenizer(outerParams, ";"); //$NON-NLS-1$
while (tokenizer.hasMoreTokens()) {
chartComponent.addOuterParamName(tokenizer.nextToken());
}
}
chartComponent.setParamName(innerParam);
chartComponent.setTopX(topX);
chartComponent.setDataAction(chartDefinitionStr);
chartComponent.setParameterProvider(HttpRequestParameterProvider.SCOPE_REQUEST, parameterProvider);
String content = chartComponent.getContent("text/html"); //$NON-NLS-1$
if (content == null || content.equals("")) { //$NON-NLS-1$
content = " "; //$NON-NLS-1$
}
if (content == null) {
StringBuffer buffer = new StringBuffer();
UIUtil.formatErrorMessage(
"text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
content = buffer.toString();
result = false;
}
outputStream.append(content);
} finally {
if (chartComponent != null)
chartComponent.dispose();
}
return result;
}
/**
* doFlashDial generates a flash media player dial. It provides a simple
* wrapper around the com.pentaho.ui.charting.FlashChartComponent
*
* @param solutionName the solution name
* @param actionPath the action path
* @param chartName the xml file describing the chart
* @param parameterProvider the collection of parameters to customize the chart
* @param outputStream the output string buffer for the content
* @param userSession the user session object
* @param messages a collection to store error and logging messages
* @param logger logging object
*
* @return true if successful
*/
public static boolean doFlashDial(String solutionName, String actionPath, String actionName,
IParameterProvider parameterProvider, StringBuffer outputStream, IPentahoSession userSession, ArrayList messages,
ILogger logger) {
boolean result = true;
String urlDrillTemplate = parameterProvider.getStringParameter("drill-url", null); //$NON-NLS-1$
String imageUrl = parameterProvider.getStringParameter("image-url", null); //$NON-NLS-1$
if (imageUrl == null) {
imageUrl = PentahoSystem.getApplicationContext().getBaseUrl();
}
if (urlDrillTemplate == null) {
urlDrillTemplate = ""; //$NON-NLS-1$
}
int width = (int) parameterProvider.getLongParameter("image-width", 150); //$NON-NLS-1$
int height = (int) parameterProvider.getLongParameter("image-height", 150); //$NON-NLS-1$
int topX = (int) parameterProvider.getLongParameter("topX", -1); //$NON-NLS-1$
SimpleUrlFactory urlFactory = new SimpleUrlFactory(urlDrillTemplate);
FlashChartComponent chartComponent = null;
try {
String chartDefinitionStr = solutionName + File.separator + actionPath + File.separator + actionName;
chartComponent = new FlashChartComponent(chartDefinitionStr, width, height, urlFactory, messages);
if (logger != null) {
chartComponent.setLoggingLevel(logger.getLoggingLevel());
}
chartComponent.validate(userSession, null);
chartComponent.setUrlTemplate(urlDrillTemplate);
chartComponent.setTopX(topX);
chartComponent.setDataAction(chartDefinitionStr);
chartComponent.setParameterProvider(HttpRequestParameterProvider.SCOPE_REQUEST, parameterProvider);
String content = chartComponent.getDialContent("text/html"); //$NON-NLS-1$
if (content == null || content.equals("")) { //$NON-NLS-1$
content = " "; //$NON-NLS-1$
}
if (content == null) {
StringBuffer buffer = new StringBuffer();
UIUtil.formatErrorMessage(
"text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
content = buffer.toString();
result = false;
}
outputStream.append(content);
} finally {
if (chartComponent != null)
chartComponent.dispose();
}
return result;
}
}
The table below shows all metrics for FlashChartHelper.java.




