001 /** 002 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 013 */ 014 015 package com.liferay.portlet.rss.util; 016 017 import com.liferay.portal.kernel.util.Time; 018 import com.liferay.portal.kernel.webcache.WebCacheException; 019 import com.liferay.portal.kernel.webcache.WebCacheItem; 020 021 import com.sun.syndication.feed.synd.SyndFeed; 022 import com.sun.syndication.io.SyndFeedInput; 023 import com.sun.syndication.io.XmlReader; 024 025 import java.net.URL; 026 027 /** 028 * @author Brian Wing Shun Chan 029 */ 030 public class RSSWebCacheItem implements WebCacheItem { 031 032 public RSSWebCacheItem(String url) { 033 _url = url; 034 } 035 036 public Object convert(String key) throws WebCacheException { 037 SyndFeed feed = null; 038 039 try { 040 041 // com.liferay.portal.kernel.util.HttpUtil will break the connection 042 // if it spends more than 5 seconds looking up a location. However, 043 // German umlauts do not get encoded correctly. This may be a bug 044 // with commons-httpclient or with how FeedParser uses 045 // java.io.Reader. 046 047 // Use http://xml.newsisfree.com/feeds/29/629.xml and 048 // http://test.domosoft.com/up/RSS to test if German umlauts show 049 // up correctly. 050 051 /*Reader reader = new StringReader( 052 new String(HttpUtil.URLtoByteArray(_url))); 053 054 channel = FeedParser.parse(builder, reader);*/ 055 056 SyndFeedInput input = new SyndFeedInput(); 057 058 feed = input.build(new XmlReader(new URL(_url))); 059 } 060 catch (Exception e) { 061 throw new WebCacheException(_url + " " + e.toString()); 062 } 063 064 return feed; 065 } 066 067 public long getRefreshTime() { 068 return _REFRESH_TIME; 069 } 070 071 private static final long _REFRESH_TIME = Time.MINUTE * 20; 072 073 private String _url; 074 075 }