?? dlog_diary_velocitytool.java
字號(hào):
/*
* DLOG_Diary_VelocityTool.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Winter Lau
* http://dlog4j.sourceforge.net
*
*/
package com.liusoft.dlog4j.velocity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import com.liusoft.dlog4j.DLOG_CacheManager;
import com.liusoft.dlog4j.SessionUserObject;
import com.liusoft.dlog4j.TextCacheManager;
import com.liusoft.dlog4j.base._DiaryBase;
import com.liusoft.dlog4j.beans.CatalogBean;
import com.liusoft.dlog4j.beans.DiaryBean;
import com.liusoft.dlog4j.beans.DiaryOutlineBean;
import com.liusoft.dlog4j.beans.DiaryReplyBean;
import com.liusoft.dlog4j.beans.SiteBean;
import com.liusoft.dlog4j.dao.CatalogDAO;
import com.liusoft.dlog4j.dao.DiaryDAO;
import com.liusoft.dlog4j.dao.FCKUploadFileDAO;
import com.liusoft.dlog4j.dao.ReplyDAO;
/**
* 日記相關(guān)的Toolbox類(lèi)
* @author liudong
*/
public class DLOG_Diary_VelocityTool{
final static Log log = LogFactory.getLog(DLOG_Diary_VelocityTool.class);
private final static String CACHE_KEY = "dlog_home_info";
/**
* 列出最熱門(mén)的專(zhuān)欄文章
* @param days
* @param count
* @return
*/
public List list_hot_articles(SiteBean site, int days, int count){
if(site==null)
return null;
StringBuffer nKey = new StringBuffer("hot_articles_");
nKey.append(site.getId());
nKey.append('_');
nKey.append(days);
nKey.append('_');
nKey.append(count);
List articles = (List)DLOG_CacheManager.getObjectCached(CACHE_KEY, nKey.toString());
if(articles == null){
articles = DiaryDAO.listHotArticles(site.getId(), days, count);
if(articles==null || articles.size()==0){
articles = DiaryDAO.listHotArticles(site.getId(), days * 100, count);
}
else
if(articles.size() < count){
List others = DiaryDAO.listHotArticlesBefore(site.getId(),
days, count - articles.size());
articles.addAll(others);
}
DLOG_CacheManager.putObjectCached(CACHE_KEY, nKey, (Serializable)articles);
}
return articles;
}
/**
* 列出當(dāng)前已經(jīng)上傳的附件
* @param session_id
* @return
*/
public List attachments(SessionUserObject user, String session_id){
if(user == null)
return null;
return FCKUploadFileDAO.listOrphanFiles(user.getId(), session_id);
}
/**
* 訪問(wèn)某個(gè)評(píng)論內(nèi)容
* @param site
* @param reply_id
* @return
*/
public DiaryReplyBean reply(int reply_id){
if(reply_id < 0)
return null;
return (DiaryReplyBean)ReplyDAO.getReply(DiaryReplyBean.class, reply_id);
}
/**
* 判斷用戶(hù)可否有訪問(wèn)指定日記的權(quán)限并返回日記詳細(xì)資料(showlog.vm)
*
* @param site
* @param user
* @param log_id
* @return
* @throws HibernateException
*/
public _DiaryBase diary(SiteBean site, SessionUserObject user, int log_id) {
if (site == null || log_id < 0)
return null;
// 如何將日記的內(nèi)容進(jìn)行緩存,避免從數(shù)據(jù)庫(kù)直接讀取大文本
String text = TextCacheManager.getTextContent(DiaryBean.TYPE_DIARY, log_id);
_DiaryBase diary = null;
if(text==null){
diary = DiaryDAO.getDiaryByID(log_id);
if(diary!=null && diary.getStatus()==DiaryBean.STATUS_NORMAL){
TextCacheManager.updateTextContent(DiaryBean.TYPE_DIARY, log_id, diary.getContent());
}
}
else{
diary = DiaryDAO.getDiaryOutlineByID(log_id);
if(diary!=null)
diary.setContent(text);
}
if (diary == null || diary.getSite().getId() != site.getId())
return null;
if(user!=null && diary.getOwner().getId()==user.getId())
return diary;
if (!CatalogDAO.canUserViewThisCatalog(diary.getCatalog(), user))
return null;
return diary;
}
/**
* 直接讀取某一篇日記
*
* @param log_id
* @return
* @throws HibernateException
*/
public _DiaryBase diary(int log_id) {
if (log_id < 0)
return null;
String text = TextCacheManager.getTextContent(DiaryBean.TYPE_DIARY, log_id);
_DiaryBase diary = null;
if(text==null){
diary = DiaryDAO.getDiaryByID(log_id);
if(diary!=null && diary.getStatus()==DiaryBean.STATUS_NORMAL){
TextCacheManager.updateTextContent(DiaryBean.TYPE_DIARY, log_id, diary.getContent());
}
}
else{
diary = DiaryDAO.getDiaryOutlineByID(log_id);
if(diary!=null)
diary.setContent(text);
}
return diary;
}
/**
* 填充日記內(nèi)容
* @param diary
*/
public void fill_diary_content(_DiaryBase diary){
String text = TextCacheManager.getTextContent(DiaryBean.TYPE_DIARY, diary.getId());
if(text==null){
DiaryBean db = DiaryDAO.getDiaryByID(diary.getId());
diary.setContent(db.getContent());
if(diary!=null && diary.getStatus()==DiaryBean.STATUS_NORMAL){
TextCacheManager.updateTextContent(DiaryBean.TYPE_DIARY, diary.getId(), diary.getContent());
}
}
else{
diary.setContent(text);
}
}
/**
* 獲取上一篇日記(showlog.vm)
* @param site
* @param user
* @param catalog_id
* @param log_id
* @return
*/
public DiaryOutlineBean prev_diary(SiteBean site, SessionUserObject user, int catalog_id, int log_id){
if (site == null || log_id < 0)
return null;
try{
return DiaryDAO.getPrevDiary(site,user,catalog_id,log_id);
}catch(Exception e){
log.error("DLOG_VelocityTool.prev_diary execute failed.", e);
}
return null;
}
/**
* 獲取下一篇日記(showlog.vm)
* @param site
* @param user
* @param catalog_id
* @param log_id
* @return
*/
public DiaryOutlineBean next_diary(SiteBean site, SessionUserObject user, int catalog_id, int log_id){
if (site == null || log_id < 0)
return null;
try{
return DiaryDAO.getNextDiary(site, user, catalog_id, log_id);
}catch(Exception e){
log.error("DLOG_VelocityTool.next_diary execute failed.", e);
}
return null;
}
/**
* 獲取某個(gè)網(wǎng)站最新的一篇日記
* @param site
* @param user
* @param fromIdx
* @param count
* @param withContent
* @return
*/
public List top_diary(SiteBean site, SessionUserObject user, int page, int count, boolean withContent) {
if (site == null)
return null;
return list_diary(site,user,-1,-1,-1,-1,page, count, withContent);
}
/**
* 列出所有上傳的文件(用于管理)
* @param page
* @param count
* @return
*/
public List list_files(int page, int count){
int fromIdx = (page-1)*count;
return FCKUploadFileDAO.listFiles(fromIdx, count);
}
public int file_count(){
return FCKUploadFileDAO.fileCount();
}
/**
* 根據(jù)要求的條件讀取日記(包括日記內(nèi)容)
*
* @param site
* @param user
* @param catalog_id
* @param page
* @param pageSize
* @return
*/
public List list_diary(SiteBean site, SessionUserObject user, int catalog_id, int year,int month,int date,
int page, int pageSize) {
return list_diary(site, user, catalog_id, year,month,date, page, pageSize, true);
}
/**
* 根據(jù)要求的條件讀取日記
*
* @param site
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -