?? topicaction.java
字號:
forumtopicreply.setLocked(Byte.valueOf(locked));
if (!El.getEl().getForumUserMgr().ReplyTopic(forumtopicreply)) {
ActionErrors errors = new ActionErrors();
errors.add("", new ActionError("forum.reply.errors"));
saveErrors(request, errors);
//System.out.println("錯誤啦");
return (new ActionForward(mapping.getInput()));
}
// 獲取 forumTopic reply + 1
ForumTopic fourmTopic = El.getEl().getTopicMgr().getTopicId(topicId);
fourmTopic.setReply(fourmTopic.getReply() + 1);
El.getEl().getTopicMgr().saveTopic(fourmTopic);
//System.out.println("reply:::::::::::::::::+1");
// 讀出TOPIC FROM PIECE
List<Forumtopicreply> falist = El.getEl().getTopicMgr().findTopicReply(
topicId);
request.setAttribute("reply", falist);
request.setAttribute("pieceId", pieceId);
request.setAttribute("topicId", topicId);
request.setAttribute("pieceTopic", El.getEl().getTopicMgr()
.findPieceTopic(topicId));
// 構造位置,由showTopic..TopicAction.負責
return this.showTopic(mapping, form, request, response);
//return mapping.findForward("showTopic");
}
/*
* 1,如果返回fa是NULL,則沒有文章. 2,構造位置. 3,獲取回復. 4,獲取引用片段. (non-Javadoc)
*
* @see com.elan.forum.actions.topic.TopicBaseAction#quoteReply(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected ActionForward quoteReply(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Integer topicId = getTopicId(request);
ForumTopic fa = El.getEl().getTopicMgr().findPieceTopic(topicId);
if (fa == null) {
ActionErrors errors = new ActionErrors();
// 1 無此帖子
errors.add("", new ActionError("topic.no.find"));
saveErrors(request, errors);
return mapping.findForward("topicNotFind");
}
// 2 //構造路徑
/*String position = constructPosition(request, fa.getPiece().getId(), fa
.getPiece().getName(), fa.getId(), fa.getTitle());
request.setAttribute("position", position);
// 3 獲取回復的帖子
List<Forumtopicreply> falist = El.getEl().getTopicMgr().findTopicReply(
topicId);
ForumUser topicAuthor = fa.getForumUser();
request.setAttribute("topicAuthor", topicAuthor);
request.setAttribute("replyList", falist);
request.setAttribute("topic", fa);
request.setAttribute("pieceId", fa.getPiece().getId());*/
//TEST://System.out.println("pieceId:" + fa.getPiece().getId());
// 4
String quoteStr = request.getParameter("quoteId");
Integer quoteId;
if (quoteStr != null) {
quoteId = (Integer.valueOf(quoteStr));
if (topicId.intValue() != quoteId.intValue()) {
Forumtopicreply ftr = El.getEl().getTopicMgr()
.findTopicReplyById(quoteId);
if (ftr != null) {
request.setAttribute("quoteReply", "以下是引用 ["
+ ftr.getAuthor() + "] 片段:<br>" + ftr.getText());
}
}
} else {
request.setAttribute("quoteReply", "以下是引用 [" + fa.getAuthor()
+ "] 片段:<br>" + fa.getText());
}
//System.out.println("沒有任何的問題哦!");
//return mapping.findForward("showTopic");
//return new ActionForward("topic.do?action=showTopic&topicId=" + topicId);
return this.showTopic(mapping, form, request, response);
}
/**
* 返回熱門帖子
*
* @return ActionForward
*/
@Override
protected ActionForward hotTopic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Integer pieceId = this.getPieceId(request);
String pieceName = null;
Integer topicCount = Constents.hotTopicCount;
if (pieceId != null) {
pieceName = El.getEl().getTopicMgr().getForumPieceById(pieceId)
.getName();
this.setAttribute(request, "pieceId", pieceId);
}
String position = this.constructPosition(request, pieceId, pieceName,
null, null);
if (pieceId != null) {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=hotTopic&pieceId=" + pieceId
+ "\">熱門主題</a>";
} else {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=hotTopic\">熱門主題</a>";
}
List<ForumTopic> list = El.getEl().getTopicMgr().getHotTopic(pieceId,
null, topicCount);
this.setAttribute(request, "position", position);
this.setAttribute(request, "topicCount", topicCount);
this.setAttribute(request, "topicList", list);
return mapping.findForward("hotTopic");
}
/**
*
* 返回新發的帖子
*
* 1, 返回的是全部的新帖子(分頁) 2, 返回的是piece下面的帖子
*
* @return ActionForward
*/
@Override
protected ActionForward newPostTopic(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
Integer pieceId = this.getPieceId(request);
String pieceName = null;
if (pieceId != null) {
pieceName = El.getEl().getTopicMgr().getForumPieceById(pieceId)
.getName();
this.setAttribute(request, "pieceId", pieceId);
}
List<ForumTopic> list = El.getEl().getTopicMgr().getNewPostTopic(
pieceId, null, Constents.newPostTopicPageSize);
String position = this.constructPosition(request, pieceId, pieceName,
null, null);
if (pieceId != null) {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=newPostTopic&pieceId=" + pieceId
+ "\">新帖</a>";
} else {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=newPostTopic\">新帖</a>";
}
this.setAttribute(request, "position", position);
this.setAttribute(request, "topicList", list);
this.setAttribute(request, "pageSize", Constents.newPostTopicPageSize);
this.setAttribute(request, "topicCount", Constents.newPostTopicCount);
return mapping.findForward("newPostTopic");
}
/**
* 1)查詢 搜索
*/
@Override
protected ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//總頁數
Integer pageCount = 0;
//頁碼大小
Integer pageSize = Constents.searchPageSize;
//送搜索出來的記錄
Integer topicCount = 0;
//當前頁面
Integer page = this.getPage(request);//如果< 0 則為1
//獲取數據
String pieceName = null;
Integer hotReal = null; // 全部范圍,1最新,2新華
Integer moduleId = this.getModuleId(request);
Integer pieceId = this.getPieceId(request);
Integer topicId = this.getTopicId(request);
Integer precision = 2; // 模糊搜索
if (pieceId != null && pieceId > 0) {
Forumpiece fe = El.getEl().getTopicMgr().getForumPieceById(pieceId);
pieceName = fe == null ? "" : fe.getName();
}
String position = this.constructPosition(request, pieceId, pieceName,
null, null);
if (pieceId != null && pieceId > 0) {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=search&pieceId=" + pieceId
+ "\">論壇搜索</a>";
} else {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=search\">論壇搜索</a>";
}
String isSearch = request.getParameter("isSearch");
String fastSearch = request.getParameter("fastSearch");
// 獲取module,piece信息,以用于在JSP中的select控件使用
List<Forummodule> listModule = El.getEl().getTopicMgr().getModule();
List<Forumpiece> listPiece = El.getEl().getTopicMgr().getpiece();
// 快速搜索
if ("true".equals(fastSearch)) {
String keyword = request.getParameter("keyword");
String topicName = keyword;
String author = null;
Timestamp startTime = null;
Timestamp endTime = null;
Map<String, Object> map = null;
List<ForumTopic> listTopic = null;
if (topicName != null && !"".equals(topicName.trim())) {
map = El.getEl().getTopicMgr().search(moduleId, pieceId,
topicId, hotReal, topicName, author, startTime,
endTime, precision, page, pageSize);
if(map != null) {
listTopic = (List<ForumTopic>) map.get("listTopic");
topicCount = (Integer) map.get("topicCount");
page = (Integer) map.get("page");
pageSize = (Integer) map.get("pageSize");
pageCount = (Integer) map.get("pageCount");
}
} else {
ActionErrors errors = new ActionErrors();
errors.add("", new ActionError("search keyword must not null"));
saveErrors(request, errors);
}
this.setAttribute(request, "position", position);
this.setAttribute(request, "listModule", listModule);
this.setAttribute(request, "listPiece", listPiece);
this.setAttribute(request, "listTopic", listTopic);
this.setAttribute(request, "pieceId", pieceId);
this.setAttribute(request, "moduleId", moduleId);
this.setAttribute(request, "topicId", topicId);
this.setAttribute(request, "page", page);
this.setAttribute(request, "pageSize", pageSize);
this.setAttribute(request, "topicCount", topicCount);
this.setAttribute(request, "hotReal", hotReal);
return mapping.findForward("search");
}
// 1
if ("true".equals(isSearch)) {
if (request.getParameter("precision") != null) {
precision = Integer.valueOf(request.getParameter("precision"));
}
if (request.getParameter("topic") != null
&& !"".equals(request.getParameter("topic").trim())) {
topicId = Integer.valueOf(request.getParameter("topic"));
}
if (request.getParameter("hotReal") != null
&& !"".equals((request.getParameter("hotReal").trim()))) {
hotReal = Integer.valueOf(request.getParameter("hotReal"));
}
String topicName = null;
if (request.getParameter("topicName") != null
&& !"".equals((request.getParameter("topicName").trim()))) {
topicName = request.getParameter("topicName");
}
String author = null;
if (request.getParameter("author") != null
&& !"".equals((request.getParameter("author").trim()))) {
author = request.getParameter("author");
}
Timestamp startTime = this.createTimestamp(request, 1);
Timestamp endTime = this.createTimestamp(request, 2);
System.out.println("topic moduleId " + moduleId);
System.out.println("topic pieceId " + pieceId);
System.out.println("topic topicId " + topicId);
System.out.println("topic topicName " + topicName);
System.out.println("topic author " + author);
System.out.println("topic hotReal " + hotReal);
if ((moduleId == null || -1 == moduleId)
&& (pieceId == null || -1 == pieceId ) && topicId == null
&& topicName == null
&& author == null
&& (hotReal == null|| -1 == hotReal)) {
ActionErrors errors = new ActionErrors();
errors.add("", new ActionError("choose a one"));
saveErrors(request, errors);
this.setAttribute(request, "position", position);
this.setAttribute(request, "listModule", listModule);
this.setAttribute(request, "listPiece", listPiece);
this.setAttribute(request, "moduleId", moduleId);
this.setAttribute(request, "topicId", topicId);
this.setAttribute(request, "pieceId", pieceId);
this.setAttribute(request, "page", page);
this.setAttribute(request, "pageSize", pageSize);
this.setAttribute(request, "topicCount", topicCount);
this.setAttribute(request, "hotReal", hotReal);
return mapping.findForward("search");
}
Map<String, Object> map = El.getEl().getTopicMgr().search(
moduleId, pieceId, topicId, hotReal, topicName, author,
startTime, endTime, precision, page, pageSize);
List<ForumTopic> listTopic = null;
if(map != null) {
System.out.println("sdfsdfsdfsdfdsfsfds");
listTopic = (List<ForumTopic>) map.get("listTopic");
topicCount = (Integer) map.get("topicCount");
page = (Integer) map.get("page");
pageSize = (Integer) map.get("pageSize");
pageCount = (Integer) map.get("pageCount");
}
System.out.println("topicCount::" + topicCount);
this.setAttribute(request, "position", position);
this.setAttribute(request, "listModule", listModule);
this.setAttribute(request, "listPiece", listPiece);
this.setAttribute(request, "listTopic", listTopic);
this.setAttribute(request, "pieceId", pieceId);
this.setAttribute(request, "moduleId", moduleId);
this.setAttribute(request, "topicId", topicId);
this.setAttribute(request, "page", page);
this.setAttribute(request, "pageSize", pageSize);
this.setAttribute(request, "topicCount", topicCount);
this.setAttribute(request, "hotReal", hotReal);
return mapping.findForward("search");
}
this.setAttribute(request, "position", position);
this.setAttribute(request, "listModule", listModule);
this.setAttribute(request, "listPiece", listPiece);
this.setAttribute(request, "pieceId", pieceId);
this.setAttribute(request, "moduleId", moduleId);
this.setAttribute(request, "topicId", topicId);
this.setAttribute(request, "topicCount", topicCount);
this.setAttribute(request, "page", page);
this.setAttribute(request, "pageSize", pageSize);
this.setAttribute(request, "hotReal", hotReal);
return mapping.findForward("search");
}
@Override
protected ActionForward essence(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Integer pageSize = Constents.essencePageSize;
Integer topicCount = 0;
String pieceName = null;
Integer pieceId = this.getPieceId(request); // 有可能返回的是空的值
if (pieceId != null) {
pieceName = El.getEl().getTopicMgr().getForumPieceById(pieceId)
.getName();
this.setAttribute(request, "pieceId", pieceId);
}
String position = this.constructPosition(request, pieceId, pieceName,
null, null);
if (pieceId != null) {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=essence&pieceId=" + pieceId
+ "\">精華帖子</a>";
} else {
position += "<a href=\"" + request.getContextPath()
+ "/forum/topic.do?action=essence\">精華帖子</a>";
}
List<ForumTopic> listEssenceTopic = El.getEl().getTopicMgr()
.getEssenceTopic(pieceId);
topicCount = null != listEssenceTopic ? listEssenceTopic.size() : 0;
this.setAttribute(request, "position", position);
this.setAttribute(request, "pageSize", pageSize);
this.setAttribute(request, "topicCount", topicCount);
this.setAttribute(request, "listEssenceTopic", listEssenceTopic);
return mapping.findForward("essence");
}
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return super.execute(mapping, form, request, response);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -