JavaFX - Custom Feed Parsers
By Rakesh Menon on Sep 15, 2009
Unfortunately many feeds do not strictly comply with the RSS/ATOM format. Example: In some cases the date specified for pubDate element may be in wrong format, or its an invalid date or the information specified is embedded in CDATA instead of TEXT. The parser will fail for such scenarios. Hence we need to implement custom parsers so as to handle the situation.
Below sample reads engadget rss feed..
<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="/rakeshmenonp/resource/CustomRssTask/CustomRssTask.js"></script>
For Applet mode, click on above image
Both RssTask and AtomTask API provide an attribute - factory - which can be used to specify custom implementation of RSS or ATOM Factory. Users may also customize various elements such as Channel, Item, Entry, Feed by overriding functions such as - fromXML, tryParseDate etc.
Example: In some cases the default parser fails to convert pubDate to valid DateTime instance. So a new attribute - pubDateText - is added so as to save the date as String.
Now we need to implement a custom Factory which will instantiate and return the above CustomItem instance.
Above Factory is set in factory attribute of RssTask as shown below.
Update: Please refer to SpeedReaderFX by Jim Weaver for real world example.
Try it out and let me know feedback