RSSWebCacheItem.java |
1 /** 2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or modify it under 5 * the terms of the GNU Lesser General Public License as published by the Free 6 * Software Foundation; either version 2.1 of the License, or (at your option) 7 * any later version. 8 * 9 * This library is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 12 * details. 13 */ 14 15 package com.liferay.portlet.rss.util; 16 17 import com.liferay.portal.kernel.util.Time; 18 import com.liferay.portal.kernel.webcache.WebCacheException; 19 import com.liferay.portal.kernel.webcache.WebCacheItem; 20 21 import com.sun.syndication.feed.synd.SyndFeed; 22 import com.sun.syndication.io.SyndFeedInput; 23 import com.sun.syndication.io.XmlReader; 24 25 import java.net.URL; 26 27 /** 28 * <a href="RSSWebCacheItem.java.html"><b><i>View Source</i></b></a> 29 * 30 * @author Brian Wing Shun Chan 31 */ 32 public class RSSWebCacheItem implements WebCacheItem { 33 34 public RSSWebCacheItem(String url) { 35 _url = url; 36 } 37 38 public Object convert(String key) throws WebCacheException { 39 SyndFeed feed = null; 40 41 try { 42 43 // com.liferay.portal.kernel.util.HttpUtil will break the connection 44 // if it spends more than 5 seconds looking up a location. However, 45 // German umlauts do not get encoded correctly. This may be a bug 46 // with commons-httpclient or with how FeedParser uses 47 // java.io.Reader. 48 49 // Use http://xml.newsisfree.com/feeds/29/629.xml and 50 // http://test.domosoft.com/up/RSS to test if German umlauts show 51 // up correctly. 52 53 /*Reader reader = new StringReader( 54 new String(HttpUtil.URLtoByteArray(_url))); 55 56 channel = FeedParser.parse(builder, reader);*/ 57 58 SyndFeedInput input = new SyndFeedInput(); 59 60 feed = input.build(new XmlReader(new URL(_url))); 61 } 62 catch (Exception e) { 63 throw new WebCacheException(_url + " " + e.toString()); 64 } 65 66 return feed; 67 } 68 69 public long getRefreshTime() { 70 return _REFRESH_TIME; 71 } 72 73 private static final long _REFRESH_TIME = Time.MINUTE * 20; 74 75 private String _url; 76 77 }