Frage

I am trying to write a small RSS Reader. I use ROME in order to get the RSS feeds. This works fine so far. However, I am not able to obtain the RSS icon of the individual feeds. Is there a way to get the icon (e.g. the URL) via ROME or does anybody know an easy way to achieve this through java without ROME?

War es hilfreich?

Lösung

The favicon.ico is almost always in the root of the host, for example, for stackoverflow's you can go here: https://stackoverflow.com/favicon.ico and get redirected to the icon. Sometimes, RSS feeds are actually hosted on a different service (like google or feedburner) than the site itself (where all the RSS items are), so you need to access the <link> element to get the host, then simply access the host's favicon.ico.

Example, over at Crunchy Roll, they use feed burner and the RSS feed looks something like this:

<channel>
 <title>Latest in Anime News by Crunchyroll!</title>
 <description>Read about the latest updates on Crunchyroll.com</description>
 <link>http://www.crunchyroll.com/news</link>

So if you have a SyndEntry,

  1. you can call the getLink() method to access this link, (http://www.crunchyroll.com/news)
  2. remove the URI (http://www.crunchyroll.com/)
  3. append favicon.ico and fetch the icon (http://www.crunchyroll.com/favicon.ico)

This may not always work, although sites really should be putting favicon.ico in their document root, some sites may use a <link> tag within the page, something like:

<link rel="shortcut icon" href="new_category/favicon.ico" type="image/x-icon">

To indicate that for a given page, to use this other favicon. This doesn't necessarily mean there isn't a favicon,ico sitting at the document root, just that for this link, to use this icon. So if you want to take the extra steps, you can insert these steps between 1. and 2. above:

  • Load the link (http://www.crunchyroll.com/news)
  • Check for a <link rel="shortcut icon"> in the header
  • Load that and call it a day
  • Otherwise continue to step 2
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top