Ejemplo n.º 1
0
  /** 全文输出 */
  @At
  @Ok("raw:xml")
  public String rss() throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    String urlbase = conf.get("website.urlbase", "https://nutz.cn");
    feed.setLink(urlbase);
    feed.setTitle(conf.get("website.title", "Nutz社区"));
    feed.setDescription(conf.get("website.description", "一个有爱的社区"));

    feed.setAuthor(conf.get("website.author", "wendal"));
    feed.setEncoding("UTF-8");
    feed.setLanguage("zh-cn");

    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    SyndEntry entry;
    SyndContent description;
    List<Topic> list =
        dao.query(Topic.class, Cnd.orderBy().desc("createTime"), dao.createPager(1, 10));
    for (Topic topic : list) {
      dao.fetchLinks(topic, "author");
      entry = new SyndEntryImpl();
      entry.setTitle(topic.getTitle());
      entry.setLink(urlbase + "/yvr/t/" + topic.getId());
      entry.setPublishedDate(topic.getCreateTime());
      description = new SyndContentImpl();
      description.setType("text/html");
      description.setValue(Markdowns.toHtml(topic.getContent(), urlbase));
      entry.setDescription(description);
      entry.setAuthor(topic.getAuthor().getLoginname());
      entries.add(entry);
    }

    feed.setEntries(entries);
    if (list.size() > 0) {
      feed.setPublishedDate(list.get(0).getCreateTime());
    }

    SyndFeedOutput output = new SyndFeedOutput();
    return output.outputString(feed, true);
  }