viewForum.jsp
资源名称:NetOffice.rar [点击查看]
上传用户:guhaomin
上传日期:2007-06-10
资源大小:23203k
文件大小:9k
源码类别:
电子政务应用
开发平台:
Java
- <%
- /**
- * $RCSfile: viewForum.jsp,v $
- * $Revision: 1.4 $
- * $Date: 2000/12/27 22:39:45 $
- */
- %>
- <%@ page
- import="java.util.*,
- java.text.*,
- java.net.*,
- com.coolservlets.forum.*,
- com.coolservlets.forum.util.*"
- errorPage="/mainctrl/bbs/error"
- %>
- <%! // Global variables
- //final SimpleDateFormat formatter = new SimpleDateFormat( "EE, MMM d" );
- final SimpleDateFormat formatter = new SimpleDateFormat( "yyyy.MM.dd h:mm a" );
- final SimpleDateFormat timeFormatter = new SimpleDateFormat( "h:mm a" );
- final SimpleDateFormat dayFormatter = new SimpleDateFormat( "yyyy.MM.dd" );
- final long ONE_DAY = 1000L * 60 * 60 * 24;
- final long ONE_WEEK = ONE_DAY * 7;
- final int DEFAULT_MSG_RANGE = 15;
- // Method to print one line on the thread table
- private String displayMessage(int forumID, ForumThread thread, ForumMessage message, String forumParams, long now, long lastVisited) {
- StringBuffer buf = new StringBuffer();
- if( message != null ) {
- Date messageDate = thread.getModifiedDate();
- long messageDateMS = messageDate.getTime();
- String subject = message.getSubject();
- int messageID = message.getID();
- String username = null;
- if( !message.isAnonymous() ) {
- User user = message.getUser();
- username = user.getName();
- if (username == null)
- username = user.getUsername();
- }
- if (username == null)
- username = "匿名者";
- int threadID = thread.getID();
- int numReplies = thread.getMessageCount()-1;
- if( subject == null || subject.equals("") ) {
- subject = "[无主题]";
- }
- String dateText = "";
- //if (messageDateMS >= (now - 2 * ONE_DAY)) {
- //dateText = SkinUtils.dateToText(messageDate);
- //}
- //else {
- dateText = formatter.format(messageDate);
- //}
- // new flag
- buf.append("<td width='1%'>");
- buf.append(messageDateMS > lastVisited ? "<img src="/skins/bay/images/new.gif">" : " ");
- buf.append("</td>");
- // subject cell
- buf.append("<td width='96%'><font face='verdana' >");
- buf.append("<a href='/mainctrl/bbs/viewMessage?message=").append(messageID).append("&thread=");
- buf.append(threadID).append("&forum=").append(forumID);
- if (forumParams.length() > 0)
- buf.append("&forumparams=").append(forumParams);
- buf.append("'><font class=strong>").append(subject);
- buf.append("</font></a>");
- //buf.append(" [").append(numReplies).append("]");
- buf.append("</font></td>").append("n");
- // replies cell
- buf.append("<td width='1%' align='center'>");
- buf.append("<font color='#666666' face='verdana' >");
- buf.append("[");
- buf.append("<a href='/mainctrl/bbs/viewMessage?message=").append(messageID).append("&thread=");
- buf.append(threadID).append("&forum=").append(forumID);
- if (forumParams.length() > 0)
- buf.append("&forumparams=").append(forumParams);
- buf.append("'><font class=strong>").append(numReplies);
- buf.append("</font></a>");
- buf.append("]");
- buf.append("</font></td>");
- // username cell
- buf.append("<td width='1%' nowrap align='center'>");
- buf.append("<font color='#666666' face='verdana' >");
- buf.append(username);
- buf.append("</font></td>");
- // date cell
- if( messageDateMS >= (now-ONE_WEEK) ) {
- buf.append("<td width='1%' nowrap class='dateTimeListToday' align='center'>");
- } else {
- buf.append("<td width='1%' nowrap class='dateTimeList' align='center'>");
- }
- buf.append("<font face='verdana' >");
- buf.append( dateText );
- buf.append("</font></font>");
- buf.append("</td>").append("n");
- }
- return buf.toString();
- }
- %>
- <% ////////////////////////
- // Authorization check
- // check for the existence of an authorization token
- Authorization authToken = SkinUtils.getUserAuthorization(request,response);
- // if the token was null, they're not authorized. Since this skin will
- // allow guests to view forums, we'll set a "guest" authentication
- // token
- if( authToken == null ) {
- authToken = AuthorizationFactory.getAnonymousAuthorization();
- }
- %>
- <% // get parameters
- int forumID = ParamUtils.getIntParameter(request, "forum", -1);
- int range = ParamUtils.getIntParameter(request, "range", DEFAULT_MSG_RANGE);
- int start = ParamUtils.getIntParameter(request, "start", 0);
- long lastVisited = SkinUtils.getLastVisited(request, response);
- String startParam = (start == 0) ? "" : "&start=" + start;
- String rangeParam = (range == DEFAULT_MSG_RANGE) ? "" : "&range=" + range;
- %>
- <% ForumThread thread = null;
- Forum forum = null;
- ForumFactory forumFactory = ForumFactory.getInstance(authToken);
- try {
- forum = forumFactory.getForum(forumID); // throws ForumNotFoundException
- }
- catch( UnauthorizedException ue ) {
- response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("您没有权限访问此论坛!") );
- return;
- }
- catch( ForumNotFoundException fnfe ) {
- response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("此论坛不存在!") );
- return;
- }
- String forumName = forum.getName();
- Iterator forumIterator = forumFactory.forums();
- %>
- <% /////////////////
- // header include
- String title = forumName;
- %>
- <%@ include file="/skins/bay/header.jsp" %>
- <%-- begin breadcrumbs --%>
- <form>
- <table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
- <tr>
- <td>
- <font class="strongw"><a href="/mainctrl/home/index"><font color="#FFFFFF">首页</font></a>>><a href="/mainctrl/communication/main"><font color="#FFFFFF">通信</font></a>>><a href="/mainctrl/bbs/index"><font color="#FFFFFF">论坛主页</font></a>
- >></font>
- <font class="strong">
- <select name="forumName" size=1 class="text" onchange="location=this.options[this.selectedIndex].value;">
- <option value="" selected><%= forumName %>
- <option value="/mainctrl/bbs/viewForum?forum=<%= forumID %>">---------------------------
- <% while (forumIterator.hasNext()) {
- Forum tmpForum = (Forum)forumIterator.next();
- String name = tmpForum.getName();
- String location = "/mainctrl/bbs/viewForum?forum=" + tmpForum.getID();
- %>
- <option value="<%= location %>">>> <%= name %>
- <% }
- %>
- </select>
- </font>
- </td>
- </tr>
- </table>
- </form>
- <%-- end breadcrubms --%>
- <div align="center"><a href="/mainctrl/bbs/post?forum=<%= forumID %>" class="normal"><img src="/skins/bay/images/newthread.gif" width=106 height=23 border="0"></a><br></div>
- <% Iterator it = forum.threads(start,range);
- if( !it.hasNext() ) {
- %>
- <ul>
- <font face="verdana" ><font class="strong">
- 此论坛中没有帖子。
- </font><br>
- </font>
- </ul>
- <% } else { %>
- <table bgcolor="#999999" cellpadding=0 cellspacing=0 border=0 width="100%">
- <td>
- <table bgcolor="#999999" cellpadding=3 cellspacing=1 border=0 width="100%">
- <tr bgcolor="#dddddd">
- <td width="1%"> </td>
- <td align="center" width="96%"><font class="strong">主题</font></td>
- <td align="center" width="1%" nowrap><font class="strong">回复</font></td>
- <td align="center" width="1%" nowrap><font class="strong">作者</font></td>
- <td align="center" width="1%" nowrap><img src="/skins/bay/images/arrow-up.gif" width=8 height=7 border=0 hspace=6><font class="strong">时间</font></td>
- </tr>
- <% long now = (new java.util.Date()).getTime();
- ForumMessage root = null;
- int rowColor = 0;
- String bgcolor = "";
- String forumParams = URLEncoder.encode(startParam + rangeParam);
- int numThreadInForum = forum.getThreadCount();
- while(it.hasNext()) {
- rowColor++;
- thread = (ForumThread)it.next();
- root = thread.getRootMessage();
- if( rowColor%2 == 0 ) {
- bgcolor = "#ffffff";
- } else {
- bgcolor = "#eeeeee";
- }
- %>
- <tr bgcolor="<%= bgcolor %>">
- <%= displayMessage(forumID, thread, root, forumParams, now, lastVisited) %>
- </tr>
- <% } %>
- </table>
- </td>
- </table>
- <table cellpadding=0 height=26 cellspacing=0 border=0 width="100%" bgcolor="#fafafa">
- <td width="1%" nowrap>
- <font face="verdana,arial">
- <% if( (start-range) >= 0 ) { %>
- <a href="/mainctrl/bbs/viewForum?forum=<%= forumID %><%= rangeParam %>&start=<%= (start-range) %>"><font class="strong"><<</font>前<%= range %>帖子</a>
- <% } %>
- </font>
- </td>
- <td width="98%" nowrap>
- </td>
- <td width="1%" nowrap>
- <font face="verdana,arial">
- <% if( (range+start) < numThreadInForum ) { %>
- <a href="/mainctrl/bbs/viewForum?forum=<%= forumID %><%= rangeParam %>&start=<%= (start+range) %>">后<%= (((numThreadInForum-range)<=range)?(numThreadInForum-range):range) %>帖子 <font class="strong">>></font></a>
- <% } %>
- </font>
- </td>
- </table>
- <% } %>
- <%@ include file="/skins/bay/footer.jsp" %>