From 601a91f488cdffe3ebe7ed9f8d411c4a04aa6f55 Mon Sep 17 00:00:00 2001 From: Vincent Lucas Date: Wed, 8 Oct 2008 16:04:34 +0000 Subject: [PATCH] Some feeds are storing the URI of the entry in the LINK tag. This correction manages this exception. --- .../impl/protocol/rss/RssItemKey.java | 67 ++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/rss/RssItemKey.java b/src/net/java/sip/communicator/impl/protocol/rss/RssItemKey.java index 11433f136..07ff39ab5 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/RssItemKey.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/RssItemKey.java @@ -27,46 +27,65 @@ public class RssItemKey private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceRssImpl.class); - /*** + /** * Date of the last show post. If it cannot be used, it's null. */ private Date itemDate; - /*** + /** * URI (link) of the last shown post. If it's not used, it's null. */ private String itemUri; - /*** + /** * Flag to mark whether date is used to mark items (true) or * URI (false) */ private boolean usesDate; + /** + * Sets the date format for serializing and deserialiazing. + */ private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd-HH:mm:ss"); - /*** - * Creates a RssContactSettings object that uses date to identify feed - * items, with the last item date specified by the lastPostDate - * parameter. - * @param itemDate date/time of the item + /** + * Creates a RssContactSettings object that uses date if possible or at + * least URI to identify feed items. + * @param entry The last Syndentry of the RSS feed. */ public RssItemKey(SyndEntry entry) { this.itemUri = entry.getUri(); this.itemDate = entry.getPublishedDate(); this.usesDate = (this.itemDate != null); + // Some feeds are storing the URI of the entry in the link tag. Do not + // ask me why, but it is llike this. + if(!usesDate && itemUri == null) + { + this.itemUri = entry.getLink(); + } } - public RssItemKey(Date date) + /** + * Creates a RssContactSettings object that uses date to identify feed + * items, with the last item date specified by the Date + * parameter. + * @param date date/time of the last item of the RSS feed. + */ + private RssItemKey(Date date) { this.itemUri = null; this.itemDate = date; this.usesDate = true; } - public RssItemKey(String uri) + /** + * Creates a RssContactSettings object that uses URI to identify feed + * items. + * @param uri The URI of the last RSS entry. + */ + private RssItemKey(String uri) { this.itemUri = uri; this.itemDate = null; @@ -132,13 +151,17 @@ public static RssItemKey deserialize(String settings) { String data[] = reader.nextToken().split("=", 2); + // Parse the date item. if (data[0].equals("itemDate")) { if (data.length == 2) { try { - date = formatter.parse(data[1]); + if(!data[1].equals("null")) + { + date = formatter.parse(data[1]); + } } catch (ParseException e) { @@ -156,11 +179,15 @@ public static RssItemKey deserialize(String settings) return null; } } + // Parse the uri item. else if (data[0].equals("itemUri")) { if (data.length == 2) { - uri = data[1]; + if(!data[1].equals("null")) + { + uri = data[1]; + } } else { @@ -170,6 +197,7 @@ else if (data[0].equals("itemUri")) return null; } } + // Parse the usesDate item. else if (data[0].equals("usesDate")) { if (data.length == 2) @@ -187,6 +215,7 @@ else if (data[0].equals("usesDate")) } } + // If the initialization was good, we create a new RssItemKey. if(useInitialized) { if(isDateUsed && date != null) @@ -198,6 +227,7 @@ else if(!isDateUsed && uri != null) return new RssItemKey(uri); } } + // Else we must return null, has the persistentData is buggy. return null; } @@ -210,18 +240,21 @@ public String serialize() { StringBuffer result = new StringBuffer(); + // Create the date item for the persistentData. result.append("itemDate="); result.append( itemDate == null ? - "" : formatter.format(itemDate)); + "null" : formatter.format(itemDate)); result.append(";"); + // Create the uri item for the persistentData. result.append("itemUri="); result.append( itemUri == null ? - "" : itemUri); + "null" : itemUri); result.append(";"); + // Create the usesDate item for the persistentData. result.append("usesDate="); result.append(usesDate); result.append(";"); @@ -240,7 +273,11 @@ public String toString() return this.serialize(); } - + /** + * Compare 2 RssItemKey. Compare items with date or with uri, but return + * always 1 when we can't say anything about order (one is date, the other + * is uri or the obj is null). + */ public int compareTo(RssItemKey obj) { if(obj == null)