morciuch 2003/08/27 07:57:40
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
WeatherAction.java
Log:
Restoring prior version - somehow it got overwritten by one of the patches (see
Bugzilla bug# 20593)
Revision Changes Path
1.7 +56 -110
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WeatherAction.java 23 Jul 2003 19:50:12 -0000 1.6
+++ WeatherAction.java 27 Aug 2003 14:57:40 -0000 1.7
@@ -1,7 +1,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,10 +54,12 @@
package org.apache.jetspeed.modules.actions.portlets;
-// Velocity stuff
+// Jetspeed stuff
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
+import org.apache.jetspeed.util.PortletConfigState;
+// Turbine stuff
import org.apache.turbine.util.RunData;
// Velocity Stuff
@@ -69,19 +71,27 @@
/**
* WeatherAction portlet uses WeatherUnderground's weather condition
* stickers/banners to build the portlet view.
- *
+ *
* <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 $Id$
*/
public class WeatherAction extends VelocityPortletAction
{
-
+ public static final String WEATHER_CITY_INFO = "weather_city_info";
+ public static final String WEATHER_STATE = "weather_state";
+ public static final String WEATHER_CITY = "weather_city";
+ public static final String WEATHER_STATION = "weather_station";
+ public static final String WEATHER_STYLE = "weather_style";
+
/**
* Nothing specific for maximized view.
- *
+ *
+ * @param portlet
+ * @param context
+ * @param rundata
* @see VelocityPortletAction#buildMaximizedContext
*/
protected void buildMaximizedContext( VelocityPortlet portlet,
@@ -90,112 +100,73 @@
{
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 )
- {
- buildNormalContext( portlet, context, rundata);
- String cityInfo = (String)context.get("weather_city_info");
- if(cityInfo != null)
- {
- try
- {
- javax.naming.Name path = new javax.naming.CompositeName(cityInfo);
- if(path.size()==3)
- {
- 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)
- {}
- }
- setTemplate(rundata, "weather-customize");
- }
-
+
/**
* Subclasses must override this method to provide default behavior
* for the portlet action
- *
+ *
+ * @param portlet
+ * @param context
+ * @param rundata
* @see VelocityPortletAction#buildNormalContext
*/
protected void buildNormalContext( VelocityPortlet portlet,
Context context,
RunData rundata )
{
- 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 cityInfo = PortletConfigState.getParameter(portlet, rundata,
WEATHER_CITY_INFO, null);
+ //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);
+ //}
+ context.put(WEATHER_CITY_INFO, cityInfo);
+ PortletConfigState.setInstanceParameter(portlet, rundata,
WEATHER_CITY_INFO, cityInfo);
+
+ String style = PortletConfigState.getParameter(portlet, rundata,
WEATHER_STYLE, "infobox");
+ 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
+ *
+ * @param city
+ * @param state
+ * @return
*/
private String getUSInfo(String city, String state)
{
city = city.trim().toLowerCase()+" ";
- if(city.indexOf(" ")>0)
+ if (city.indexOf(" ")>0)
{
String newCity = "";
StringTokenizer st = new StringTokenizer(city, " ");
- while(st.hasMoreTokens())
+ while (st.hasMoreTokens())
{
String token = st.nextToken();
newCity = newCity + token.substring(0,1).toUpperCase() +
- token.substring(1) + "_";
+ 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.
+ *
+ * @param city
+ * @param state
+ * @param station
+ * @return
*/
private String getCityInfo(String city, String state, String station)
{
@@ -210,43 +181,18 @@
}
return cityInfo;
}
-
+
/**
+ *
+ * @param data
+ * @param context
* @see VelocityPortletAction#doCancel
- */
+ */
public void doCancel(RunData data, Context context)
{
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);
- }
- }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]