CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
int count = 0;
int totalPage;
String url, real;
File file, parent;
Content c;
Channel chnl;
CmsSite site;
PageInfo info;
Template tpl;
Writer out = null;
if (data == null) {
data = new HashMap<String, Object>();
}
while (contents.next()) {
c = (Content) contents.get(0);
chnl = c.getChannel();
// 如果是外部链接或者不生成静态页面,则不生成
if (!StringUtils.isBlank(c.getLink()) || !chnl.getStaticContent()) {
continue;
}
// 如果不需要生成静态页面,则不生成
if(!c.getNeedRegenerate()){
continue;
}
site = c.getSite();
tpl = conf.getTemplate(c.getTplContentOrDef());
FrontUtils.frontData(data, site, null, null, null);
data.put("content", c);
data.put("channel", c.getChannel());
totalPage = c.getPageCount();
for (int pageNo = 1; pageNo <= totalPage; pageNo++) {
String txt = c.getTxtByNo(pageNo);
// 内容加上关键字
txt = cmsKeywordMng.attachKeyword(site.getId(), txt);
Paginable pagination = new SimplePage(pageNo, 1, c
.getPageCount());
data.put("pagination", pagination);
url = c.getUrlStatic(pageNo);
info = URLHelper.getPageInfo(url
.substring(url.lastIndexOf("/")), null);
FrontUtils.putLocation(data, url);
FrontUtils.frontPageData(pageNo, info.getHref(), info
.getHrefFormer(), info.getHrefLatter(), data);
data.put("title", c.getTitleByNo(pageNo));
data.put("txt", txt);
data.put("pic", c.getPictureByNo(pageNo));
if (pageNo == 1) {
real = realPathResolver.get(c.getStaticFilename(pageNo));
file = new File(real);
parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
} else {
real = realPathResolver.get(c.getStaticFilename(pageNo));
file = new File(real);
}
try {
// FileWriter不能指定编码确实是个问题,只能用这个代替了。
out = new OutputStreamWriter(new FileOutputStream(file),
UTF8);
tpl.process(data, out);
log.info("create static file: {}", file.getAbsolutePath());
} finally {
if (out != null) {
out.close();
}
}
}
c.setNeedRegenerate(false);
if (++count % 20 == 0) {
session.clear();
}
}
return count;