📄 document.java
字号:
isHome = false;
else if (strIsHome.equals("false"))
isHome = false;
else if (strIsHome.equals("true"))
isHome = true;
else
isHome = false;
String strexamine = mfu.getFieldValue("examine");
int oldexamine = examine;
examine = Integer.parseInt(strexamine);
keywords = StrUtil.getNullStr(mfu.getFieldValue("keywords"));
String strisRelateShow = StrUtil.getNullStr(mfu.getFieldValue("isRelateShow"));
int intisRelateShow = 0;
if (StrUtil.isNumeric(strisRelateShow)) {
intisRelateShow = Integer.parseInt(strisRelateShow);
if (intisRelateShow==1)
isRelateShow = true;
}
String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew"));
if (StrUtil.isNumeric(strisnew))
isNew = Integer.parseInt(strisnew);
else
isNew = 0;
String strCanComment = StrUtil.getNullStr(mfu.getFieldValue(
"canComment"));
if (strCanComment.equals(""))
canComment = false;
else if (strCanComment.equals("1"))
canComment = true;
flowTypeCode = StrUtil.getNullStr(mfu.getFieldValue("flowTypeCode"));
color = StrUtil.getNullStr(mfu.getFieldValue("color"));
bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true");
expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"), "yyyy-MM-dd");
source = StrUtil.getNullStr(mfu.getFieldValue("source"));
try {
pageTemplateId = Integer.parseInt(mfu.getFieldValue(
"pageTemplateId"));
}
catch (Exception e) {
pageTemplateId = -1;
}
String docType = StrUtil.getNullStr(mfu.getFieldValue("docType"));
if (!docType.equals("" + TYPE_VOTE)) {
type = Integer.parseInt(docType);
}
if (!dir_code.equals(class1)) {
Leaf lf = new Leaf();
lf = lf.getLeaf(dir_code);
parentCode = lf.getParentCode();
}
Conn conn = new Conn(connname);
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
// 更新文件内容
pstmt = conn.prepareStatement(SAVE_DOCUMENT);
pstmt.setString(1, title);
pstmt.setInt(2, canComment ? 1 : 0);
pstmt.setBoolean(3, isHome);
pstmt.setInt(4, examine);
pstmt.setString(5, keywords);
pstmt.setInt(6, intisRelateShow);
pstmt.setInt(7, templateId);
pstmt.setString(8, dir_code);
pstmt.setInt(9, isNew);
pstmt.setString(10, author);
pstmt.setString(11, flowTypeCode);
pstmt.setString(12, "" + System.currentTimeMillis());
pstmt.setString(13, parentCode);
pstmt.setString(14, color);
pstmt.setInt(15, bold?1:0);
pstmt.setString(16, DateUtil.toLongString(expireDate));
pstmt.setString(17, source);
pstmt.setInt(18, type);
pstmt.setInt(19, pageTemplateId);
// System.out.println(getClass().getName() + " pageTemplateId=" + pageTemplateId);
pstmt.setInt(20, id);
conn.executePreUpdate();
} catch (SQLException e) {
logger.error("update:" + e.getMessage());
throw new ErrMsgException("DB operate error.");
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
// 更新缓存
DocCacheMgr dcm = new DocCacheMgr();
if (oldexamine==examine) {
dcm.refreshUpdate(id);
}
else {
dcm.refreshUpdate(id, class1, parentCode);
}
// 如果是更改了类别
if (!dir_code.equals(class1)) {
dcm.refreshChangeDirCode(class1, dir_code);
class1 = dir_code;
}
// 更新第一页的内容
DocContent dc = new DocContent();
dc = dc.getDocContent(id, 1);
dc.save(application, mfu);
}
return true;
}
public boolean create(ServletContext application,
CMSMultiFileUploadBean mfu, String nick) throws
ResKeyException,ErrMsgException {
String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(
"isuploadfile"));
// 取得表单中域的信息
author = StrUtil.getNullString(mfu.getFieldValue("author"));
title = StrUtil.getNullString(mfu.getFieldValue("title"));
content = StrUtil.getNullString(mfu.getFieldValue("htmlcode"));
String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));
keywords = StrUtil.getNullStr(mfu.getFieldValue("keywords"));
String strisRelateShow = StrUtil.getNullStr(mfu.getFieldValue("isRelateShow"));
int intisRelateShow = 0;
if (StrUtil.isNumeric(strisRelateShow)) {
intisRelateShow = Integer.parseInt(strisRelateShow);
if (intisRelateShow==1)
isRelateShow = true;
}
String strexamine = StrUtil.getNullStr(mfu.getFieldValue("examine"));
if (StrUtil.isNumeric(strexamine)) {
examine = Integer.parseInt(strexamine);
}
else
examine = 0;
String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew"));
if (StrUtil.isNumeric(strisnew))
isNew = Integer.parseInt(strisnew);
else
isNew = 0;
flowTypeCode = StrUtil.getNullStr(mfu.getFieldValue("flowTypeCode"));
// 检查目录节点中是否允许插入文章
Directory dir = new Directory();
// logger.info("update: dir_code=" + dir_code + " title=" + title);
Leaf lf = dir.getLeaf(dir_code);
if (lf.getType() == 0)
throw new ResKeyException("res.cms.Document", "err_dir_type_none");
if (lf.getType() == 1) {
if (getFirstIDByCode(dir_code) != -1)
throw new ResKeyException("res.cms.Document", "err_dir_type_doc_created");
// throw new ErrMsgException("该目录节点为文章节点,且文章已经被创建!");
}
String strCanComment = StrUtil.getNullStr(mfu.getFieldValue(
"canComment"));
if (strCanComment.equals(""))
canComment = false;
else if (strCanComment.equals("1"))
canComment = true;
//logger.info("strCanComment=" + strCanComment);
String strtid = StrUtil.getNullStr(mfu.getFieldValue("templateId"));
if (StrUtil.isNumeric(strtid))
templateId = Integer.parseInt(strtid);
// 投票处理
String docType = mfu.getFieldValue("docType");
String[] voptions = null;
type = TYPE_DOC; // 类型1表示为投票
String voteresult = "", votestr = "";
if (docType.equals("1")) {
type = TYPE_VOTE;
String voteoption = mfu.getFieldValue("vote").trim();
if (!voteoption.equals("")) {
voptions = voteoption.split("\\r\\n");
}
if (voteoption.indexOf("|") != -1)
throw new ResKeyException("res.cms.Document", "err_vote_option");
// throw new ErrMsgException("投票选项中不能包含|");
int len = voptions.length;
for (int k = 0; k < len; k++) {
if (voteresult.equals("")) {
voteresult = "0";
votestr = voptions[k];
} else {
voteresult += "|" + "0";
votestr += "|" + voptions[k];
}
}
}
else if (docType.equals("2")) {
type = TYPE_LINK;
}
color = StrUtil.getNullStr(mfu.getFieldValue("color"));
bold = StrUtil.getNullStr(mfu.getFieldValue("isBold")).equals("true");
expireDate = DateUtil.parse(mfu.getFieldValue("expireDate"), "yyyy-MM-dd");
source = StrUtil.getNullStr(mfu.getFieldValue("source"));
pageTemplateId = Integer.parseInt(mfu.getFieldValue("pageTemplateId"));
// 清缓存
DocCacheMgr dcm = new DocCacheMgr();
dcm.refreshCreate(dir_code, lf.getParentCode());
// 如果不上传文件
if (isuploadfile.equals("false"))
return create(dir_code, title, content, type, votestr, voteresult,
nick, templateId, author);
this.id = (int) SequenceMgr.nextID(SequenceMgr.DOCUMENT);
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
try {
// 插入文章标题及相关设置
parentCode = lf.getParentCode();
pstmt = conn.prepareStatement(INSERT_DOCUMENT);
pstmt.setInt(1, id);
pstmt.setString(2, title);
pstmt.setString(3, dir_code);
pstmt.setInt(4, type);
pstmt.setString(5, votestr);
pstmt.setString(6, voteresult);
pstmt.setString(7, nick);
pstmt.setString(8, keywords);
pstmt.setInt(9, intisRelateShow);
pstmt.setInt(10, canComment?1:0);
pstmt.setInt(11, templateId);
pstmt.setString(12, parentCode);
pstmt.setInt(13, examine);
pstmt.setInt(14, isNew);
pstmt.setString(15, author);
pstmt.setString(16, flowTypeCode);
pstmt.setString(17, "" + System.currentTimeMillis());
pstmt.setString(18, color);
pstmt.setInt(19, bold?1:0);
pstmt.setString(20, DateUtil.toLongString(expireDate));
pstmt.setString(21, source);
pstmt.setInt(22, pageTemplateId);
pstmt.setString(23, "" + System.currentTimeMillis());
conn.executePreUpdate();
pstmt.close();
pstmt = null;
// 插入文章中的内容
DocContent dc = new DocContent();
dc.create(application, mfu, id, content, 1);
} catch (SQLException e) {
logger.error("create:" + e.getMessage());
throw new ResKeyException(SkinUtil.ERR_DB);
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return true;
}
/**
* 用以在不上传图片时直接创建文件
* @param application ServletContext
* @param request HttpServletRequest
* @throws ErrMsgException
*/
public boolean create(String code_class1, String title, String content,
int type, String voteoption, String voteresult,
String nick, int templateId, String author) {
Leaf lf = new Leaf();
lf = lf.getLeaf(code_class1);
parentCode = lf.getParentCode();
Conn conn = new Conn(connname);
this.id = (int) SequenceMgr.nextID(SequenceMgr.DOCUMENT);
try {
// 插入文章标题及相关设置
PreparedStatement pstmt = conn.prepareStatement(INSERT_DOCUMENT);
pstmt.setInt(1, id);
pstmt.setString(2, title);
pstmt.setString(3, code_class1);
pstmt.setInt(4, type);
pstmt.setString(5, voteoption);
pstmt.setString(6, voteresult);
pstmt.setString(7, nick);
pstmt.setString(8, "");
pstmt.setInt(9, 1);
pstmt.setInt(10, canComment?1:0);
pstmt.setInt(11, templateId);
pstmt.setString(12, parentCode);
pstmt.setInt(13, examine);
pstmt.setInt(14, isNew);
pstmt.setString(15, author);
pstmt.setString(16, flowTypeCode);
pstmt.setString(17, "" + System.currentTimeMillis());
pstmt.setString(18, color);
pstmt.setInt(19, bold?1:0);
pstmt.setString(20, DateUtil.toLongString(expireDate));
pstmt.setString(21, source);
pstmt.setInt(22, pageTemplateId);
pstmt.setString(23, "" + System.currentTimeMillis());
conn.executePreUpdate();
// 插入文章中的内容
DocContent dc = new DocContent();
dc.create(id, content);
} catch (SQLException e) {
logger.error(e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return true;
}
public String get(String field) {
if (field.equals("title"))
return getTitle();
else if (field.equals("content"))
return getContent(1);
else if (field.equals("summary"))
return getSummary();
else if (field.equals("id"))
return "" + getID();
else
return "";
}
public boolean del() throws ErrMsgException {
Conn conn = new Conn(connname);
ResultSet rs = null;
try {
// 删除文章中的页
String sql = "select page_num from doc_content where doc_id=" + id;
rs = conn.executeQuery(sql);
if (rs!=null) {
while (rs.next()) {
int pn = rs.getInt(1);
DocContent dc = new DocContent();
dc = dc.getDocContent(id, pn);
dc.del();
}
}
if (rs!=null) {
rs.close();
rs = null;
}
PreparedStatement pstmt = conn.prepareStatement(DEL_DOCUMENT);
pstmt.setInt(1, id);
conn.executePreUpdate();
// 更新缓存
DocCacheMgr dcm = new DocCacheMgr();
dcm.refreshDel(id, class1, parentCode);
} catch (SQLException e) {
logger.error(e.getMessage());
return false;
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return true;
}
private void loadFromDB() {
// Based on the id in the object, get the message data from the database.
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(LOAD_DOCUMENT);
pstmt.setInt(1, id);
rs = conn.executePreQuery();
if (!rs.next()) {
logger.error("Document id= " + id + " not found." + StrUtil.trace(new Exception()));
} else {
this.title = rs.getString(1);
this.class1 = rs.getString(2);
this.modifiedDate = DateUtil.parse(rs.getString(3));
this.canComment = rs.getBoolean(4);
this.summary = rs.getString(5);
this.isHome = rs.getBoolean(6);
this.type = rs.getInt(7);
this.voteOption = rs.getString(8);
this.voteResult = rs.getString(9);
this.examine = rs.getInt(10);
this.nick = rs.getString(11);
this.keywords = rs.getString(12);
this.isRelateShow = rs.getInt(13)==1?true:false;
this.hit = rs.getInt(14);
this.templateId = rs.getInt(15);
this.pageCount = rs.getInt(16);
this.parentCode = rs.getString(17);
this.isNew = rs.getInt(18);
this.author = rs.getString(19);
this.flowTypeCode = rs.getString(20);
color = StrUtil.getNullString(rs.getString(21));
bold = rs.getInt(22)==1;
expireDate = DateUtil.parse(rs.getString(23));
source = StrUtil.getNullStr(rs.getString(24));
pageTemplateId = rs.getInt(25);
createDate = DateUtil.parse(rs.getString(26));
if (createDate==null) // 为了兼容以前未加createDate字段时的文章
createDate = modifiedDate;
loaded = true; // 已初始化
}
} catch (SQLException e) {
logger.error("loadFromDB:" + e.getMessage());
} finally {
/*
if (pstmt != null) {
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -