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);