KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > portlet > charting > TimeSeriesCollectionChartPortlet


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12 */

13 /*
14  * Copyright 2006 Pentaho Corporation. All rights reserved.
15  * This software was developed by Pentaho Corporation and is provided under the terms
16  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
17  * this file except in compliance with the license. If you need a copy of the license,
18  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
19  * BI Platform. The Initial Developer is Pentaho Corporation.
20  *
21  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
22  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
23  * the license for the specific language governing your rights and limitations.
24  *
25  * @created Jun 27, 2006
26  * @author Ron Troyer
27  */

28
29 package org.pentaho.ui.portlet.charting;
30
31 import java.io.IOException JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34 import javax.portlet.ActionRequest;
35 import javax.portlet.ActionResponse;
36 import javax.portlet.PortletException;
37 import javax.portlet.RenderRequest;
38 import javax.portlet.RenderResponse;
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import org.pentaho.messages.Messages;
42 import org.pentaho.core.util.UIUtil;
43 import org.pentaho.ui.component.charting.TimeSeriesCollectionChartComponent;
44 import org.pentaho.ui.portlet.PentahoPortletSession;
45 import org.pentaho.ui.portlet.PortletRequestParameterProvider;
46 import org.pentaho.ui.portlet.PortletSessionParameterProvider;
47 import org.pentaho.ui.portlet.PortletUrlFactory;
48 import org.pentaho.ui.portlet.ViewPortlet;
49
50 public class TimeSeriesCollectionChartPortlet extends ViewPortlet {
51
52     private static final String JavaDoc CHART = "chart"; //$NON-NLS-1$
53

54     private static final Log portletLogger = LogFactory.getLog(XYSeriesCollectionChartPortlet.class);
55
56     public Log getLogger() {
57         return portletLogger;
58     }
59
60     public void processPortletAction(ActionRequest request, ActionResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
61
62     }
63
64     public void doPortletView(RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
65         response.setContentType("text/html"); //$NON-NLS-1$
66

67         PortletUrlFactory urlFactory = new PortletUrlFactory(response, request.getWindowState(), request.getPortletMode());
68
69         PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(request);
70         PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(userSession);
71
72         String JavaDoc chartDefinitionStr = getSetting(CHART, null, request, requestParameters);
73
74         if (chartDefinitionStr == null) {
75             response.getWriter().print(Messages.getString("TimeSeriesCollectionChartPortlet.ERROR_0001.NO_CHART_DEF")); //$NON-NLS-1$
76
return;
77         }
78
79         ArrayList JavaDoc messages = new ArrayList JavaDoc();
80         TimeSeriesCollectionChartComponent chartComponent = null;
81         String JavaDoc urlDrillTemplate = getSetting("drill-url", null, request, null); //$NON-NLS-1$
82
String JavaDoc outerParams = getSetting("outer-params", null, request, null); //$NON-NLS-1$
83
String JavaDoc innerParam = getSetting("inner-param", null, request, null); //$NON-NLS-1$
84

85         try {
86             chartComponent = new TimeSeriesCollectionChartComponent(chartDefinitionStr, urlFactory, messages);
87             chartComponent.validate(userSession, null);
88             chartComponent.setUrlTemplate(urlDrillTemplate);
89             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(outerParams, ";"); //$NON-NLS-1$
90
while (tokenizer.hasMoreTokens()) {
91                 chartComponent.addOuterParamName(tokenizer.nextToken());
92             }
93             chartComponent.setParamName(innerParam);
94
95             chartComponent.setDataAction(chartDefinitionStr);
96
97             chartComponent.setParameterProvider("request", requestParameters); //$NON-NLS-1$
98
chartComponent.setParameterProvider("session", sessionParameters); //$NON-NLS-1$
99

100             String JavaDoc content = chartComponent.getContent("text/html"); //$NON-NLS-1$
101

102             if (content == null || content.equals("")) { //$NON-NLS-1$
103
content = " "; //$NON-NLS-1$
104
}
105             response.getWriter().print(content);
106
107             if (content == null) {
108                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
109                 UIUtil.formatErrorMessage("text/html", Messages.getString("TimeSeriesCollectionChartPortlet.ERROR_0002.COULD_NOT_CREATE"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
110
content = buffer.toString();
111             }
112         } finally {
113             if (chartComponent != null)
114                 chartComponent.dispose();
115         }
116     }
117 }
118
Popular Tags