KickJava   Java API By Example, From Geeks To Geeks.

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


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 // Jetspeed stuff
24
import org.apache.jetspeed.portal.Portlet;
25 import org.apache.jetspeed.modules.actions.portlets.JspPortletAction;
26 import org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService;
27 import org.apache.jetspeed.webservices.finance.stockmarket.StockQuote;
28 import org.apache.jetspeed.util.PortletConfigState;
29 import org.apache.jetspeed.util.PortletSessionState;
30 import org.apache.jetspeed.util.StringUtils;
31
32 /**
33  * This action sets up the template context for retrieving stock quotes.
34  *
35  * @author <a HREF="mailto:morciuch@apache.org">Mark Orciuch</a>
36  * @version $Id: TutorialStockQuoteAction8.java,v 1.1 2004/04/08 17:03:54 taylor Exp $
37  */

38 public class TutorialStockQuoteAction8 extends JspPortletAction
39 {
40     private static final String JavaDoc SYMBOLS = "symbols";
41     private static final String JavaDoc COLUMNS = "columns";
42     private static final String JavaDoc QUOTES = "quotes";
43     private static final String JavaDoc[] ALL_COLUMNS = {"Symbol","Price","Change","Volume"};
44
45     /**
46      * Build the normal state content for this portlet.
47      *
48      * @param portlet The jsp-based portlet that is being built.
49      * @param rundata The turbine rundata context for this request.
50      */

51     protected void buildNormalContext(Portlet portlet,
52                                       RunData rundata)
53     {
54         try
55         {
56             // Get reference to stock quote web service
57
StockQuoteService service = (StockQuoteService) TurbineServices.getInstance().
58                 getService(StockQuoteService.SERVICE_NAME);
59
60             // Retrieve portlet parameters
61
String JavaDoc symbols = (String JavaDoc) PortletSessionState.getAttributeWithFallback(portlet, rundata, SYMBOLS);
62
63             // Request stock quote(s) from the stock quote web service
64
String JavaDoc[] symbolArray = StringUtils.stringToArray(symbols, ",");
65             StockQuote[] quotes = service.fullQuotes(symbolArray);
66
67             // Place appropriate objects in jsp context
68
rundata.getRequest().setAttribute(QUOTES, quotes);
69             rundata.getRequest().setAttribute(COLUMNS, ALL_COLUMNS);
70         }
71         catch (Exception JavaDoc e)
72         {
73             Log.error(e);
74         }
75     }
76 }
77
78
Popular Tags