示例#1
0
  /* (non-Javadoc)
   * @see java.lang.Thread#run()
   */
  @SuppressWarnings("unchecked")
  @Override
  public void run() {

    while (!plugin.isSuspendThread()) {
      try {
        Thread.sleep(plugin.getConfiguration().getRefreshInterval() * 1000);
      } catch (InterruptedException e) {
        // ignore exception
      }

      for (final URL feedURL : plugin.getConfiguration().getFeedURLs()) {

        try {

          final SyndFeed feed = input.build(new XmlReader(feedURL));

          for (final SyndEntry feedEntry : (List<SyndEntry>) feed.getEntries()) {
            plugin.addContent(
                feedEntry.getTitle(), feedEntry.getPublishedDate(), new URL(feedEntry.getLink()));
          }

        } catch (IllegalArgumentException e) {
          plugin.addException(new PluginException(plugin.getConfiguration(), e));
        } catch (IOException e) {
          plugin.addException(new PluginException(plugin.getConfiguration(), e));
        } catch (FeedException e) {
          plugin.addException(new PluginException(plugin.getConfiguration(), e));
        }
      }
    }
  }
  private String getEntryContent(SyndEntry entry) {
    List contents = entry.getContents();
    StringBuffer buffer = new StringBuffer();
    for (int index = 0; contents != null && index < contents.size(); index++) {
      SyndContent content = (SyndContent) contents.get(index);
      buffer.append(content.getValue());
    }

    return (buffer.length() == 0) ? entry.getDescription().getValue() : buffer.toString();
  }
 private FeedItem convertEntryToFeedItem(SyndEntry entry) {
   if (entry != null) {
     String content = this.getEntryContent(entry);
     String description =
         entry.getDescription() == null ? content : entry.getDescription().getValue();
     String title = entry.getTitle();
     String url = entry.getLink();
     Date date =
         entry.getUpdatedDate() == null ? entry.getPublishedDate() : entry.getUpdatedDate();
     return new FeedItem(content, description, title, url, date);
   }
   return null;
 }