📄 postwebhandler.java
字号:
} catch ( ObjectNotFoundException ex ) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
throw new ObjectNotFoundException(localizedMessage);
}
int forumID = threadBean.getForumID();
try {
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
throw new ObjectNotFoundException(localizedMessage);
}
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
// user must have been authenticated before he can view pending/disabled threads
permission.ensureIsAuthenticated();
// check normal permission
permission.ensureCanModerateThread(forumID);
int postsPerPage = 10000;
int offset = 0;
Collection postBeans = DAOFactory.getPostDAO().getDisablePosts_inThread_limit(threadID, offset, postsPerPage);
Iterator iterator = postBeans.iterator();
while (iterator.hasNext()) {
PostBean postBean = (PostBean) iterator.next();
// very slow here
/** @todo find a better solution */
MemberBean memberBean = null;
if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
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);
}
}
}
PostBean firstPostBean = DAOFactory.getPostDAO().getFirstPost_inThread(threadID);
if (firstPostBean.getMemberID() != 0 && firstPostBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
MemberBean memberBean = MemberCache.getInstance().getMember_forPublic(firstPostBean.getMemberID());
firstPostBean.setMemberBean(memberBean);
}
request.setAttribute("ThreadBean", threadBean);
request.setAttribute("FirstPostBean", firstPostBean);
request.setAttribute("PostBeans", postBeans);
request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
}
public void processModeratePendingPosts(GenericRequest request)
throws AssertionException, DatabaseException, AuthenticationException,
BadInputException, DatabaseException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
Locale locale = I18nUtil.getLocaleInRequest(request);
// user must have been authenticated before he can moderate pending/disabled posts
permission.ensureIsAuthenticated();
// 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 threadID = -1;
int forumID = -1;
try {
threadID = GenericParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = null;
try {
threadBean = DAOFactory.getThreadDAO().getThread(threadID);
} catch ( ObjectNotFoundException ex ) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
throw new ObjectNotFoundException(localizedMessage);
}
forumID = threadBean.getForumID();
permission.ensureCanModerateThread(forumID);
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
} catch (BadInputException ex) {
// just ignore, in case of use customized client
}
permission.ensureCanModerateThreadInAnyForum();
try {
String prefix = "modpostaction_";
for (Enumeration enumeration = request.getParameterNames(); enumeration.hasMoreElements(); ) {
String param = (String) enumeration.nextElement();
if (param.startsWith(prefix)) {
String modValue = GenericParamUtil.getParameter(request, param, true);
String strPostID = param.substring(prefix.length());
int postID = Integer.parseInt(strPostID);
if (modValue.equals("approve")) {
PostBean postBean = null;
try {
postBean = DAOFactory.getPostDAO().getPost(postID);
} catch(ObjectNotFoundException ex) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object[] {new Integer(postID)});
throw new ObjectNotFoundException(localizedMessage);
}
int currentForumID = postBean.getForumID();
permission.ensureCanModerateThread(currentForumID);
DAOFactory.getPostDAO().updateStatus(postID, PostBean.POST_STATUS_DEFAULT);
} else if (modValue.equals("delete")) {
PostBean postBean = null;
try {
postBean = DAOFactory.getPostDAO().getPost(postID);
} catch(ObjectNotFoundException ex) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object[] {new Integer(postID)});
throw new ObjectNotFoundException(localizedMessage);
}
deletePost(request, postBean);
} else {
// it means ignore, do nothing
}
}
}
} finally {
// now update the forum statistics
if (forumID != -1) {
StatisticsUtil.updateForumStatistics(forumID);
}
// now update the thread statistics
if (threadID != -1) {
StatisticsUtil.updateThreadStatistics(threadID);
}
}
// Now clear the cache
PostCache.getInstance().clear();
ThreadCache.getInstance().clear();
request.setAttribute("ForumID", String.valueOf(forumID));
request.setAttribute("ThreadID", String.valueOf(threadID));
}
/**
* This method is for viewthread page and printthread page
*/
public void prepareViewThread(GenericRequest request)
throws DatabaseException, ObjectNotFoundException, BadInputException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
Locale locale = I18nUtil.getLocaleInRequest(request);
int threadID = GenericParamUtil.getParameterInt(request, "thread");
boolean printAll = GenericParamUtil.getParameterBoolean(request, "printall");
ThreadBean threadBean = null;
try {
threadBean = DAOFactory.getThreadDAO().getThread(threadID);
} catch ( ObjectNotFoundException ex ) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
throw new ObjectNotFoundException(localizedMessage);
}
int forumID = threadBean.getForumID();
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
// check normal permission
permission.ensureCanReadPost(forumID);
//ForumBean forumBean = null;
try {
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
throw new ObjectNotFoundException(localizedMessage);
}
// Only moderator can view disable threads
if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
permission.ensureCanModerateThread(forumID);
}
int postsPerPage = onlineUser.getPostsPerPage();
int offset = 0;
boolean lastPage = GenericParamUtil.getParameterBoolean(request, "lastpage");
if (lastPage) {
// note that in the worst case, numberOfPosts could equals 0 (bad database)
int pageCount = numberOfPosts / postsPerPage;
int odd = numberOfPosts % postsPerPage;
if (odd > 0) {
pageCount++;
}
if (pageCount < 1) {
pageCount = 1;// at least, there is one page
}
offset = (pageCount-1) * postsPerPage;
} else {
try {
offset = GenericParamUtil.getParameterInt(request, "offset");
} catch (BadInputException e) {
// do nothing
}
}
if (printAll) {
postsPerPage = 10000; //We assume that big number
offset = 0;
}
Collection postBeans = PostCache.getInstance().getEnablePosts_inThread_limit(threadID, offset, postsPerPage);
Iterator iterator = postBeans.iterator();
while(iterator.hasNext()) {
PostBean postBean = (PostBean)iterator.next();
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -