KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

58
59     protected void buildNormalContext(VelocityPortlet portlet,
60                                        Context context,
61                                        RunData rundata)
62     {
63         try
64         {
65             // Get reference to stock quote web service
66
StockQuoteService service = (StockQuoteService) TurbineServices.getInstance().
67                 getService(StockQuoteService.SERVICE_NAME);
68
69             // Retrieve portlet parameters
70
String JavaDoc symbols = PortletConfigState.getParameter(portlet, rundata, SYMBOLS, "IBM,MSFT,ORCL,SUNW");
71             String JavaDoc columns = PortletConfigState.getParameter(portlet, rundata, COLUMNS,
72                                                              StringUtils.arrayToString(ALL_COLUMNS, ","));
73             String JavaDoc[] selectedColumnsArray = StringUtils.stringToArray(columns, ",");
74
75             // Request stock quote(s) from the stock quote web service
76
String JavaDoc[] symbolArray = StringUtils.stringToArray(symbols, ",");
77             StockQuote[] quotes = service.fullQuotes(symbolArray);
78
79             // Place appropriate objects in Velocity context
80
context.put(QUOTES, quotes);
81             context.put(SELECTED_COLUMNS, selectedColumnsArray);
82             context.put(COLUMNS, columns);
83         }
84         catch (Exception JavaDoc e)
85         {
86             Log.error(e);
87         }
88     }
89 }
90
91
Popular Tags