📄 viewmessage.jsp
字号:
<%
/**
* $RCSfile: viewMessage.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, methods --%>
<%! final int DEFAULT_FORUM_ID = 1; // ServletForum.com Beta Forum ID
final int IMG_WIDTH = 13;
final int IMG_HEIGHT = 12;
final SimpleDateFormat dateFormatter = new SimpleDateFormat( "yyyy.MM.dd" );
final SimpleDateFormat timeFormatter = new SimpleDateFormat( "h:mm a" );
final String TREE_ROOT = "<img src='/skins/bay/images/t0.gif' align='top' width=8 height=20>";
final String TREE_EMPTY = "<img src='/skins/bay/images/t0.gif' align='top' width=20>";
final String TREE_LINE = "<img src='/skins/bay/images/t1.gif' align='top'>";
final String TREE_CORNER = "<img src='/skins/bay/images/t2.gif' align='top'>";
final String TREE_FORK = "<img src='/skins/bay/images/t3.gif' align='top'>";
final String TREE_ARROW = "<img src='/skins/bay/images/t_arrow.gif' align='top'>";
final String TREE_NEW = "<img src='/skins/bay/images/t_new.gif' align='top'>";
// Recursive method to print all the children of a message.
private void printChildren(TreeWalker walker, ForumMessage message, ForumThread thread,
int currentMessageID, int level, int childCount,
StringBuffer buf, int messageID, int forumID,
int lineNr[], String tree, long lastVisited,
String forumParams)
{
java.util.Date date = message.getModifiedDate();
long modifiedDate = date.getTime();
String subj = message.getSubject();
String username = "匿名者";
if( !message.isAnonymous() ) {
User user = message.getUser();
username = user.getName();
if (username == null)
username = user.getUsername();
}
int msgID = message.getID();
int thrID = thread.getID();
boolean onCurrent = (message.getID() == messageID);
boolean rootMsg = (lineNr[0] == 0);
String bgcolor = "";
if( subj == null || subj.equals("") ) {
subj = "[无主题]";
}
if( (lineNr[0]++ & 1) != 0) {
//bgcolor = " bgcolor='#dddddd'";
bgcolor = " bgcolor='#eeeeee'";
}
else {
bgcolor = " bgcolor='#ffffff'";
}
if( onCurrent ) {
bgcolor = " bgcolor='#dddddd'";
//bgcolor = " bgcolor='#ffffff'";
}
// print start of row, with appropriate background color
buf.append("<tr valign=middle").append( bgcolor ).append(">\n");
// start of subject cell
if( onCurrent ) {
buf.append("<td width='98%'><font class=strong>");
} else {
buf.append("<td width='98%'><font class=px_12>");
}
// padding images
if (rootMsg) {
if (!onCurrent)
buf.append(TREE_ROOT);
} else {
buf.append(tree);
if (childCount > 0)
buf.append(TREE_FORK);
else
buf.append(TREE_CORNER);
}
if (onCurrent) {
buf.append(TREE_ARROW);
}
// subject cell
if (modifiedDate > lastVisited) {
buf.append(TREE_NEW);
}
if (!onCurrent) {
buf.append("<a href='/mainctrl/bbs/viewMessage?message=").append(msgID);
buf.append("&thread=").append(thrID);
buf.append("&parent=").append(currentMessageID);
buf.append("&forum=").append(forumID);
if (forumParams.length() > 0)
buf.append(forumParams);
buf.append("'>");
}
else {
buf.append("<a name='currentMsg'>");
}
buf.append(subj);
buf.append("</a>");
buf.append("</font></td>").append("\n");
// username cell
if( onCurrent ) {
buf.append("<td width='1%' nowrap align='center'><font class=strong> ");
} else {
buf.append("<td width='1%' nowrap align='center'><font class=px_12> ");
}
buf.append(username);
buf.append(" </font></td>");
// date cell
if( onCurrent ) {
buf.append("<td width='1%' nowrap ><font class=strong>");
} else {
buf.append("<td width='1%' nowrap ><font class=px_12>");
}
buf.append(dateFormatter.format(date)).append(" - ").append(timeFormatter.format(date));
buf.append("</font></td>").append("\n");
// print end of row
buf.append("</tr>\n");
// recursive call
if (!rootMsg) {
if (childCount > 0)
tree += TREE_LINE;
else
tree += TREE_EMPTY;
}
int numChildren = walker.getChildCount(message); // keep
if( numChildren > 0 ) {
for( int i=0; i<numChildren; i++ ) {
ForumMessage child = walker.getChild(message, i);
printChildren( walker, child, thread, message.getID(), ++level, numChildren - i -1, buf, messageID, forumID, lineNr, tree, lastVisited, forumParams);
level--;
}
}
}
%>
<% ////////////////////////
// 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 parameter values
int parentID = ParamUtils.getIntParameter(request, "parent", -1);
int threadID = ParamUtils.getIntParameter(request, "thread", -1);
int messageID = ParamUtils.getIntParameter(request, "message", -1);
int forumID = ParamUtils.getIntParameter(request, "forum", -1);
String forumParams = ParamUtils.getParameter(request, "forumparams");
String forumParamsEncoded = (forumParams == null) ? "" : "&forumparams=" + URLEncoder.encode(forumParams);
long lastVisited = SkinUtils.getLastVisited(request, response);
int nextID = -1;
int previousID = -1;
%>
<% // Get a ForumFactory object
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
// Get a forum object, redirect on error:
Forum forum = null;
try {
forum = forumFactory.getForum(forumID);
}
catch( UnauthorizedException ue ) {
response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("您没有权限访问此论坛!") );
return;
}
catch( ForumNotFoundException fnfe ) {
response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("此论坛不存在!") );
return;
}
%>
<%
// Get the thread, then message
ForumThread thread = null;
int threadChildCount = 0;
try {
thread = forum.getThread(threadID);
threadChildCount = thread.getMessageCount()-1;
}
catch( ForumThreadNotFoundException tnfe ) {
response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("此主题不存在!") );
return;
}
ForumMessage message = null;
try {
if (messageID < 0) {
message = thread.getRootMessage();
}
else {
message = thread.getMessage(messageID);
}
}
catch( ForumMessageNotFoundException mnfe ) {
response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("此帖子不存在!") );
return;
}
//Get the TreeWalker
TreeWalker walker = thread.treeWalker();
ForumMessage root = walker.getRoot();
int numRecursiveChildren = walker.getRecursiveChildCount(message);
ForumMessage parent = null;
if (parentID != -1) {
parent = thread.getMessage(parentID);
int numParentsChildren = walker.getChildCount(parent);
//Get the previous and next messages in the thread.
int currentChildNum = walker.getIndexOfChild(parent,message);
if (currentChildNum >= numParentsChildren-1) {
nextID = -1;
}
else {
nextID = walker.getChild(parent,currentChildNum + 1).getID();
}
if (currentChildNum > 0) {
previousID = walker.getChild(parent,currentChildNum - 1).getID();
}
}
%>
<% /////////////////
// header include
String title = (message == null) ? "帖子不存在" : message.getSubject();
%>
<%@ include file="/skins/bay/header.jsp" %>
<%-- begin breadcrumbs --%>
<table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
<tr>
<td>
<font color="#FFFFFF" 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" class="normal"><font color="#FFFFFF">论坛主页</font></a>
>>
<a href="/mainctrl/bbs/viewForum?forum=<%= forumID %><%= forumParams == null ? "" : forumParams %>" class="normal"><font color="#FFFFFF"><%= forum.getName() %></font></a>
>>
<%= thread == null ? "" : thread.getName() %>
</font>
<%-- end breadcrumbs --%>
</td>
</tr>
</table>
<br>
<%-- Message table --%>
<table bgcolor="#666666" cellpadding=1 cellspacing=0 border=0 width="100%">
<tr>
<td>
<table bgcolor="#dddddd" cellpadding=3 cellspacing=0 border=0 width="100%">
<td bgcolor="#dddddd" width="99%">
<%
java.util.Date date = message.getModifiedDate();
String subj = message.getSubject();
boolean canEdit = false;
boolean canReply = message.hasPermission(ForumPermissions.CREATE_MESSAGE);
if( subj == null || subj.equals("") ) {
subj = "[无主题]";
}
%>
<font face="Trebuchet MS">
<font class="strong"><%= subj %></font>
</font>
<br>
<font face="verdana" >
<font class="strong">
<%
if( !message.isAnonymous() ) {
User user = message.getUser();
String email = user.getEmail();
String name = user.getName();
if (name == null)
name = user.getUsername();
canEdit = canReply && (user.getID() == authToken.getUserID() &&
System.currentTimeMillis() < date.getTime() + 2 * 3600 * 1000);
if (email != null) {
%>
<a href="mailto:<%= email %>" class="normal"><%= name %></a>
<% } else { %>
<%= name %>
<% }
} else { %>
[匿名者]
<% } %>
</font>
</font>
</td>
<td bgcolor="#dddddd" width="1%" nowrap>
<font face="verdana" >
<font class="strong">
<% java.util.Date d = message.getCreationDate(); %>
<%= dateFormatter.format(d) %> - <%= timeFormatter.format(d) %>
</font>
</font>
</td>
</table>
<table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
<td><img src="/skins/bay/images/blank.gif" width=1 height=1 border=0></td>
</table>
<table bgcolor="#eeeeee" cellpadding=3 cellspacing=0 border=0 width="100%">
<td align="center">
<% if (canEdit) { %>
<a href="/mainctrl/bbs/post?message=<%= messageID %>&thread=<%= threadID %>&forum=<%= forumID %><%= forumParamsEncoded %>&postType=edit"><img src="/skins/bay/images/edit_button.gif" width=103 height=23 border="0"></a>
<% } %>
<% if (canReply) { %>
<a href="/mainctrl/bbs/post?message=<%= messageID %>&thread=<%= threadID %>&forum=<%= forumID %><%= forumParamsEncoded %>&postType=reply"><img src="/skins/bay/images/reply_button.gif" width=103 height=23 border="0"></a><br>
<% } else { %>
<% } %>
</td>
</table>
<table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
<td><img src="/skins/bay/images/blank.gif" width=1 height=1 border=0></td>
</table>
<table bgcolor="#ffffff" cellpadding=5 cellspacing=0 border=0 width="100%">
<td>
<%= message.getBody() %>
<% if( !message.isAnonymous() ) {
User user = message.getUser();
String sig = (String)user.getProperty("sig");
%>
<pre>
<%= (sig!=null)?sig:"" %></pre>
<% } %>
</td>
</table>
</td>
</tr>
</table>
<%-- Message table --%>
<p>
<font face="tahoma" ><font class="strong">
<% if( numRecursiveChildren == 0 ) { %>
此帖没有回复。
<% } else { %>
此帖共有 <a href="#currentMsg"><%= numRecursiveChildren %>
</a> 个回复.
<% } %>
</font>
<% if (canReply) { %>
[<a href="/mainctrl/bbs/post?message=<%= messageID %>&thread=<%= threadID %>&forum=<%= forumID %><%= forumParamsEncoded %>&postType=reply" class="normal">增加帖子</a>]
<% } %>
</font>
<p>
<table bgcolor="#999999" cellpadding=0 cellspacing=0 border=0 width="100%">
<td>
<table bgcolor="#999999" cellpadding=0 cellspacing=1 border=0 width="100%">
<% StringBuffer buf = new StringBuffer();
int level = 0;
int[] lineNr = { 0 };
String tree = "";
printChildren( walker, root, thread, -1, level, -1, buf, messageID, forumID, lineNr, tree, lastVisited, forumParamsEncoded);
out.println( buf.toString() );
%>
</table>
</td>
</table>
<br>
<%@ include file="/skins/bay/footer.jsp" %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -