threadmode2.jsp

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

JSP
794
字号
<%/** *	$RCSfile: threadMode2.jsp,v $ *	$Revision: 1.14 $ *	$Date: 2002/08/10 18:07:46 $ */%><%@ page import="java.net.*,                 java.text.*,                 java.util.*,                 com.jivesoftware.util.*,                 com.jivesoftware.forum.*,                 com.jivesoftware.forum.util.*"    errorPage="error.jsp"%><%! // Global vars, methods, etc..    // Formatter for file attachment sizes.    static final DecimalFormat sizeFormatter = new DecimalFormat("#,##0.0");%><%@ 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);%><%  //    // This page displays the messages in the thread in a "flat" view.    //    // Get parameters    long forumID = ParamUtils.getLongParameter(request,"forum",-1L);    long threadID = ParamUtils.getLongParameter(request,"thread",-1L);    long messageID = ParamUtils.getLongParameter(request,"message",-1L);    int start = ParamUtils.getIntParameter(request,"start",0);    int range = getMessageRange(request,response,pageUser);    String searchWords = ParamUtils.getParameter(request,"q");    boolean unlock = ParamUtils.getBooleanParameter(request,"unlock");    boolean unarchive = ParamUtils.getBooleanParameter(request,"unarchive");    // "nav" indicates if we show the next/prev links    boolean nav = false;    // Only show nav if the thread starting point and thread range are passed in:    int threadStart = ParamUtils.getIntParameter(request,"tstart",-1);    int threadRange = ParamUtils.getIntParameter(request,"trange",-1);    int nextStart = threadStart;    int prevStart = threadStart;    if (threadStart > -1 && threadRange > -1) {        nav = true;        // If the starting point is not zero, back it up one (because the last thread        // is likely the one before it)        if (threadStart > 0) {            threadStart--;        }        // Always increment the range by one since we don't know        // if the last thread on the thread list page was clicked:        threadRange++;        // Adjust the start of the next & prev links        nextStart ++;        prevStart --;        if (prevStart < 0) {            prevStart = 0;        }    }    boolean hilite = (searchWords != null);    // Unescape search words:    if (searchWords != null) {        searchWords = new String(StringUtils.decodeHex(searchWords));    }    // Load the forum    Forum forum = forumFactory.getForum(forumID);    // The requested thread object    ForumThread thread = forum.getThread(threadID);    // Indicates if the pageUser is a moderator of this forum:    boolean isModerator = isModerator(forumFactory, forum);    // unlock or unarchive the thread if requested by the moderator:    if (unlock) {        if (!isModerator) {            throw new UnauthorizedException("You do not have permission to unlock this topic");        }        thread.deleteProperty("locked");        response.sendRedirect("thread.jsp?forum="+forumID+"&thread="+threadID+"&tstart="+threadStart+"&trange="+threadRange);        return;    }    if (unarchive) {        if (!isModerator) {            throw new UnauthorizedException("You do not have permission to unarchive this topic");        }        thread.deleteProperty("archived");        response.sendRedirect("thread.jsp?forum="+forumID+"&thread="+threadID+"&tstart="+threadStart+"&trange="+threadRange);        return;    }    // Compute number of topics, messages in this forum, number of pages    int numMessages = thread.getMessageCount();	int numReplies = numMessages-1; // subtract 1 because the root message is counted    int numPages = (int)Math.ceil((double)numMessages/(double)range);	// Variables for message iteration	Iterator messages = null;    // Determine if we need to adjust the start index of the thread iterator.    // If we're passed a message ID, we need to show the thread page that    // messageID is contained on.    //    // Note: If your forum has an *extremely* large number of messages in each    // thread, you might want to comment out the following "if" block of code.    // The following block can be a performance bottleneck if all messages    // are not in cache or if the message cache is too small.    // The result of commenting out this code is that incoming links to this    // page that use a message ID, ie: thread.jsp?forum=X&thread=Y&message=Z    // will always start on the first page of the thread, not the page where    // message Z is.    if (messageID != -1) {        // Check if the message ID is the same as the root message of the        // thread. If it is, set the start index to 0 since that message will        // be on the first page        if (messageID == thread.getRootMessage().getID()) {            start = 0;        }        else {            // get an iterator of all messages            messages = thread.messages();            int index = 0;            int messageRange = range;            // loop through the messages            while (messages.hasNext()) {                ForumMessage message = (ForumMessage)messages.next();                if (message.getID() != messageID) {                    index++;                }                else {                    // found the message, calculage what page we're on                    start = (index/messageRange)*messageRange;                    break;                }            }        }    }	// Root message of the thread	ForumMessage rootMessage = thread.getRootMessage();    ResultFilter filter = ResultFilter.createDefaultMessageFilter();    filter.setStartIndex(start);    filter.setNumResults(range);    // reinitialize the message iterator to show the appropriate range    messages = thread.messages(filter);    // A user manager lets us get information about users    UserManager userManager = forumFactory.getUserManager();    // Get a thread iterator (for the next/previous thread feature):    ForumThreadIterator threadIterator = null;    ForumThread prevThread = null;    ForumThread nextThread = null;    // Only get a next/prev iterator if it is turned on. The only case where    // it should be turned off is when coming from the post page.    if (nav) {        // Get a list of threads:        ResultFilter threadFilter = new ResultFilter();        threadFilter.setStartIndex(threadStart);        threadFilter.setNumResults(threadRange);        threadIterator = forum.threads(threadFilter);        // Set its index to this thread:        threadIterator.setIndex(thread);        // Get the previous and next threads:        if (threadIterator.hasPrevious()) {            prevThread = (ForumThread)threadIterator.previous();            // advance the iterator pointer back to the original index            threadIterator.next();        }        if (threadIterator.hasNext()) {            nextThread = (ForumThread)threadIterator.next();        }    }    // Get a watch manager to manage watches on this page.    WatchManager watchManager = null;    // Indicates if this thread is watched    boolean isWatchedThread = false;    if (!isGuest) {        watchManager = forumFactory.getWatchManager();        isWatchedThread = watchManager.isWatchedThread(pageUser, thread, WatchManager.NORMAL_WATCH);    }    String headerPaginatorHTML = "";    if (numPages > 1) {        headerPaginatorHTML = getThreadPaginator(forumID, threadID, numMessages, numReplies, numPages, start, range, true,locale);    }    String footerPaginatorHTML = "";    if (numPages > 1) {        footerPaginatorHTML = getThreadPaginator(forumID, threadID, numMessages, numReplies, numPages, start, range, false,locale);    }    // Add the subject of the root message to the title    List titleDisplay = new ArrayList(1);    titleDisplay.add(thread.getName());    String title = SkinUtils.getLocalizedString("skin.default.thread.title", locale, titleDisplay);    // Formatter for short dates    SimpleDateFormat shortDateFormatter = new SimpleDateFormat("MMM, yyyy", locale);    // Check if this topic is archived:    boolean isArchived = "true".equals(thread.getProperty("archived"));    // Check if this topic is locked:    boolean isLocked = "true".equals(thread.getProperty("locked"));%><%@ include file="header.jsp" %><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>    <td width="99%" valign="top">    <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"     color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">    <b><%= rootMessage.getSubject() %></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") %>">    <%= SkinUtils.getLocalizedString("skin.default.global.replies",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %>    <b><%= SkinUtils.getLocalizedNumber(numReplies,locale) %></b>    &nbsp;    <%= SkinUtils.getLocalizedString("skin.default.global.pages",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %>    <b><%= SkinUtils.getLocalizedNumber(numPages,locale) %></b>    &nbsp;    <%  // Print out the most recently reply in this thread (if there are replies):        if (numReplies > 0) {            ForumMessage lastPost = null;

⌨️ 快捷键说明

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