📄 threadcontent.jsp
字号:
<%
/**
* $RCSfile: threadContent.jsp,v $
* $Revision: 1.3 $
* $Date: 2000/12/18 02:06:21 $
*/
%>
<%@ page import="java.util.*,
java.text.SimpleDateFormat,
com.coolservlets.forum.*,
com.coolservlets.forum.util.*,
com.coolservlets.forum.util.admin.*"
errorPage="error.jsp"
%>
<jsp:useBean id="adminBean" scope="session"
class="com.coolservlets.forum.util.admin.AdminBean"/>
<%!
/**
* Print a child message
*/
private String printChildMessage( Forum forum, ForumThread thread, ForumMessage message, int indentation )
{
StringBuffer buf = new StringBuffer();
try {
if( message.getID() == thread.getRootMessage().getID() ) {
return "";
}
String subject = message.getSubject();
boolean msgIsAnonymous = message.isAnonymous();
User author = message.getUser();
String authorName = author.getName();
String authorEmail = author.getEmail();
int forumID = forum.getID();
int threadID = thread.getID();
int messageID = message.getID();
Date creationDate = message.getCreationDate();
String msgBody = message.getBody();
buf.append("<tr>");
buf.append("<form>");
buf.append("<td width=\"1%\" class=\"forumListCell\" align=\"center\">");
buf.append("<input type=\"radio\"");
buf.append("onclick=\"if(confirm('您确定要删除此帖子和回复它的所有帖子吗?')){");
buf.append("location.href='threadContent.jsp?message=").append(messageID).append("&doDeleteMessage=true");
buf.append("&forum=").append(forumID).append("&thread=").append(threadID).append("';}\">");
buf.append("</td>");
buf.append("<td class=\"forumListCell\" width=\"").append(99-indentation).append("%\">");
buf.append("<table cellpadding=2 cellspacing=0 border=0 width=\"100%\">");
buf.append("<tr bgcolor=\"#dddddd\">");
int i = indentation;
while(i-- >= 0 ) {
buf.append("<td bgcolor=\"#ffffff\"> </td>");
}
buf.append("<td><b>").append( message.getSubject() ).append("</b></td>");
buf.append("</tr>");
buf.append("<tr bgcolor=\"#eeeeee\">");
String rootMsgUsername = "<i>匿名者</i>";
User rootMsgUser = message.getUser();
if( !message.getUser().isAnonymous() ) {
rootMsgUsername = rootMsgUser.getUsername();
}
i = indentation;
while(i-- >= 0 ) {
buf.append("<td bgcolor=\"#ffffff\"> </td>");
}
buf.append("<td><font size=\"-2\"><b>作者: ").append( rootMsgUsername ).append(",日期: ").append( message.getCreationDate() ).append("</b></font></td>");
buf.append("</tr>");
buf.append("<tr>");
i = indentation;
while(i-- >= 0 ) {
buf.append("<td> </td>");
}
buf.append("<td>").append( message.getBody() ).append("</td>");
buf.append("</tr>");
buf.append("</table></td></form></tr>");
} catch( Exception ignored ) {}
return buf.toString();
}
/**
* Recursive method to print all the children of a message.
*/
private String printChildren( TreeWalker walker, Forum forum, ForumThread thread, ForumMessage message, int indentation )
{
StringBuffer buf = new StringBuffer();
buf.append( printChildMessage( forum, thread, message, indentation ) );
// recursive call
int numChildren = walker.getChildCount(message);
if( numChildren > 0 ) {
for( int i=0; i<numChildren; i++ ) {
buf.append(
printChildren( walker, forum, thread, walker.getChild(message,i), (indentation+1) )
);
}
}
return buf.toString();
}
%>
<%! //////////////////////////
// global vars
// date formatter for message dates
private final SimpleDateFormat dateFormatter
= new SimpleDateFormat( "yyyy.MM.dd h:mm a" );
private final static int RANGE = 15;
private final static int START = 0;
%>
<% ////////////////////////////////
// Jive authorization check
// check the bean for the existence of an authorization token.
// Its existence proves the user is valid. If it's not found, redirect
// to the login page
Authorization authToken = adminBean.getAuthToken();
if( authToken == null ) {
response.sendRedirect( "/mainctrl/bbs/admin" );
return;
}
%>
<% ////////////////////
// Security check
// make sure the user is authorized to administer users:
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
ForumPermissions permissions = forumFactory.getPermissions(authToken);
boolean isSystemAdmin = permissions.get(ForumPermissions.SYSTEM_ADMIN);
boolean isUserAdmin = permissions.get(ForumPermissions.FORUM_ADMIN);
// redirect to error page if we're not a forum admin or a system admin
if( !isUserAdmin && !isSystemAdmin ) {
request.setAttribute("message","您没有权限管理论坛。");
response.sendRedirect("error.jsp");
return;
}
%>
<% ////////////////////
// get parameters
int forumID = ParamUtils.getIntParameter(request,"forum",-1);
boolean doDeleteThread = ParamUtils.getBooleanParameter(request,"doDeleteThread");
boolean doDeleteMessage = ParamUtils.getBooleanParameter(request,"doDeleteMessage");
int threadID = ParamUtils.getIntParameter(request,"thread",-1);
int messageID = ParamUtils.getIntParameter(request,"message",-1);
int start = ParamUtils.getIntParameter(request,"start",START);
int range = ParamUtils.getIntParameter(request,"range",RANGE);
%>
<% //////////////////////////////////
// global error variables
String errorMessage = "";
boolean noForumSpecified = (forumID < 0);
boolean noThreadSpecified = (threadID < 0);
%>
<% ////////////////////
// make a profile manager
ProfileManager manager = forumFactory.getProfileManager();
%>
<% //////////////////////////
// delete an entire thread
if( doDeleteThread ) {
Forum tempForum = forumFactory.getForum(forumID);
ForumThread tempThread = tempForum.getThread(threadID);
tempForum.deleteThread(tempThread);
response.sendRedirect("forumContent.jsp?forum=" + forumID);
return;
}
else if( doDeleteMessage ) {
Forum tempForum = forumFactory.getForum(forumID);
ForumThread tempThread = tempForum.getThread(threadID);
ForumMessage tempMessage = tempThread.getMessage(messageID);
tempThread.deleteMessage(tempMessage);
response.sendRedirect("threadContent.jsp?forum=" + forumID + "&thread=" + threadID);
return;
}
%>
<html>
<head>
<title></title>
<link rel="stylesheet" href="style/global.css">
</head>
<body background="images/shadowBack.gif" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<% ///////////////////////
// pageTitleInfo variable (used by include/pageTitle.jsp)
String[] pageTitleInfo = { "论坛 : 管理论题内容" };
%>
<% ///////////////////
// pageTitle include
%><%@ include file="include/pageTitle.jsp" %>
<p>
<% //////////////////////
// show the name of the forum we're working with (if one was selected)
Forum currentForum = null;
if( !noForumSpecified ) {
try {
currentForum = forumFactory.getForum(forumID);
%>
您正在管理论坛: <b><%= currentForum.getName() %></b>,
论题: <strong><%= currentForum.getThread(threadID).getName() %></strong>
<% }
catch( ForumNotFoundException fnfe ) {
%>
<span class="errorText">没有发现此论坛。</span>
<% }
catch( UnauthorizedException ue ) {
%>
<span class="errorText">您没有权限管理此论坛。</span>
<% }
}
%>
<p>
<form action="forumContent.jsp">
<input type="hidden" name="forum" value="<%= forumID %>">
<input type="submit" value="取消 / 返回">
</form>
<p>
<%-- thread table --%>
<%
ForumThread thread = currentForum.getThread(threadID);
TreeWalker walker = thread.treeWalker();
ForumMessage rootMessage = walker.getRoot();
%>
<table bgcolor="#cccccc" cellpadding=0 cellspacing=0 border=0 width="100%">
<td>
<table bgcolor="#cccccc" cellpadding=3 cellspacing=1 border=0 width="100%">
<tr bgcolor="#dddddd">
<td class="forumListHeader" width="1%" nowrap bgcolor="#cccccc"><b>删除?</b></td>
<td class="forumListHeader" width="99%"> </td>
</tr>
<tr>
<form>
<td width="1%" class="forumListCell" align="center">
<input type="radio"
onclick="if(confirm('你确定要删除此帖子和它所有的回帖吗?')){location.href='threadContent.jsp?forum=<%= forumID %>&thread=<%= threadID %>&doDeleteThread=true';}">
<font size="-2">(删除论题)</font>
</td>
<td class="forumListCell" width="99%">
<table cellpadding=2 cellspacing=0 border=0 width="100%">
<tr bgcolor="#dddddd">
<td><b><%= rootMessage.getSubject() %></b></td>
</tr>
<tr bgcolor="#eeeeee">
<% String rootMsgUsername = "<i>Anonymous</i>";
User rootMsgUser = rootMessage.getUser();
if( !rootMessage.getUser().isAnonymous() ) {
rootMsgUsername = rootMsgUser.getUsername();
}
%>
<td><font size="-2"><b>作者:<%= rootMsgUsername %>,日期:<%= rootMessage.getCreationDate() %></b></font></td>
</tr>
<tr>
<td><%= rootMessage.getBody() %></td>
</tr>
</table>
</td>
</form>
</tr>
<%= printChildren( walker, currentForum, thread, rootMessage, 0 ) %>
</table></td></table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -