フォーラム

ホーム » Liferay Portal » English » 2. Using Liferay » General

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Monalisa Sahu
Weather Portlet
2012/02/28 4:39
答え

Monalisa Sahu

ランク: New Member

投稿: 2

参加年月日: 2012/02/28

最近の投稿

Can anybody send me weather portlet
David H Nebinger
RE: Weather Portlet
2012/02/28 5:08
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11046

参加年月日: 2006/09/01

最近の投稿

Whatever you guys are working on, you should share notes.

Review all of the other recent posts on the weather portlet: where to get it, how to deploy it, how to configure it, and why invalid params result in blank screen.
Monalisa Sahu
RE: Weather Portlet
2012/02/28 5:40
答え

Monalisa Sahu

ランク: New Member

投稿: 2

参加年月日: 2012/02/28

最近の投稿

where should i put the war file of weather portlet in order to deploy it
David H Nebinger
RE: Weather Portlet
2012/02/28 5:44
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11046

参加年月日: 2006/09/01

最近の投稿

Again, this has all been covered in recent weeks as your friends have been doing the same things.

Search the forum to find the info.
Dave Weitzel
RE: Weather Portlet
2012/12/06 13:02
答え

Dave Weitzel

ランク: Regular Member

投稿: 203

参加年月日: 2009/11/18

最近の投稿

Google has now stopped providing the weather api used in the portlet so it is not usable until updated to a new API
Hitoshi Ozawa
RE: Weather Portlet
2012/12/06 14:17
答え

Hitoshi Ozawa

ランク: Liferay Legend

投稿: 7949

参加年月日: 2010/03/23

最近の投稿

It's already been fixed.

http://issues.liferay.com/browse/LPS-29542
Jitendra Rajput
RE: Weather Portlet
2012/12/06 21:45
答え

Jitendra Rajput

ランク: Liferay Master

投稿: 858

参加年月日: 2011/01/07

最近の投稿

If you want to check code then look into WeatherWebCacheItem.java .
Old code with google API was like this

 1
 2public Object convert(String key) throws WebCacheException {
 3        Weather weather = null;
 4
 5        try {
 6            String text = HtmlUtil.stripComments(HttpUtil.URLtoString(
 7                "https://www.google.com/ig/api?weather=" +
 8                    HttpUtil.encodeURL(_zip)));
 9
10            int x = text.indexOf("temp_f data");
11
12            x = text.indexOf("\"", x) + 1;
13
14            int y = text.indexOf("\"", x);
15
16            float temperature = GetterUtil.getFloat(text.substring(x, y));
17
18            x = text.indexOf("/images", x);
19            y = text.indexOf("\"", x);
20
21            String iconURL = "https://www.google.com" + text.substring(x, y);
22
23            weather = new Weather(_zip, iconURL, temperature);
24        }
25        catch (Exception e) {
26            throw new WebCacheException(_zip);
27        }
28
29        return weather;
30    }


And new code with API change

 1
 2 public Object convert(String key) throws WebCacheException {
 3        Weather weather = null;
 4
 5        try {
 6            StringBundler sb = new StringBundler(5);
 7
 8            sb.append("http://free.worldweatheronline.com/feed/weather.ashx?key=");
 9            sb.append(WeatherPropsUtil.get("world.weather.online.api.key"));
10            sb.append("&q=");
11            sb.append(HttpUtil.encodeURL(zipName));
12            sb.append("&format=xml");
13            
14            String xml = HtmlUtil.stripComments(HttpUtil.URLtoString(sb.toString()));
15
16            Document document = SAXReaderUtil.read(xml);
17
18            Element rootElement = document.getRootElement();
19
20            Element currentConditionElement = rootElement.element(
21                "current_condition");
22
23            Element temperatureElement = currentConditionElement.element("temp_F");
24
25            float temperature = GetterUtil.getFloat(temperatureElement.getData());
26
27            Element iconElement = currentConditionElement.element("weatherIconUrl");
28
29            String iconURL = iconElement.getText();
30
31            weather = new Weather(zipName, iconURL, temperature);
32        }
33        catch (Exception e) {
34            throw new WebCacheException(zipName);
35        }
36
37        return weather;
38    }