📄 document.java
字号:
pstmt.close();
} catch (Exception e) {}
pstmt = null;
}*/
if (conn != null) {
conn.close();
conn = null;
}
}
}
public String toString() {
return "Document " + id + ":" + title;
}
private boolean canComment = true;
public boolean getCanComment() {
return canComment;
}
public int getType() {
return type;
}
public String getVoteOption() {
return voteOption;
}
public int getExamine() {
return this.examine;
}
public void setExamine(int e) {
this.examine = e;
}
public void setNick(String nick) {
this.nick = nick;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public void setIsRelateShow(boolean isRelateShow) {
this.isRelateShow = isRelateShow;
}
public void setHit(int hit) {
this.hit = hit;
}
public void setTemplateId(int templateId) {
this.templateId = templateId;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public void setParentCode(String parentCode) {
this.parentCode = parentCode;
}
public void setIsNew(int isNew) {
this.isNew = isNew;
}
public void setAuthor(String author) {
this.author = author;
}
public void setFlowTypeCode(String flowTypeCode) {
this.flowTypeCode = flowTypeCode;
}
public void setColor(String color) {
this.color = color;
}
public void setBold(boolean bold) {
this.bold = bold;
}
public void setExpireDate(java.util.Date expireDate) {
this.expireDate = expireDate;
}
public void setSource(String source) {
this.source = source;
}
public void setPageTemplateId(int pageTemplateId) {
this.pageTemplateId = pageTemplateId;
}
public String getVoteResult() {
return voteResult;
}
public String getNick() {
return nick;
}
public java.util.Date getModifiedDate() {
return this.modifiedDate;
}
public boolean vote(int id, int votesel) throws
ErrMsgException {
boolean re = false;
Conn conn = new Conn(connname);
try {
String[] rlt = voteResult.split("\\|");
int len = rlt.length;
int[] intre = new int[len];
for (int i = 0; i < len; i++)
intre[i] = Integer.parseInt(rlt[i]);
intre[votesel]++;
String result = "";
for (int i = 0; i < len; i++) {
if (result.equals(""))
result = "" + intre[i];
else
result += "|" + intre[i];
}
String sql = "update document set voteresult=" +
StrUtil.sqlstr(result)
+ " where id=" + id;
logger.info(sql);
re = conn.executeUpdate(sql) == 1 ? true : false;
// 更新缓存
DocCacheMgr dcm = new DocCacheMgr();
dcm.refreshUpdate(id);
} catch (SQLException e) {
logger.error("vote:" + e.getMessage());
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return re;
}
/**
* Returns a block of threadID's from a query and performs transparent
* caching of those blocks. The two parameters specify a database query
* and a startIndex for the results in that query.
*
* @param query the SQL thread list query to cache blocks from.
* @param startIndex the startIndex in the list to get a block for.
*/
protected long[] getDocBlock(String query, String groupKey, int startIndex) {
DocCacheMgr dcm = new DocCacheMgr();
return dcm.getDocBlock(query, groupKey, startIndex);
}
public DocBlockIterator getDocuments(String query, String groupKey,
int startIndex,
int endIndex) {
if (!SecurityUtil.isValidSql(query))
return null;
// 可能取得的infoBlock中的元素的顺序号小于endIndex
long[] docBlock = getDocBlock(query, groupKey, startIndex);
return new DocBlockIterator(docBlock, query, groupKey,
startIndex, endIndex);
}
/**
*
* @param sql String
* @return int -1 表示sql语句不合法
*/
public int getDocCount(String sql) {
DocCacheMgr dcm = new DocCacheMgr();
return dcm.getDocCount(sql);
}
public Document getDocument(int id) {
DocCacheMgr dcm = new DocCacheMgr();
return dcm.getDocument(id);
}
private int type = 0;
private String voteOption;
private String voteResult;
private String nick;
public String getKeywords() {
return keywords;
}
public boolean getIsRelateShow() {
return isRelateShow;
}
private String keywords;
private boolean isRelateShow;
private boolean loaded = false;
public boolean isLoaded() {
if (id==-1)
return false;
return loaded;
}
public int getHit() {
return hit;
}
public int getTemplateId() {
return templateId;
}
public int getPageCount() {
return pageCount;
}
public String getParentCode() {
return parentCode;
}
public int getIsNew() {
return isNew;
}
public String getAuthor() {
return author;
}
public String getFlowTypeCode() {
return flowTypeCode;
}
public String getColor() {
return color;
}
public boolean isBold() {
return bold;
}
public java.util.Date getExpireDate() {
return expireDate;
}
public String getSource() {
return source;
}
public int getPageTemplateId() {
return pageTemplateId;
}
private int hit = 0;
private int templateId = NOTEMPLATE;
public boolean AddContentPage(ServletContext application,
CMSMultiFileUploadBean mfu, String content) throws
ErrMsgException {
String action = StrUtil.getNullStr(mfu.getFieldValue("action"));
int afterpage = -1;
if (action.equals("insertafter")) {
String insafter = StrUtil.getNullStr(mfu.getFieldValue("afterpage"));
if (StrUtil.isNumeric(insafter))
afterpage = Integer.parseInt(insafter);
}
int pageNo = 1;
if (afterpage!=-1)
pageNo = afterpage + 1;
else
pageNo = pageCount + 1;
String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(
"isuploadfile"));
DocContent dc = new DocContent();
if (isuploadfile.equals("false")) {
if (dc.createWithoutFile(application, mfu, id, content, pageNo)) {
pageCount++;
return UpdatePageCount(pageCount);
}
}
else {
if (dc.create(application, mfu, id, content, pageNo)) {
pageCount++;
return UpdatePageCount(pageCount);
}
}
return false;
}
public boolean EditContentPage(ServletContext application,
CMSMultiFileUploadBean mfu) throws ErrMsgException {
String strpageNum = StrUtil.getNullStr(mfu.getFieldValue("pageNum"));
int pageNum = Integer.parseInt(strpageNum);
DocContent dc = new DocContent();
dc = dc.getDocContent(id, pageNum);
dc.setContent(content);
dc.save(application, mfu);
return true;
}
public synchronized boolean UpdatePageCount(int pagecount) throws
ErrMsgException {
String sql = "update document set modifiedDate=?,page_count=? where id=?";
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
try {
//更新文件内容
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "" + System.currentTimeMillis());
pstmt.setInt(2, pagecount);
pstmt.setInt(3, id);
conn.executePreUpdate();
// 更新缓存
DocCacheMgr dcm = new DocCacheMgr();
dcm.refreshUpdate(id);
} catch (SQLException e) {
logger.error(e.getMessage());
throw new ErrMsgException("DB operate error.");
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return true;
}
private int pageCount = 1;
private String parentCode;
public Vector getAttachments(int pageNum) {
DocContent dc = new DocContent();
dc = dc.getDocContent(id, pageNum);
if (dc==null)
return null;
return dc.getAttachments();
}
public Attachment getAttachment(int pageNum, int att_id) {
Iterator ir = getAttachments(pageNum).iterator();
while (ir.hasNext()) {
Attachment at = (Attachment)ir.next();
if (at.getId()==att_id)
return at;
}
return null;
}
public Document getTemplate() {
if (templateId == this.NOTEMPLATE)
return null;
else
return getDocument(templateId);
}
public boolean uploadDocument(FileUpload TheBean) throws
ResKeyException {
String strdocId = StrUtil.getNullStr(TheBean.getFieldValue("doc_id"));
String strfileId = StrUtil.getNullStr(TheBean.getFieldValue("file_id"));
int docId = Integer.parseInt(strdocId);
int fileId = Integer.parseInt(strfileId);
DocumentMgr dm = new DocumentMgr();
Document doc = dm.getDocument(docId);
Attachment att = doc.getAttachment(1, fileId);
if (att == null) {
throw new ResKeyException("res.cms.Document", "err_att_not_found", new Object[] {"" + docId, "" + fileId} );
// throw new ErrMsgException("取文件" + docId + "的附件" + fileId + "时,未找到!");
}
Vector v = TheBean.getFiles();
if (v.size()>0) {
FileInfo fi = (FileInfo) v.get(0);
String fullPath = Global.getRealPath() + att.getVisualPath() + "/";
fi.write(fullPath, att.getDiskName());
return true;
}
else
return false;
}
public int getId() {
return id;
}
public java.util.Date getCreateDate() {
return createDate;
}
public void setId(int id) {
this.id = id;
}
public void setCreateDate(java.util.Date createDate) {
this.createDate = createDate;
}
public String getDocHtmlPath() {
java.util.Date d = getCreateDate();
Calendar cal = Calendar.getInstance();
cal.setTime(d);
String year = "" + (cal.get(cal.YEAR));
String month = "" + (cal.get(cal.MONTH) + 1);
return "doc" + "/" + year + "/" + month;
}
public String getDocHtmlName(int pageNum) {
Config cfg = new Config();
return getDocHtmlPath() + "/" + getId() + "_" + pageNum + "." + cfg.getProperty("cms.html_ext");
}
private int isNew = 0;
private String author;
private String flowTypeCode = "";
private String color;
private boolean bold = false;
private java.util.Date expireDate;
private String source;
private int pageTemplateId = -1; // -1表示使用目录节点的模板
private java.util.Date createDate;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -