1 16 17 package org.apache.jetspeed.modules.actions.portlets; 18 19 import org.apache.jetspeed.portal.portlets.VelocityPortlet; 20 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 21 import org.apache.jetspeed.services.logging.JetspeedLogger; 22 23 import org.apache.turbine.util.RunData; 25 import org.apache.turbine.services.TurbineServices; 26 import org.apache.velocity.context.Context; 28 29 import org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService; 31 import org.apache.jetspeed.webservices.finance.stockmarket.StockQuote; 32 import org.apache.jetspeed.services.resources.JetspeedResources; 33 34 import org.apache.jetspeed.util.PortletConfigState; 35 import org.apache.jetspeed.util.StringUtils; 36 37 43 44 public class StockQuoteAction extends VelocityPortletAction 45 { 46 private static final String SYMBOLS = "symbols"; 47 private static final String COLUMNS = "columns"; 48 private static final String QUOTES = "quotes"; 49 private static final String [] ALL_COLUMNS = {"Symbol","Price","Change","Volume"}; 50 private static final String SELECTED_COLUMNS = "selected-columns"; 51 52 55 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(StockQuoteAction.class.getName()); 56 57 64 protected void buildMaximizedContext( VelocityPortlet portlet, 65 Context context, 66 RunData rundata ) 67 { 68 buildNormalContext( portlet, context, rundata); 69 } 70 71 79 protected void buildConfigureContext( VelocityPortlet portlet, 80 Context context, 81 RunData rundata ) 82 { 83 buildNormalContext( portlet, context, rundata); 84 85 setTemplate(rundata, "stock-quote-customize"); 86 87 88 } 89 90 97 98 protected void buildNormalContext( VelocityPortlet portlet, 99 Context context, 100 RunData rundata ) 101 { 102 try 103 { 104 StockQuoteService service = (StockQuoteService) TurbineServices.getInstance(). 106 getService(StockQuoteService.SERVICE_NAME); 107 108 String symbols = PortletConfigState.getParameter(portlet, rundata, SYMBOLS, "IBM,MSFT,ORCL,SUNW"); 110 String columns = PortletConfigState.getParameter(portlet, rundata, COLUMNS, 111 StringUtils.arrayToString(ALL_COLUMNS, ",")); 112 String [] selectedColumnsArray = StringUtils.stringToArray(columns, ","); 113 114 String [] symbolArray = StringUtils.stringToArray(symbols, ","); 116 StockQuote[] quotes = service.fullQuotes(symbolArray); 117 118 context.put(QUOTES, quotes); 120 context.put(SELECTED_COLUMNS, selectedColumnsArray); 121 context.put(COLUMNS, columns); 122 } 123 catch (Exception e) 124 { 125 logger.error("Exception", e); 127 128 rundata.setMessage("Error in Jetspeed Stock Quotes: " + e.toString()); 129 rundata.setStackTrace(org.apache.turbine.util.StringUtils.stackTrace(e), e); 130 rundata.setScreenTemplate(JetspeedResources.getString("template.error","Error")); 131 } 132 } 133 134 135 136 } 137 138 | Popular Tags |