jeecms 2012 源码分析(5)后台生成栏目页静态化分析

StaticPageDaoImpl 中

 转载请标识出处 by chenbo:http://blog.csdn.net/chenbo19867758/article/details/11953539

  1. public int channelStatic(Integer siteId, Integer channelId,  
  2.             boolean containChild, Configuration conf, Map<String, Object> data)  
  3.             throws IOException, TemplateException {  
  4.         Finder finder = Finder.create("select bean from Channel bean");  
  5.         if (channelId != null) {  
  6.             if (containChild) {  
  7.                 finder.append(",Channel parent where").append(  
  8.                         " bean.lft between parent.lft and parent.rgt").append(  
  9.                         " and parent.site.id=bean.site.id").append(  
  10.                         " and parent.id=:channelId");  
  11.                 finder.setParam("channelId", channelId);  
  12.             } else {  
  13.                 finder.append(" where bean.id=:channelId");  
  14.                 finder.setParam("channelId", channelId);  
  15.             }  
  16.         } else if (siteId != null) {  
  17.             finder.append(" where bean.site.id=:siteId");  
  18.             finder.setParam("siteId", siteId);  
  19.         }  
  20.         Session session = getSession();  
  21.         ScrollableResults channels = finder.createQuery(session).setCacheMode(  
  22.                 CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);  
  23.         int count = 0;  
  24.         CmsSite site;  
  25.         Channel c;  
  26.         PageInfo info;  
  27.         Writer out = null;  
  28.         Template tpl;  
  29.         String real, filename;  
  30.         File f, parent;  
  31.         int quantity, totalPage;  
  32.         if (data == null) {  
  33.             data = new HashMap<String, Object>();  
  34.         }  
  35.         while (channels.next()) {  
  36.             c = (Channel) channels.get(0);  
  37.             site = c.getSite();  
  38.             FrontUtils.frontData(data, site, nullnullnull);  
  39.             // 如果是外部链接或者不需要生产静态页,则不生成  
  40.             if (!StringUtils.isBlank(c.getLink()) || !c.getStaticChannel()) {  
  41.                 continue;  
  42.             }  
  43.             // 没有内容或者有子栏目,则只生成一页  
  44.             int childs = childsOfChannel(c.getId());  
  45.             if (!c.getModel().getHasContent()) {  
  46.                 totalPage = 1;  
  47.             } else {  
  48.                 if (c.getListChild()) {  
  49.                     quantity = childs;  
  50.                 } else {  
  51.                     if(!c.getListChild() && childs > 0){  
  52.                         quantity=contentsOfParentChannel(c.getId());  
  53.                     }else{  
  54.                         quantity = contentsOfChannel(c.getId());  
  55.                     }  
  56.                 }  
  57.                 if (quantity <= 0) {  
  58.                     totalPage = 1;  
  59.                 } else {  
  60.                     totalPage = (quantity - 1) / c.getPageSize() + 1;  
  61.                 }  
  62.             }  
  63.             for (int i = 1; i <= totalPage; i++) {  
  64.                 filename = c.getStaticFilename(i);  
  65.                 real = realPathResolver.get(filename.toString());  
  66.                 f = new File(real);  
  67.                 parent = f.getParentFile();  
  68.                 if (!parent.exists()) {  
  69.                     parent.mkdirs();  
  70.                 }  
  71.                 tpl = conf.getTemplate(c.getTplChannelOrDef());  
  72.                 String urlStatic = c.getUrlStatic(i);  
  73.                 info = URLHelper.getPageInfo(filename.substring(filename  
  74.                         .lastIndexOf("/")), null);  
  75.                 FrontUtils.frontPageData(i, info.getHref(), info  
  76.                         .getHrefFormer(), info.getHrefLatter(), data);  
  77.                 FrontUtils.putLocation(data, urlStatic);  
  78.                 data.put("channel", c);  
  79.                 try {  
  80.                     // FileWriter不能指定编码确实是个问题,只能用这个代替了。  
  81.                     out = new OutputStreamWriter(new FileOutputStream(f), UTF8);  
  82.                     tpl.process(data, out);  
  83.                     log.info("create static file: {}", f.getAbsolutePath());  
  84.                 } finally {  
  85.                     if (out != null) {  
  86.                         out.close();  
  87.                     }  
  88.                 }  
  89.             }  
  90.             if (++count % 20 == 0) {  
  91.                 session.clear();  
  92.             }  
  93.         }  
  94.         return count;  
  95.     }  

新闻栏目为例

内容页:/WEB-INF/t/cms/www/red/channel/新闻栏目.html

生成的静态页面 D:\tomcat-4.0\webapps\jeecms2012\news\index.html

 转载请标识出处 by chenbo: http://blog.csdn.net/chenbo19867758/article/details/11953539
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值