KickJava   Java API By Example, From Geeks To Geeks.

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


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: TutorialStockQuoteAction1.java,v 1.1 2004/04/08 17:03:54 taylor Exp $
41  */

42 public class TutorialStockQuoteAction1 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 QUOTES = "quotes";
47     private static final String JavaDoc[] ALL_COLUMNS = {"Symbol","Price","Change","Volume"};
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
70             // Request stock quote(s) from the stock quote web service
71
String JavaDoc[] symbolArray = StringUtils.stringToArray(symbols, ",");
72             StockQuote[] quotes = service.fullQuotes(symbolArray);
73
74             // Place appropriate objects in Velocity context
75
context.put(QUOTES, quotes);
76             context.put(COLUMNS, ALL_COLUMNS);
77         }
78         catch (Exception JavaDoc e)
79         {
80             Log.error(e);
81         }
82     }
83 }
84
85
Popular Tags