📄 threadwebhandler.java
字号:
// Note that because this forumBeans is a new instance
// we have to put it in session instead of get it again from the ForumCache
request.setAttribute("ForumBeans", forumBeans);
request.setAttribute("PendingThreadCount", new Integer(pendingThreadCount));
request.setAttribute("ThreadsWithPendingPostsCount", new Integer(threadsWithPendingPostsCount));
}
public void prepareModeratePendingThreads_inForum_limit(GenericRequest request)
throws AssertionException, DatabaseException, AuthenticationException, BadInputException,
DatabaseException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// user must have been authenticated before he can view pending/disabled threads
permission.ensureIsAuthenticated();
int forumID = GenericParamUtil.getParameterInt(request, "forum");
// make sure there is the forum
// will throw an BadInputException if there is not this forum
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
permission.ensureCanModerateThread(forumID);
Locale locale = I18nUtil.getLocaleInRequest(request);
// for sort and order stuff
String sort = GenericParamUtil.getParameter(request, "sort");
String order = GenericParamUtil.getParameter(request, "order");
if (sort.length() == 0) sort = "ThreadLastPostDate";
if (order.length()== 0) order = "DESC";
int postsPerPage = onlineUser.getPostsPerPage();
int offset = 0;
try {
offset = GenericParamUtil.getParameterInt(request, "offset");
} catch (BadInputException e) {
// do nothing
}
int totalThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
if (offset > totalThreads) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
throw new BadInputException(localizedMessage);
//throw new BadInputException("The offset is not allowed to be greater than total rows.");
}
Collection threadBeans = DAOFactory.getThreadDAO().getDisableThreads_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);
Collection firstPostBeans = new ArrayList();
for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
ThreadBean threadBean = (ThreadBean)iterator.next();
PostBean postBean = DAOFactory.getPostDAO().getFirstPost_inThread(threadBean.getThreadID());
firstPostBeans.add(postBean);
MemberBean memberBean = null;
if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
// Use cache for maximum performance
memberBean = MemberCache.getInstance().getMember_forPublic(postBean.getMemberID());
}
postBean.setMemberBean(memberBean);
int postAttachCount = postBean.getPostAttachCount();
if ((postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) {
int postID = postBean.getPostID();
Collection attachBeans = DAOFactory.getAttachmentDAO().getAttachments_inPost(postID);
int actualAttachCount = attachBeans.size();
// now check if the attachCount in talbe Post equals to the actual attachCount in table Attachment
if (postAttachCount != actualAttachCount) {
if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfAttachments_inPost(postID)) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.serious_error.cannot_process_attachment_count");
throw new AssertionException(localizedMessage);
//throw new AssertionException("AssertionException: Serious error: cannot process Attachment Count in table Attachment");
}
log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " +
postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount);
DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount);
}
if (actualAttachCount > 0) {
postBean.setAttachmentBeans(attachBeans);
}
}
}
request.setAttribute("FirstPostBeans", firstPostBeans);
request.setAttribute("ThreadBeans", threadBeans);
request.setAttribute("TotalThreads", new Integer(totalThreads));
}
public void processModeratePendingThreads(GenericRequest request)
throws AssertionException, DatabaseException, AuthenticationException,
BadInputException, DatabaseException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// user must have been authenticated before he can moderate pending/disabled threads
permission.ensureIsAuthenticated();
Locale locale = I18nUtil.getLocaleInRequest(request);
// check normal permission, note that we dont check
// permission on a forumID because we allow moderate posts
// in multiple forums even if the web interface does not support it
int forumID = -1;
try {
forumID = GenericParamUtil.getParameterInt(request, "forum");
ForumCache.getInstance().getBean(forumID);// check valid forumID
permission.ensureCanModerateThread(forumID);
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
} catch (BadInputException ex) {
// just ignore, in case of use customized client
}
permission.ensureCanModerateThreadInAnyForum();
try {
String prefix = "modthreadaction_";
for (Enumeration enumeration = request.getParameterNames(); enumeration.hasMoreElements(); ) {
String param = (String) enumeration.nextElement();
if (param.startsWith(prefix)) {
String modValue = GenericParamUtil.getParameter(request, param, true);
String strThreadID = param.substring(prefix.length());
int threadID = Integer.parseInt(strThreadID);
if (modValue.equals("approve")) {
ThreadBean threadBean = null;
try {
threadBean = DAOFactory.getThreadDAO().getThread(threadID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
throw new ObjectNotFoundException(localizedMessage);
}
int currentForumID = threadBean.getForumID();
permission.ensureCanModerateThread(currentForumID);
DAOFactory.getThreadDAO().updateThreadStatus(threadID, ThreadBean.THREAD_STATUS_DEFAULT);
// now if change from Disable to Enable, update the lastpostdate so
// that the Watch will see this thread as a new thread
if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED ) {
Timestamp now = DateUtil.getCurrentGMTTimestamp();
DAOFactory.getThreadDAO().updateLastPostDate(threadID, now);
}
} else if (modValue.equals("delete")) {
ThreadBean threadBean = null;
try {
threadBean = DAOFactory.getThreadDAO().getThread(threadID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
throw new ObjectNotFoundException(localizedMessage);
}
deleteThread(request, threadBean);
} else {
// it means ignore, do nothing
}
}
}
} finally {
// now update the forum statistics
if (forumID != -1) {
StatisticsUtil.updateForumStatistics(forumID);
}
}
// Now clear the cache
PostCache.getInstance().clear();
ThreadCache.getInstance().clear();
request.setAttribute("ForumID", String.valueOf(forumID));
}
public void prepareList_inFavorite(GenericRequest request)
throws DatabaseException, AssertionException, AuthenticationException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureIsAuthenticated();
int memberID = onlineUser.getMemberID();
Collection threadBeans = DAOFactory.getThreadDAO().getThreads_inFavorite_inMember(memberID);
//remove threads that current user dont have permission
for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
ThreadBean threadBean = (ThreadBean)iter.next();
int currentForumID = threadBean.getForumID();
if (permission.canReadPost(currentForumID) == false) {
iter.remove();
} else if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
if (permission.canModerateThread(currentForumID) == false) {
iter.remove();
}
} else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
iter.remove();
}
}
int max = MVNForumConfig.getMaxFavoriteThread();
int favoriteThreadCount = threadBeans.size();
double ratio = 0;
if (max == 0) {
ratio = 1.0;
} else {
ratio = (double)favoriteThreadCount / max;
}
request.setAttribute("QuotaRatio", new Double(ratio * 100));
request.setAttribute("ThreadBeans", threadBeans);
}
public void prepareRSSSummary(GenericRequest request)
throws DatabaseException {
// for sort and order stuff
String sort = GenericParamUtil.getParameter(request, "sort");
String order = GenericParamUtil.getParameter(request, "order");
if (sort.length() == 0) sort = "ThreadLastPostDate";
if (order.length()== 0) order = "DESC";
// call this to check the parameter sort and order
DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(0/*offset*/, 1/*rows*/, sort, order);
}
void prepareListRSS(HttpServletRequest request)
throws DatabaseException, AssertionException,
AuthenticationException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// for sort and order stuff
String sort = ParamUtil.getParameter(request, "sort");
String order = ParamUtil.getParameter(request, "order");
if (sort.length() == 0) sort = "ThreadLastPostDate";
if (order.length()== 0) order = "DESC";
int offset = 0;// offset MUST always equals 0, please dont change !!!
int rows = MVNForumConfig.getRowsPerRSS();
try {
rows = ParamUtil.getParameterInt(request, "rows");
if (rows <= 0) rows = MVNForumConfig.getRowsPerRSS();
} catch (Exception ex) {
//just ignore
}
// now find that user want global/category/forum RSS
int forumID = -1;
int categoryID = -1;
try {
forumID = ParamUtil.getParameterInt(request, "forum");
} catch (Exception ex) {
try {
categoryID = ParamUtil.getParameterInt(request, "category");
} catch (Exception ex1) { }
}
Collection threadBeans = null;
if (forumID > 0) {
if (permission.canReadPost(forumID)) {
threadBeans = DAOFactory.getThreadDAO().getAllEnableThreads_inForum_withSortSupport_limit(forumID, offset, rows, sort, order);
} else {
// dont have permission on this forum, just create empty Collection
threadBeans = new ArrayList();
}
} else if (categoryID > 0) {
//@todo implement later
} else {// global RSS
threadBeans = DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(offset, rows, sort, order);
//remove threads that current user dont have permission
for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
ThreadBean threadBean = (ThreadBean)iter.next();
int currentForumID = threadBean.getForumID();
if (permission.canReadPost(currentForumID) == false) {
iter.remove();
} else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
iter.remove();
}
}
}
request.setAttribute("ThreadBeans", threadBeans);
request.setAttribute("ForumID", new Integer(forumID));
request.setAttribute("CategoryID", new Integer(categoryID));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -