Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7591312 建立时间:2006年5月29日 |

| |
[FreeMarker]使用freemarker给cms生成静态html 软件技术
lhwork 发表于 2006/12/15 12:20:35 |
作为CMS内容发布来说,将要显示的内容html化无疑是一个很基本的要求,这样可以提高整个系统的效率。考虑一个内容节点Content,其中节点有个pagecontent的属性,这个属性用来存储用户在后台输入的内容,内容+模板=显示,这里是:内容+模板-->显示静态html内容用FCK来编辑,模板也同样用FCK编辑,这里用freemarker无疑是一个好的选择。这里是个最简单的例子。首先定义一个最简单的模板content.ftl500)this.width=500'><html>500)this.width=500'>500)this.width=500'>$500)this.width=500'>{content}500)this.width=500'></html>然后就是把内容填充进去:500)this.width=500'> Configuration cfg = new Configuration();500)this.width=500'> //模板存储的目录500)this.width=500'> cfg.setDirectoryForTemplateLoading(Path.getTemplateDirectory());500)this.width=500'> //默认500)this.width=500'> cfg.setObjectWrapper(new DefaultObjectWrapper());500)this.width=500'>//填充数据 500)this.width=500'>Map root = new HashMap();500)this.width=500'>root.put("content", c.getPageContent());500)this.width=500'> Template temp = cfg.getTemplate("content.ftl");500)this.width=500'>//发布日期500)this.width=500'>String date=c.getActivedate();500)this.width=500'>String filename = c.getId()+".html";500)this.width=500'>//创建目录500)this.width=500'>Path.createFold(Path.getWebCmsHtmlDirPath(),date);500)this.width=500'>Writer out = new OutputStreamWriter(new FileOutputStream(Path.getWebCmsHtmlDirPath()+"/"+date+"/"+filename));500)this.width=500'>temp.process(root, out);500)this.width=500'>out.flush();其实就是这么简单!对html的管理就很容易了,基本的FILE操作 |
|
|