KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > tutorial > modules > actions > portlets > TutorialStockQuoteAction12


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.tutorial.modules.actions.portlets;
17
18 // Turbine stuff
19
import org.apache.turbine.util.Log;
20 import org.apache.turbine.util.RunData;
21 import org.apache.turbine.services.TurbineServices;
22
23 // Velocity Stuff
24
import org.apache.velocity.context.Context;
25
26 // Jetspeed stuff
27
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
28 import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
29 import org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService;
30 import org.apache.jetspeed.webservices.finance.stockmarket.StockQuote;
31 import org.apache.jetspeed.util.PortletConfigState;
32 import org.apache.jetspeed.util.StringUtils;
33
34 /**
35  * This action sets up the template context for retrieving stock quotes.
36  *
37  * @author <a HREF="mailto:morciuch@apache.org">Mark Orciuch</a>
38  * @version $Id: TutorialStockQuoteAction12.java,v 1.1 2004/04/08 17:03:54 taylor Exp $
39  */

40 public class TutorialStockQuoteAction12 extends VelocityPortletAction
41 {
42     private static final String JavaDoc SYMBOLS = "symbols";
43     private static final String JavaDoc COLUMNS = "columns";
44     private static final String JavaDoc SORT = "sort";
45     private static final String JavaDoc QUOTES = "quotes";
46     private static final String JavaDoc[] ALL_COLUMNS = {"Symbol","Price","Change","Volume"};
47     private static final String JavaDoc SELECTED_COLUMNS = "selected-columns";
48
49     /**
50      * Build the normal state content for this portlet.
51      *
52      * @param portlet The velocity-based portlet that is being built.
53      * @param context The velocity context for this request.
54      * @param rundata The turbine rundata context for this request.
55      */

56
57     protected void buildNormalContext(VelocityPortlet portlet,
58                                        Context context,
59                                        RunData rundata)
60     {
61         try
62         {
63             // Get reference to stock quote web service
64
StockQuoteService service = (StockQuoteService) TurbineServices.getInstance().
65                 getService(StockQuoteService.SERVICE_NAME);
66
67             // Retrieve portlet parameters
68
String JavaDoc symbols = PortletConfigState.getParameter(portlet, rundata, SYMBOLS, "IBM,MSFT,ORCL,SUNW");
69             String JavaDoc columns = PortletConfigState.getParameter(portlet, rundata, COLUMNS,
70                                                              StringUtils.arrayToString(ALL_COLUMNS, ","));
71             String JavaDoc[] selectedColumnsArray = StringUtils.stringToArray(columns, ",");
72             String JavaDoc sort = PortletConfigState.getParameter(portlet, rundata, SYMBOLS, "Symbol");
73
74             // Request stock quote(s) from the stock quote web service
75
String JavaDoc[] symbolArray = StringUtils.stringToArray(symbols, ",");
76             StockQuote[] quotes = service.fullQuotes(symbolArray);
77
78             // Place appropriate objects in Velocity context
79
context.put(QUOTES, quotes);
80             context.put(SELECTED_COLUMNS, selectedColumnsArray);
81             context.put(COLUMNS, columns);
82         }
83         catch (Exception JavaDoc e)
84         {
85             Log.error(e);
86         }
87     }
88
89     /**
90      * Subclasses should override this method if they wish to
91      * provide their own customization behavior.
92      * Default is to use Portal base customizer action
93      */

94     protected void buildConfigureContext(VelocityPortlet portlet,
95                                          Context context,
96                                          RunData rundata)
97     {
98         Log.debug("TutorialStockQuoteAction: portlet = " + portlet.getName());
99         //context.put("portlet", portlet);
100
//context.put("customizer", org.apache.jetspeed.util.template.JetspeedTool.getCustomizer(portlet));
101
setTemplate(rundata, "customizer-portlet");
102     }
103
104 }
105
106
Popular Tags