paulsp      2002/07/27 06:45:11

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets
                        WeatherAction.java
  Log:
  o Converted tabs to spaces
  o Added some java comments
  o Set some function private.
  
  Revision  Changes    Path
  1.3       +124 -107  
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/WeatherAction.java
  
  Index: WeatherAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/WeatherAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WeatherAction.java        20 Jul 2002 09:05:29 -0000      1.2
  +++ WeatherAction.java        27 Jul 2002 13:45:11 -0000      1.3
  @@ -74,164 +74,181 @@
    *
    * <p> Donated by Community Grids Java Source Package</p>
    * <p> Provides supporting classess for portal environments.</p>
  - * 
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ozgur Balsoy</a>
  - * @version 0.1.0
  + * @version $Id$
    */
   public class WeatherAction extends VelocityPortletAction
   {
  -
  +    
       /**
        * Nothing specific for maximized view.
  +     *
  +     * @see VelocityPortletAction#buildMaximizedContext
        */
       protected void buildMaximizedContext( VelocityPortlet portlet,
  -                                       Context context,
  -                                       RunData rundata )
  +                                          Context context,
  +                                          RunData rundata )
       {
  -         buildNormalContext( portlet, context, rundata);
  +        buildNormalContext( portlet, context, rundata);
       }
  -
  +    
       /**
        * Subclasses should override this method if they wish to
        * provide their own customization behavior.
        * Default is to use Portal base customizer action
  +     *
  +     * @see VelocityPortletAction#buildConfigureContext
        */
       protected void buildConfigureContext( VelocityPortlet portlet,
  -                                       Context context,
  -                                       RunData rundata )
  +                                          Context context,
  +                                          RunData rundata )
       {
  -     buildNormalContext( portlet, context, rundata);
  -     String cityInfo = (String)context.get("weather_city_info");
  -     if(cityInfo != null) 
  +        buildNormalContext( portlet, context, rundata);
  +        String cityInfo = (String)context.get("weather_city_info");
  +        if(cityInfo != null)
           {
  -             try 
  +            try
               {
  -                 javax.naming.Name path = new javax.naming.CompositeName(cityInfo);
  -                 if(path.size()==3) 
  +                javax.naming.Name path = new javax.naming.CompositeName(cityInfo);
  +                if(path.size()==3)
                   {
  -                     if(path.get(0).equals("US"))
  +                    if(path.get(0).equals("US"))
                       {
  -                             context.put("weather_state",path.get(1));
  -                             context.put("weather_city",path.get(2).replace('_',' 
'));
  -                     } else {
  -                             context.put("weather_station",path.get(2));
  -                     }
  -                     }
  -             } 
  -            catch(Exception ex) 
  +                        context.put("weather_state",path.get(1));
  +                        context.put("weather_city",path.get(2).replace('_',' '));
  +                    } else
  +                    {
  +                        context.put("weather_station",path.get(2));
  +                    }
  +                }
  +            }
  +            catch(Exception ex)
               {}
  -         }
  -         setTemplate(rundata, "weather-customize");
  +        }
  +        setTemplate(rundata, "weather-customize");
       }
  -
  +    
       /**
        * Subclasses must override this method to provide default behavior
        * for the portlet action
  +     *
  +     * @see VelocityPortletAction#buildNormalContext
        */
       protected void buildNormalContext( VelocityPortlet portlet,
  -                                    Context context,
  -                                    RunData rundata )
  +                                       Context context,
  +                                       RunData rundata )
       {
  -         String cityInfo = portlet.getAttribute("weather_city_info",null, rundata);
  -         if( cityInfo == null) 
  +        String cityInfo = portlet.getAttribute("weather_city_info",null, rundata);
  +        if( cityInfo == null)
           {
  -         String city = portlet.getPortletConfig().getInitParameter("weather_city");
  -         String state = 
portlet.getPortletConfig().getInitParameter("weather_state");
  -         String station = 
portlet.getPortletConfig().getInitParameter("weather_station");
  -         cityInfo = getCityInfo(city, state, station);
  -         if(cityInfo == null) 
  -            {
  -                 setTemplate(rundata, "weather-customize");
  -                 return;
  -             } 
  -            else 
  -            {
  -                     portlet.setAttribute("weather_city_info",cityInfo, rundata);
  -             }
  -         }
  -     context.put("weather_city_info", cityInfo);
  -         String style = portlet.getAttribute("weather_style",null,rundata);
  -         if(style == null) 
  -        {
  -             style = portlet.getPortletConfig().getInitParameter("weather_style");
  -             if(style == null) 
  -            {
  -                     style = "infobox";
  -                     portlet.setAttribute("weather_style",style,rundata);
  -             }
  -         }
  -         context.put("weather_style",style);
  +            String city = 
portlet.getPortletConfig().getInitParameter("weather_city");
  +            String state = 
portlet.getPortletConfig().getInitParameter("weather_state");
  +            String station = 
portlet.getPortletConfig().getInitParameter("weather_station");
  +            cityInfo = getCityInfo(city, state, station);
  +            if(cityInfo == null)
  +            {
  +                setTemplate(rundata, "weather-customize");
  +                return;
  +            }
  +            else
  +            {
  +                portlet.setAttribute("weather_city_info",cityInfo, rundata);
  +            }
  +        }
  +        context.put("weather_city_info", cityInfo);
  +        String style = portlet.getAttribute("weather_style",null,rundata);
  +        if(style == null)
  +        {
  +            style = portlet.getPortletConfig().getInitParameter("weather_style");
  +            if(style == null)
  +            {
  +                style = "infobox";
  +                portlet.setAttribute("weather_style",style,rundata);
  +            }
  +        }
  +        context.put("weather_style",style);
       }
  -
  +    
       /**
        * Builds the path for US cities. The format is US/ST/City.html, i.e.
        * for New York City, the city path is US/NY/New_York
        */
  -    String getUSInfo(String city, String state)
  +    private String getUSInfo(String city, String state)
       {
  -         city = city.trim().toLowerCase()+" ";
  -         if(city.indexOf(" ")>0) 
  +        city = city.trim().toLowerCase()+" ";
  +        if(city.indexOf(" ")>0)
           {
  -         String newCity = "";
  -         StringTokenizer st = new StringTokenizer(city, " ");
  -         while(st.hasMoreTokens()) 
  -            {
  -                     String token = st.nextToken();
  -                     newCity = newCity + token.substring(0,1).toUpperCase() +
  -                 token.substring(1) + "_";
  -             }
  -             city = newCity.substring(0, newCity.length()-1); // remove last '_'
  -         }
  -     state = state.toUpperCase();
  -     return "US/" + state + "/" + city;
  +            String newCity = "";
  +            StringTokenizer st = new StringTokenizer(city, " ");
  +            while(st.hasMoreTokens())
  +            {
  +                String token = st.nextToken();
  +                newCity = newCity + token.substring(0,1).toUpperCase() +
  +                token.substring(1) + "_";
  +            }
  +            city = newCity.substring(0, newCity.length()-1); // remove last '_'
  +        }
  +        state = state.toUpperCase();
  +        return "US/" + state + "/" + city;
       }
  -
  +    
       /**
        * Builds the city path for US or other world cities. For world cities,
        * the city path is global/station/station_number, i.e.
        * for Istanbul, Turkey, it is global/stations/17060. The station numbers
        * need to be obtained from the Weather Underground's site.
        */
  -    String getCityInfo(String city, String state, String station)
  +    private String getCityInfo(String city, String state, String station)
       {
  -         String cityInfo = null;
  -         if (city!=null && state !=null && !city.equals("") && !state.equals(""))
  -         {
  -         cityInfo = getUSInfo(city, state);
  -         }
  -         else if (station != null && !station.equals(""))
  -         {
  -         cityInfo = "global/stations/" + station;
  -         }
  -         return cityInfo;
  +        String cityInfo = null;
  +        if (city!=null && state !=null && !city.equals("") && !state.equals(""))
  +        {
  +            cityInfo = getUSInfo(city, state);
  +        }
  +        else if (station != null && !station.equals(""))
  +        {
  +            cityInfo = "global/stations/" + station;
  +        }
  +        return cityInfo;
       }
  -
  +    
  +    /**
  +     * @see VelocityPortletAction#doCancel
  +     */    
       public void doCancel(RunData data, Context context)
       {
  -         VelocityPortlet portlet = (VelocityPortlet)context.get("portlet");
  -         buildNormalContext(portlet, context, data);
  +        VelocityPortlet portlet = (VelocityPortlet) context.get("portlet");
  +        buildNormalContext(portlet, context, data);
       }
  -
  +    
  +    /**
  +     * Update PSML parmaters to reflect the desired
  +     * weather station, i.e. city
  +     *
  +     * @param data data
  +     * @param context a context for web pages.
  +     */
       public void doUpdate(RunData data, Context context)
       {
  -     String city = (String)data.getParameters().getString("weather_city");
  -     String state = (String)data.getParameters().getString("weather_state");
  -     String style = (String)data.getParameters().getString("weather_style");
  -     String station = (String)data.getParameters().getString("weather_station");
  -    
  -     String cityInfo = getCityInfo(city, state, station);
  -     if(cityInfo != null) 
  -        {
  -         VelocityPortlet portlet = (VelocityPortlet)context.get("portlet");
  -         context.put("weather_city_info",cityInfo);
  -         portlet.setAttribute("weather_city_info",cityInfo,data);
  -             if(style == null || style.equals("")) 
  -            {
  -             style = "infobox";
  -             }
  -             context.put("weather_style",style);
  -             portlet.setAttribute("weather_style",style,data);
  -         }
  +        String city = (String) data.getParameters().getString("weather_city");
  +        String state = (String) data.getParameters().getString("weather_state");
  +        String style = (String) data.getParameters().getString("weather_style");
  +        String station = (String) data.getParameters().getString("weather_station");
  +        
  +        String cityInfo = getCityInfo(city, state, station);
  +        if (cityInfo != null)
  +        {
  +            VelocityPortlet portlet = (VelocityPortlet) context.get("portlet");
  +            context.put("weather_city_info", cityInfo);
  +            portlet.setAttribute("weather_city_info", cityInfo, data);
  +            if (style == null || style.equals(""))
  +            {
  +                style = "infobox";
  +            }
  +            context.put("weather_style", style);
  +            portlet.setAttribute("weather_style", style, data);
  +        }
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to