Ejemplo n.º 1
0
 /** 输出Sitemap */
 @At
 @Ok("raw:xml")
 public File sitemap() throws MalformedURLException, ParseException {
   String tmpdir = conf.get("website.tmp_dir", "/tmp");
   Files.createDirIfNoExists(tmpdir);
   final WebSitemapGenerator gen = new WebSitemapGenerator(urlbase, new File(tmpdir));
   gen.addUrl(urlbase + "/yvr/list");
   dao.each(
       Topic.class,
       Cnd.orderBy().desc("createTime"),
       dao.createPager(1, 1000),
       new Each<Topic>() {
         public void invoke(int index, Topic topic, int length) {
           try {
             Options options = new Options(urlbase + "/yvr/t/" + topic.getId());
             // TODO 从redis读取最后更新时间
             // options.lastMod(topic.getCreateAt());
             WebSitemapUrl url = new WebSitemapUrl(options);
             gen.addUrl(url);
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       });
   List<File> list = gen.write();
   if (list.size() > 0) return list.get(0);
   return null;
 }
Ejemplo n.º 2
0
  private static void extractItems(
      final MavenProject project,
      final List<MenuItem> items,
      final WebSitemapGenerator generator,
      final ChangeFreq changeFreq)
      throws MalformedURLException {
    if (items == null || items.isEmpty()) {
      return;
    }

    for (final MenuItem item : items) {
      final Options options = new Options(project.getUrl() + relativePath(item.getHref()));
      options.lastMod(new Date());
      options.changeFreq(changeFreq);
      generator.addUrl(options.build());
      extractItems(project, item.getItems(), generator, changeFreq);
    }
  }