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

StaticPageDaoImpl 中

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

public int channelStatic(Integer siteId, Integer channelId,
			boolean containChild, Configuration conf, Map<String, Object> data)
			throws IOException, TemplateException {
		Finder finder = Finder.create("select bean from Channel bean");
		if (channelId != null) {
			if (containChild) {
				finder.append(",Channel parent where").append(
						" bean.lft between parent.lft and parent.rgt").append(
						" and parent.site.id=bean.site.id").append(
						" and parent.id=:channelId");
				finder.setParam("channelId", channelId);
			} else {
				finder.append(" where bean.id=:channelId");
				finder.setParam("channelId", channelId);
			}
		} else if (siteId != null) {
			finder.append(" where bean.site.id=:siteId");
			finder.setParam("siteId", siteId);
		}
		Session session = getSession();
		ScrollableResults channels = finder.createQuery(session).setCacheMode(
				CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
		int count = 0;
		CmsSite site;
		Channel c;
		PageInfo info;
		Writer out = null;
		Template tpl;
		String real, filename;
		File f, parent;
		int quantity, totalPage;
		if (data == null) {
			data = new HashMap<String, Object>();
		}
		while (channels.next()) {
			c = (Channel) channels.get(0);
			site = c.getSite();
			FrontUtils.frontData(data, site, null, null, null);
			// 如果是外部链接或者不需要生产静态页,则不生成
			if (!StringUtils.isBlank(c.getLink()) || !c.getStaticChannel()) {
				continue;
			}
			// 没有内容或者有子栏目,则只生成一页
			int childs = childsOfChannel(c.getId());
			if (!c.getModel().getHasContent()) {
				totalPage = 1;
			} else {
				if (c.getListChild()) {
					quantity = childs;
				} else {
					if(!c.getListChild() && childs > 0){
						quantity=contentsOfParentChannel(c.getId());
					}else{
						quantity = contentsOfChannel(c.getId());
					}
				}
				if (quantity <= 0) {
					totalPage = 1;
				} else {
					totalPage = (quantity - 1) / c.getPageSize() + 1;
				}
			}
			for (int i = 1; i <= totalPage; i++) {
				filename = c.getStaticFilename(i);
				real = realPathResolver.get(filename.toString());
				f = new File(real);
				parent = f.getParentFile();
				if (!parent.exists()) {
					parent.mkdirs();
				}
				tpl = conf.getTemplate(c.getTplChannelOrDef());
				String urlStatic = c.getUrlStatic(i);
				info = URLHelper.getPageInfo(filename.substring(filename
						.lastIndexOf("/")), null);
				FrontUtils.frontPageData(i, info.getHref(), info
						.getHrefFormer(), info.getHrefLatter(), data);
				FrontUtils.putLocation(data, urlStatic);
				data.put("channel", c);
				try {
					// FileWriter不能指定编码确实是个问题,只能用这个代替了。
					out = new OutputStreamWriter(new FileOutputStream(f), UTF8);
					tpl.process(data, out);
					log.info("create static file: {}", f.getAbsolutePath());
				} finally {
					if (out != null) {
						out.close();
					}
				}
			}
			if (++count % 20 == 0) {
				session.clear();
			}
		}
		return count;
	}

新闻栏目为例

内容页:/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
    评论
jeecms v9.3 是一个开源的内容管理系统(CMS),可用于构建和管理各种类型的网站。想要下载这个版本的源代码,你可以按照以下步骤进行操作。 首先,打开 jeecms 官方网站,通常可以通过搜索引擎进行查找。在官方网站上,你可以找到 jeecms 的下载面。 进入下载面后,你会看到可供下载的不同版本。找到 jeecms v9.3 版本,并点击下载按钮。通常,下载按钮会提供一个压缩包文件以供下载。 下载完成后,解压缩该文件到你选择的目录。解压缩后,你将获得 jeecms v9.3 版本的源代码。 接下来,你可以使用一个适用的集成开发环境(IDE)打开源代码。常见的 IDE 包括 Eclipse、IntelliJ IDEA 等。确保你已经在计算机上安装并配置好了所选的 IDE。 在 IDE 中创建一个新的项目,并将源码导入该项目。具体导入方式取决于你所使用的 IDE。 导入完成后,你可以开始使用 jeecms v9.3 版本的源代码。根据自己的需求进行定制和开发,如修改面布局、添加功能模块等。 要注意的是,下载和使用 jeecms v9.3 版本的源代码需要遵守相关的开源许可协议,如 GPL。请确保你了解并遵守这些许可协议,以确保合法使用。此外,根据你的技术水平和需求,你可能需要一些基础的编程知识和技能来使用和定制 jeecms。 总之,下载 jeecms v9.3 版本的源代码很简单,只需访问官方网站,下载压缩包文件并解压缩即可。然后,使用适用的开发环境导入源代码,即可开始使用和定制 jeecms

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值