portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets StockQuoteAction.java
Date Mon, 29 Oct 2001 09:00:59 GMT
taylor      01/10/29 01:00:59

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets
                        StockQuoteAction.java
  Log:
  Changed StockPortlet to get symbols per user, symbol lists are stored on the web service
server.
  Added Customization to edit and store symbols on web service server. Symbol lists are stored
by user.
  
  Revision  Changes    Path
  1.2       +88 -9     jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/StockQuoteAction.java
  
  Index: StockQuoteAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/StockQuoteAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StockQuoteAction.java	2001/09/23 07:45:59	1.1
  +++ StockQuoteAction.java	2001/10/29 09:00:59	1.2
  @@ -62,10 +62,12 @@
   import org.apache.turbine.util.StringUtils;
   import org.apache.turbine.services.Service;
   import org.apache.turbine.services.TurbineServices;
  +import org.apache.turbine.om.security.User;
   
   // Velocity Stuff
   import org.apache.velocity.context.Context;
   
  +import org.apache.jetspeed.util.StringUtils;
   import org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService;
   import org.apache.jetspeed.webservices.finance.stockmarket.StockQuote;
   
  @@ -103,8 +105,11 @@
                                             Context context,
                                             RunData rundata )
       {
  +        buildNormalContext( portlet, context, rundata);
  +        
  +        setTemplate(rundata, "stock-quote-customize");
   
  -        buildNormalContext( portlet, context, rundata);        
  +        
       }
   
       /** 
  @@ -114,9 +119,6 @@
        * @param context The velocity context for this request.
        * @param rundata The turbine rundata context for this request.
        */
  -
  -     // TODO: replace this array with configurable velocity screen
  -    static String[] symbols = { "DST", "IONA", "IBM" };
       
       protected void buildNormalContext( VelocityPortlet portlet, 
                                          Context context,
  @@ -126,12 +128,20 @@
           {                        
               StockQuoteService service = 
                   (StockQuoteService)TurbineServices.getInstance().getService(StockQuoteService.SERVICE_NAME);
  -
  -            // TODO: replace fullQuotes with:
  -            //          StockQuote[] quotes = service.quotesByUser( username );
   
  -            StockQuote[] quotes = service.fullQuotes( symbols );
  +            String symbols = (String)context.get("symbols");
  +            if (null == symbols || symbols == "")
  +            {
  +                String userName = getCurrentUser(rundata);
  +                String password = getCurrentPassword(rundata);
  +                symbols = service.getSymbols( "jetspeed", userName, password );
  +                context.put("symbols", symbols);
  +
  +            }
  +            String [] symbolArray = org.apache.jetspeed.util.StringUtils.stringToArray(symbols,
",");
  +            StockQuote[] quotes = service.fullQuotes( symbolArray );
               context.put("quotes", quotes);
  +
           }
           catch (Exception e)
           {
  @@ -139,10 +149,79 @@
               Log.error(e);
   
               rundata.setMessage("Error in Jetspeed Stock Quotes: " + e.toString());
  -            rundata.setStackTrace(StringUtils.stackTrace(e), e);
  +            rundata.setStackTrace(org.apache.turbine.util.StringUtils.stackTrace(e), e);
               rundata.setScreenTemplate("Error.vm");            
           }
       }
  +    
  +    private String getCurrentUser(RunData rundata)
  +    {
  +        User user = rundata.getUser();
  +        String userName;
  +    
  +        if (null == user)
  +        {
  +            userName = "anon";
  +        }
  +        else
  +        {
  +            userName = user.getUserName();
  +            if (null == userName)
  +            {
  +                userName = "anon";
  +            }
  +        }
  +        return userName;
  +    }
   
  +    private String getCurrentPassword(RunData rundata)
  +    {
  +        User user = rundata.getUser();
  +        String password;
  +    
  +        if (null == user)
  +        {
  +            password = "anon";
  +        }
  +        else
  +        {
  +            password = user.getPassword();
  +            if (null == password)
  +            {
  +                password = "anon";
  +            }
  +        }
  +        return password;
  +    }
  +
  +
  +
  +    public void doUpdate(RunData data, Context context)
  +    {
  +        String newSymbols = org.apache.jetspeed.util.StringUtils.removeChars(data.getParameters().getString("symbols"),
" ");
  +       
  +        try
  +        {                        
  +            StockQuoteService service = 
  +                (StockQuoteService)TurbineServices.getInstance().getService(StockQuoteService.SERVICE_NAME);
  +
  +            String userName = getCurrentUser(data);
  +            String password = getCurrentPassword(data);
  +            boolean success = service.storeSymbols( "jetspeed", userName, password, newSymbols
);
  +            context.put("symbols", newSymbols);
  +            VelocityPortlet portlet = (VelocityPortlet)context.get("portlet");
  +            buildNormalContext( portlet, context, data);
  +
  +        }
  +        catch (Exception e)
  +        {
  +           // log the error msg
  +            Log.error(e);
  +
  +            data.setMessage("Error in Jetspeed Stock Quotes: " + e.toString());
  +            data.setStackTrace(org.apache.turbine.util.StringUtils.stackTrace(e), e);
  +            data.setScreenTemplate("Error.vm");            
  +        }
  +    }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message