if (feed == null)
{
try
{
// Parse the feed
SyndFeedInput feedInput = new SyndFeedInput();
feed = feedInput.build(new InputStreamReader(
new URL(feedUrl).openStream()));
}
catch (Exception e1)
{
mLogger.info("Error parsing RSS: " + feedUrl);
}
}
// Store parsed feed in the cache
mCache.put(feedUrl, feed);
mLogger.debug("Newsfeed: not in Cache");
}
else
{
if (mLogger.isDebugEnabled())
{
mLogger.debug("Newsfeed: not using Cache for " + feedUrl);
}
try
{
// charset fix from Jason Rumney (see ROL-766)
URLConnection connection = new URL(feedUrl).openConnection();
connection.connect();
String contentType = connection.getContentType();
// Default charset to UTF-8, since we are expecting XML
String charset = "UTF-8";
if (contentType != null) {
int charsetStart = contentType.indexOf("charset=");
if (charsetStart >= 0) {
int charsetEnd = contentType.indexOf(";", charsetStart);
if (charsetEnd == -1) charsetEnd = contentType.length();
charsetStart += "charset=".length();
charset = contentType.substring(charsetStart, charsetEnd);
// Check that charset is recognized by Java
try {
byte[] test = "test".getBytes(charset);
}
catch (UnsupportedEncodingException codingEx) {
// default to UTF-8
charset = "UTF-8";
}
}
}
// Parse the feed
SyndFeedInput feedInput = new SyndFeedInput();
feed = feedInput.build(new InputStreamReader(
connection.getInputStream(), charset));
}
catch (Exception e1)
{
mLogger.info("Error parsing RSS: " + feedUrl);