post.jsp

来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· JSP 代码 · 共 661 行 · 第 1/2 页

JSP
661
字号
<%/** *	$RCSfile: post.jsp,v $ *	$Revision: 1.14 $ *	$Date: 2002/08/12 03:35:29 $ */%><%@ page import="java.net.*,                 java.text.*,                 java.util.*,                 com.jivesoftware.util.*,                 com.jivesoftware.forum.*,                 com.jivesoftware.forum.util.*"    errorPage="error.jsp"%><%@ include file="postUtils.jsp" %><%@ include file="global.jsp" %><%  // Put the request URI and query string in the session as an attribute.    // This is done so the error.jsp and auth.jsp pages can figure out what    // page sent it an error and redirect appropriately.    setRedirectURL(request);%><%  // Login code. Usually the following code (below the parameter code) is in    // global.jsp, but on this page we're not including global.jsp so we can    // have better control over the way UnauthorizedExceptions are handled.    // First, get the message parameters because we might be entering this page    // after submitting the message form to post a message.    long forumID = ParamUtils.getLongParameter(request,"forum",-1L);	long threadID = ParamUtils.getLongParameter(request,"thread",-1L);    long messageID = ParamUtils.getLongParameter(request,"message",-1L);    String subject = ParamUtils.getParameter(request,"subject");    String body = ParamUtils.getParameter(request,"body");    String name = ParamUtils.getParameter(request,"name");    String email = ParamUtils.getParameter(request,"email");    boolean reply = ParamUtils.getBooleanParameter(request,"reply");    boolean doPost = ParamUtils.getBooleanParameter(request,"doPost");    boolean fromPreview = ParamUtils.getBooleanParameter(request,"fromPreview");    boolean quote = ParamUtils.getBooleanParameter(request,"quote");    boolean cancel = request.getParameter("cancel") != null;    boolean preview = request.getParameter("preview") != null;    // A special parameter - tells us if the user was logged in    boolean wasLoggedIn = ParamUtils.getBooleanParameter(request, "isLoggedIn");    // Check for a cancel:    if (cancel) {        // Redirect to index.jsp by default:        String redirect = "index.jsp";        // If threadID and forumID are both present, redirect back to the forum        // page:        if (forumID > -1 && threadID > -1) {            redirect = "thread.jsp?forum=" + forumID + "&thread=" + threadID;        }        else if (forumID > -1) {            redirect = "forum.jsp?forum=" + forumID;        }        response.sendRedirect(redirect);        return;    }    // Load the forum we're interested in:    Forum forum = forumFactory.getForum(forumID);    // Check if the user (guest or otherwise) has permission to post:    boolean canPost = false;    if (reply) {        if (forum.hasPermission(ForumPermissions.CREATE_MESSAGE) || isModerator(forumFactory,forum)) {            canPost = true;        }    }    else {        if (forum.hasPermission(ForumPermissions.CREATE_THREAD) || isModerator(forumFactory,forum)) {            canPost = true;        }    }    // If we can't post, redirect to a specialized error page    if (!canPost) {        if (isGuest) {            throw new UnauthorizedException(SkinUtils.getLocalizedString("skin.default.error.no_perm_to_post",locale));        }        else {            response.sendRedirect("perm.jsp?forum=" + forumID);            return;        }    }    // Grab the subject & body from the session if we're coming from    // a message preview (these values can't be passed as parameters)	if (fromPreview) { 	    subject = (String)session.getAttribute("jive.post.subject."+forumID+"."+threadID);        body = (String)session.getAttribute("jive.post.body."+forumID+"."+threadID);        name = (String)session.getAttribute("jive.post.name."+forumID+"."+threadID);        email = (String)session.getAttribute("jive.post.email."+forumID+"."+threadID);	}    // Error checks:    boolean subjectOK = (subject != null);    boolean bodyOK = (body != null);    // Watches    boolean autoWatchNewTopics = false;    boolean autoWatchReplies = false;    boolean addWatch = ParamUtils.getBooleanParameter(request,"addWatch");    if (!isGuest) {        autoWatchNewTopics = "true".equals(pageUser.getProperty("jiveAutoWatchNewTopics"));        autoWatchReplies = "true".equals(pageUser.getProperty("jiveAutoWatchReplies"));    }    boolean wasAutoWatchReplies = ParamUtils.getBooleanParameter(request,"wasAutoWatchReplies");    if (reply && (addWatch != wasAutoWatchReplies)) {        autoWatchReplies = addWatch;    }    boolean wasAutoWatchNewTopics = ParamUtils.getBooleanParameter(request,"wasAutoWatchNewTopics");    if (!reply && (addWatch != wasAutoWatchNewTopics)) {        autoWatchNewTopics = addWatch;    }    // If the subject & body are both not blank, we can check if we should    // do a preview, spell check or attach files:    if (doPost && subjectOK && bodyOK) {        // Previewing, spell checking and attaching files all need the subject,        // body and name & email in the session:        session.setAttribute("jive.post.subject."+forumID+"."+threadID, subject);        session.setAttribute("jive.post.body."+forumID+"."+threadID, body);        // Put the name and email in the session if they're not null        if (name != null) {            session.setAttribute("jive.post.name."+forumID+"."+threadID, name);        }        if (email != null) {            session.setAttribute("jive.post.email."+forumID+"."+threadID, email);        }        // Redirect to the right page:        if (preview) {            response.sendRedirect(                "preview.jsp?forum=" + forumID + "&thread=" + threadID + "&message="                + messageID + "&reply=" + reply                + "&addWatch=" + addWatch            );            return;        }    }    // The thread we're posting in (if this is a reply).	ForumThread thread = null;    // The parent message we're replying to (if this is a reply).	ForumMessage parentMessage = null;	if (reply) {     	thread = forum.getThread(threadID);        // A message ID might not be passed in. If this is the case, we're        // replying to the root message so get the message ID from the root        // message of the thread.        if (messageID == -1L) {            parentMessage = thread.getRootMessage();            messageID = parentMessage.getID();        } else {            parentMessage = thread.getMessage(messageID);        }	}    // Determine if moderation is turned on for this forum:    boolean isThreadModOn = (        forum.getModerationDefaultThreadValue() < forum.getModerationMinThreadValue()    );    boolean isMsgModOn = (        forum.getModerationDefaultMessageValue() < forum.getModerationMinMessageValue()    );    // A user manager lets us get and set user information:    UserManager userManager = forumFactory.getUserManager();    // Post the message if requested and if no errors.    ForumMessage newMessage = null;    if (doPost && subjectOK && bodyOK) {        newMessage = postMessage(request, reply, forumFactory, forum, thread,                messageID, pageUser, name, email, subject, body);        thread = newMessage.getForumThread();        // Remove the subject and body from the session as they're no longer        // needed.        session.removeAttribute("jive.post.subject."+forumID+"."+threadID);        session.removeAttribute("jive.post.body."+forumID+"."+threadID);        session.removeAttribute("jive.post.name."+forumID+"."+threadID);        session.removeAttribute("jive.post.email."+forumID+"."+threadID);        // Add a watch if requested.        if (pageUser != null) {            // Determine if we'll also need to make this watch an email watch.            boolean autoAddEmailWatch = "true".equals(pageUser.getProperty("jiveAutoAddEmailWatch"));            // Check if we need to add a watch to this message            if (autoWatchNewTopics || (reply && autoWatchReplies)) {                WatchManager watchManager = forumFactory.getWatchManager();                watchManager.createWatch(pageUser, thread, WatchManager.NORMAL_WATCH);                if (autoAddEmailWatch) {                    watchManager.createWatch(pageUser, thread, WatchManager.EMAIL_NOTIFY_WATCH);                }            }        }		// Now that posting is done, figure out where we need to redirect to.        // Do a standard redirect back to the new thread page if we're        // not replying to a message        if (!reply) {            // However, if thread moderation is turned on, we shoud just            // redirect back to the forum's thread listing:            if (isThreadModOn) {                response.sendRedirect("forum.jsp?forum="+forumID);                return;            }            else {                // Standard redirect back to the new thread page                response.sendRedirect("thread.jsp?nav=false&forum="+forumID+"&thread="+thread.getID());                return;            }        }        // Otherwise, we need to redirect back to the new posted reply.        // Compute the correct thread page to go to.        else {            // However, if message moderation is turned on, we should just            // redirect back to the top of the thread listing            if (isMsgModOn) {                response.sendRedirect("thread.jsp?nav=false&forum=" + forumID                    + "&thread=" + threadID);                return;            }            else {                // the ID of the newly created message                long newMessageID = newMessage.getID();                // the number of threads a user wants to display on a topic page                int threadRange = getThreadRange(request, response, pageUser);                // the number of messages in this thread                int messageCount = thread.getMessageCount();                // number of pages in the topic listing (we'll want to be at                // the end of that since new messages end up at the end of the                // thread list)                int numPages = (int)Math.ceil((double)messageCount/(double)threadRange);                // starting point:                int start = (numPages-1) * threadRange;                // do the redirect:    			response.sendRedirect(                    "thread.jsp?nav=false&forum=" + forumID + "&thread=" + thread.getID()                    + "&start=" + start + "&msRange=" + userMessageRange                );                return;            }        }    }    // Formatter for short dates    SimpleDateFormat shortDateFormatter = new SimpleDateFormat("MMM, yyyy", locale);    String title = SkinUtils.getLocalizedString("skin.default.post.title",locale);%><%@ include file="header.jsp" %><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>    <td valign="top" width="98%">    <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"     color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">    <%  if (reply) { %>        <b><%= SkinUtils.getLocalizedString("skin.default.global.post_message",locale) %></b>    <%  } else { %>        <b><%= SkinUtils.getLocalizedString("skin.default.global.post_new_topic",locale) %></b>    <%  } %>    </font>    <br>    <%-- Breadcrumbs --%>    <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"     face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"     color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">    <b>    <a href="<%= JiveGlobals.getJiveProperty("skin.default.homeURL") %>"    ><%= SkinUtils.getLocalizedString("skin.default.global.home",locale) %></a>    &raquo;    <a href="index.jsp"     title="<%= SkinUtils.getLocalizedString("skin.default.global.go_back_to_forum_list",locale) %>"     ><%= SkinUtils.getLocalizedString("skin.default.global.forums",locale) %></a>    &raquo;    <a href="forum.jsp?forum=<%= forumID %>"     title="<%= SkinUtils.getLocalizedString("skin.default.global.go_back_to_topic_list",locale) %>"     ><%= forum.getName() %></a>    </b>    </font>    <p>    <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"     face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">    <%  // Create the list of arguments to pass into the following two i18n        // string methods:        List postLinkDisplay = new ArrayList(2);        // Add the name and link to the forum:        postLinkDisplay.add("<a href=\"forum.jsp?forum=" + forumID + "\">"                + forum.getName() + "</a>");        if (reply) {            // Add the name and link to the message:            postLinkDisplay.add("<a href=\"thread.jsp?forum=" + forumID                    + "&thread=" + threadID + "&message=" + messageID                    + "#" + messageID + "\">" + parentMessage.getSubject() + "</a>");        }    %>    <%  if (reply) { %>        <%= SkinUtils.getLocalizedString("skin.default.post.reply_in_forum_to_message", postLinkDisplay) %>    <%  } else { %>        <%= SkinUtils.getLocalizedString("skin.default.post.post_in_forum", postLinkDisplay) %>    <%  } %>    </font>    <p>    </td>    <td valign="top" width="1%" align="center">    <%@ include file="loginbox.jsp" %>    </td></tr></table><p><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"><%  if (reply) { %>    <%= SkinUtils.getLocalizedString("skin.default.post.reply_description",locale) %>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?