1 6 7 package org.exoplatform.portlets.weather.component; 8 9 import java.text.DecimalFormat ; 10 import java.util.Calendar ; 11 import java.util.List ; 12 import java.util.ResourceBundle ; 13 import java.util.StringTokenizer ; 14 15 import javax.faces.context.FacesContext; 16 import org.exoplatform.faces.core.component.UIExoComponentBase; 17 18 import com.capeclear.www.GlobalWeather_xsd.Direction; 19 import com.capeclear.www.GlobalWeather_xsd.Layer; 20 import com.capeclear.www.GlobalWeather_xsd.Sky; 21 import com.capeclear.www.GlobalWeather_xsd.WeatherReport; 22 import com.capeclear.www.GlobalWeather_xsd.Wind; 23 24 25 public class UIWeatherView extends UIExoComponentBase 26 { 27 private boolean stationFound_; 28 private WeatherReport weatherReport_; 29 private ResourceBundle resources_; 30 private String contextPath_; 31 32 private UIWeatherDetail uiWeatherDetail; 33 private UIWeatherForm uiWeatherForm; 34 35 public UIWeatherView() { 36 super(); 37 setId("UIWeatherView"); 38 setRendererType("ChildrenRenderer"); 39 40 List children = getChildren(); 41 42 uiWeatherDetail = new UIWeatherDetail(); 43 uiWeatherForm = new UIWeatherForm(); 44 45 weatherReport_ = null; 46 stationFound_ = false; 47 resources_ = null; 48 contextPath_ = null; 49 updateTree(); 50 children.add(uiWeatherDetail); 51 children.add(uiWeatherForm); 52 } 53 54 public String getSearchStationCode() { 55 return uiWeatherForm.getSearchStationCode(); 56 } 57 58 public String getSearchStationName() { 59 return uiWeatherForm.getSearchStationName(); 60 } 61 62 public UIWeatherForm getUIWeatherForm() { 63 return uiWeatherForm; 64 } 65 66 public void setSearchStationCode(String pSearchStationCode) { 67 uiWeatherForm.setSearchStationCode(pSearchStationCode); 68 } 69 70 public void setSearchStationName(String pSearchStationName) { 71 uiWeatherForm.setSearchStationName(pSearchStationName); 72 } 73 74 public void setStationFound(boolean pStationFound) { 75 stationFound_ = pStationFound; 76 updateTree(); 77 } 78 79 public void setWeatherReport(WeatherReport pWeatherReport) { 80 weatherReport_ = pWeatherReport; 81 updateTree(); 82 } 83 84 public void setResources(ResourceBundle pResources) { 85 resources_ = pResources; 86 updateTree(); 87 } 88 89 public void setContextPath(String pContextPath) { 90 contextPath_ = pContextPath; 91 updateTree(); 92 } 93 94 public void decode(FacesContext context) { 95 } 96 97 private void updateTree() { 98 if (weatherReport_ != null) { 99 Calendar timeStamp = weatherReport_.getTimestamp(); 101 uiWeatherDetail.setStationDetail(timeStamp.getTime().toLocaleString()); 102 Sky sky = weatherReport_.getSky(); 104 if (sky != null) { 105 String typeSky = null; 106 String iconFile = null; 107 Layer [] layers = sky.getLayers(); 108 if (layers != null) { 109 if (layers.length > 0) { 110 typeSky = layers[0].getType().getValue(); 111 if (typeSky != null) 112 { 113 if (typeSky.equals("CLOUD")) { 114 int extent = layers[0].getExtent(); 115 if ((extent == 1) || (extent == 2) || (extent == 3) || (extent == 4)) { 116 typeSky+="_"+String.valueOf(extent); 117 } 118 } 119 try { 120 iconFile = resources_.getString(typeSky+"_DAY_ICON"); 121 } 122 catch(Exception ex) { 123 } 124 try { 125 uiWeatherDetail.setIconSrc(contextPath_+resources_.getString("ICONS_SOURCE_PATH")+iconFile); 126 } 127 catch(Exception ex) { 128 } 129 } 130 } 131 } 132 } 133 uiWeatherDetail.setTemperature(String.valueOf(weatherReport_.getTemperature().getAmbient())); 135 Wind wind = weatherReport_.getWind(); 137 if (wind != null) { 138 String stringWind = null; 139 try { 140 DecimalFormat df = new DecimalFormat ("# ###.###"); 141 stringWind = df.format(wind.getPrevailing_speed()) + " m/s"; 142 } catch (Exception ex) { 143 } 144 Direction direction = wind.getPrevailing_direction(); 145 if (direction != null) { 146 StringTokenizer strTk = new StringTokenizer (direction.getString(),"("); 147 if (stringWind != null) stringWind += " (" + strTk.nextToken().toString().trim()+")"; 148 else stringWind = strTk.nextToken().toString(); 149 } 150 uiWeatherDetail.setWind(stringWind); 151 } 152 uiWeatherDetail.setRendered(true); 153 } 154 else { 155 uiWeatherDetail.setRendered(false); 156 } 157 uiWeatherForm.setRendered(true); 158 } 159 } 160 | Popular Tags |