<%@ page language="java" import="java.util.ArrayList, org.pentaho.core.ui.SimpleUrlFactory, org.pentaho.messages.Messages, org.pentaho.core.system.PentahoSystem, org.pentaho.ui.component.charting.CategoryDatasetChartComponent, org.pentaho.plugin.jfreechart.JFreeChartEngine, org.pentaho.core.solution.HttpRequestParameterProvider, org.pentaho.core.solution.HttpSessionParameterProvider, org.pentaho.core.session.IPentahoSession, org.pentaho.core.util.UIUtil, org.pentaho.core.util.IUITemplater, org.pentaho.messages.util.LocaleHelper, org.pentaho.commons.connection.IPentahoConnection, org.pentaho.commons.connection.IPentahoResultSet, org.pentaho.data.PentahoConnectionFactory, org.pentaho.core.system.PentahoSystem, org.pentaho.core.system.PathBasedSystemSettings, org.pentaho.core.system.IApplicationContext, org.pentaho.core.system.WebApplicationContext, java.util.Enumeration,java.util.Properties, org.pentaho.core.system.StandaloneApplicationContext, org.apache.commons.lang.StringUtils" %><% /* * 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. */ response.setCharacterEncoding(LocaleHelper.getSystemEncoding()); String solutionPath="D:/EnterprisePT/JbossServices/server/default/deploy/HRPEAP.ear/hrAppWeb.war/DASHBOARD/"; String baseUrl ="http://localhost:8080/hr/DASHBOARD/"; ServletContext context = pageContext.getServletContext(); IApplicationContext applicationContext = new WebApplicationContext(solutionPath, baseUrl, context.getRealPath(""), context); try{ Properties props = new Properties(); Enumeration initParmNames = context.getInitParameterNames(); String initParmName; while (initParmNames.hasMoreElements()) { initParmName = (String) initParmNames.nextElement(); props.setProperty(initParmName, context.getInitParameter(initParmName)); } // ((WebApplicationContext) applicationContext).setProperties(props); WebApplicationContext wb=(WebApplicationContext)applicationContext; wb.setProperties(props); String jvmSpecifiedSysCfgPath = System.getProperty(PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY); if (StringUtils.isBlank(jvmSpecifiedSysCfgPath)) { String webSpecifiedSysCfgPath = context.getInitParameter("pentaho-system-cfg"); //$NON-NLS-1$ if (StringUtils.isNotBlank(webSpecifiedSysCfgPath)) { System.setProperty(PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY, webSpecifiedSysCfgPath); } } boolean initOk = PentahoSystem.init(applicationContext); }catch(Exception ex){ } IPentahoSession userSession = UIUtil.getPentahoSession( request ); HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider( request ); HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider( userSession ); int chartType = (int)requestParameters.getLongParameter("ChartType", JFreeChartEngine.UNDEFINED_CHART_TYPE); //$NON-NLS-1$ String chartDefinitionPath = requestParameters.getStringParameter("ChartDefinitionPath", null); //$NON-NLS-1$ String thisUrl = baseUrl + "Chart?"; //$NON-NLS-1$ String intro = ""; //$NON-NLS-1$ String footer = ""; //$NON-NLS-1$ String content = ""; //$NON-NLS-1$ SimpleUrlFactory urlFactory = new SimpleUrlFactory( thisUrl ); ArrayList messages = new ArrayList(); CategoryDatasetChartComponent barChart = new CategoryDatasetChartComponent( chartType, chartDefinitionPath, 600, 400, urlFactory, messages ); IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, "SampleData", null); //$NON-NLS-1$ try { String query = "select department, actual, budget, variance from QUADRANT_ACTUALS"; //$NON-NLS-1$ IPentahoResultSet results = connection.executeQuery(query); try { barChart.setValues(results); barChart.validate( userSession, null ); barChart.setParameterProvider( HttpRequestParameterProvider.SCOPE_REQUEST, requestParameters ); //$NON-NLS-1$ barChart.setParameterProvider( HttpSessionParameterProvider.SCOPE_SESSION, sessionParameters ); //$NON-NLS-1$ content = barChart.getContent( "text/html" ); //$NON-NLS-1$ if( content == null ) { StringBuffer buffer = new StringBuffer(); UIUtil.formatErrorMessage( "text/html", Messages.getErrorString( "CHART.DISPLAY_ERROR" ), messages, buffer ); //$NON-NLS-1$ //$NON-NLS-2$ content = buffer.toString(); } IUITemplater templater = PentahoSystem.getUITemplater( userSession ); if( templater != null ) { String sections[] = templater.breakTemplate( "template-document.html", Messages.getString( "CHART.USER_SAMPLES" ), userSession ); //$NON-NLS-1$ //$NON-NLS-2$ if( sections != null && sections.length > 0 ) { intro = sections[0]; } if( sections != null && sections.length > 1 ) { footer = sections[1]; } } else { intro = Messages.getString( "UI.ERROR_0002_BAD_TEMPLATE_OBJECT" ); //$NON-NLS-1$ } } finally { results.close(); } } finally { connection.close(); } %><%//= intro %> <%//= content %> <%//= footer %>