⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewthread.jsp

📁 JSP聊天系统
💻 JSP
字号:

<%
/**
 *	$RCSfile: viewThread.jsp,v $
 *	$Revision: 1.5.2.3 $
 *	$Date: 2001/01/21 21:30:25 $
 */
%>
<%@ page contentType="text/html;charset=gb2312"%>

<%@	page import="java.io.*,
                 java.util.*,
                 java.text.*,
                 com.coolservlets.forum.*,
                 com.coolservlets.forum.util.*"
	errorPage="error.jsp"
%>

<%!	////////////////
	// global variables
	SimpleDateFormat dateFormatter 
		= new SimpleDateFormat("EEE, MMM d '于' hh:mm:ss");
	
	/**
	 * Print a child message
	 */
	private String printChildMessage( Forum forum, ForumThread thread, ForumMessage message, int indentation, String mode )
	{
		StringBuffer buf = new StringBuffer();
		try {
		if( mode.equals("flat") ) {
			indentation = 0;
		}
		String subject = message.getSubject();
		boolean msgIsAnonymous = message.isAnonymous();
		User author = message.getUser();
		String authorName = author.getName();
		String authorEmail = author.getEmail();
		String userName = author.getUsername();
		int forumID = forum.getID();
		int threadID = thread.getID();
		int messageID = message.getID();
		Date creationDate = message.getCreationDate();
		String msgBody = message.getBody();
		
		buf.append("<table bgcolor=\"#cccccc\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"");
		buf.append( 100-(3*indentation) ).append("%\" align=\"right\">");
		buf.append("<td><table bgcolor=\"#cccccc\" cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"100%\">");
		buf.append("<tr bgcolor=\"#eeeeee\">");
		buf.append("<td width=\"1%\" nowrap>");
		buf.append("<span class=\"messageHeader\">");
		buf.append( subject );
		buf.append("</span>");
		buf.append("<br>");
		buf.append("<span class=\"messageAuthor\">");
		if( msgIsAnonymous ) {
			String displayName = "<i>匿名</i>";
			String savedName = message.getProperty("name");
			String savedEmail = message.getProperty("email");
			if( savedName != null ) {
				displayName = "<i>" + savedName + "</i>";
			}
			if( savedEmail != null ) {
				displayName = "<a href=\"mailto:" + savedEmail + "\">" + displayName + "</a>";
			}
			buf.append(displayName);
		} else {
			
			if( author.isEmailVisible() ) {
				userName = "<a href=\"mailto:" + authorEmail + "\">" + userName + "</a>";
			}
			buf.append("posted by: ").append(userName);
			if( author.isNameVisible() && (authorName!=null && !authorName.equals("")) ) {
				buf.append(" ( ");
				if( author.isEmailVisible() ) {
					buf.append("&nbsp;<i><a href=\"mailto:").append(authorEmail).append("\">");
				}
				buf.append(authorName);
				if( author.isEmailVisible() ) {
					buf.append("</a>");
				}
				buf.append(" )");
			}
		}
		//if( authorEmail != null && !authorEmail.equals("") ) {
		//	buf.append("&nbsp;<i><a href=\"mailto:").append(authorEmail).append("\">").append(authorEmail).append("</a></i>");
		//}
		buf.append("</span>");
		buf.append("</td>");
		buf.append("<td width=\"98%\" align=\"center\">");
		buf.append("<a href=\"post.jsp?reply=true&forum=");
		buf.append(forumID).append("&thread=").append(threadID).append("&message=").append(messageID).append("\"");
		buf.append("><img src=\"images/reply.gif\" width=\"50\" height=\"19\" alt=\"点击这里回应这个消息 \" border=\"0\"></a>");
		buf.append("</td>");
		buf.append("<td width=\"1%\" nowrap align=\"center\">");
		buf.append("<small class=\"date\">Posted ").append(SkinUtils.dateToText(creationDate));
		buf.append("<br><i>").append(dateFormatter.format(creationDate)).append("</i></small>");
		buf.append("</td>");
		buf.append("</tr>");
		buf.append("<tr><td bgcolor=\"#ffffff\" colspan=\"3\">");
		buf.append("<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
		buf.append("<td>").append( (msgBody!=null)?msgBody:"" ).append("</td>");
		buf.append("</table>");
		buf.append("</td>");
		buf.append("</tr>");
		buf.append("</table>");
		buf.append("</td>");
		buf.append("</table>");
		buf.append("<br clear=\"all\"><br>\n\n");
		} 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, String mode )
	{
		StringBuffer buf = new StringBuffer();
		
		buf.append( printChildMessage( forum, thread, message, indentation, mode ) );
		
		// 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), mode )
				);
            }
        }
		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();
	}
%>

<%	///////////////////////
	// page forum variables
	
	// do not delete these
	ForumFactory forumFactory = ForumFactory.getInstance(authToken);
	User user = forumFactory.getProfileManager().getUser(authToken.getUserID());
	long userLastVisitedTime = SkinUtils.getLastVisited(request,response);
%>

<%	//////////////////////
	// get parameters
	int forumID  = ParamUtils.getIntParameter(request,"forum",-1);
	int threadID = ParamUtils.getIntParameter(request,"thread",-1);
	String mode = ParamUtils.getParameter(request,"mode");
	if( mode == null ) {
		mode = "threaded";
	}
%>

<%	//////////////////////
	// page error variables
	
	String errorMessage = "";
	
	boolean invalidForumID = (forumID < 0);
	boolean invalidThreadID = (threadID < 0);
	boolean notAuthorizedToViewForum = false;
	boolean forumNotFound = false;
	boolean threadNotFound = false;
	boolean rootMessageNotFound = false;
%>

<%	//////////////////////////
	// try loading up forums (exceptions may be thrown)
	Forum forum = null;
	try {
		forum = forumFactory.getForum(forumID);
	}
	catch( UnauthorizedException ue ) {
		notAuthorizedToViewForum = true;
	}
	catch( ForumNotFoundException fnfe ) {
		forumNotFound = true;
	}
%>

<%	//////////////////////////////////
	// try loading up the thread
	ForumThread thread = null;
	if( forum != null && !invalidThreadID ) {
		try {
			thread = forum.getThread(threadID);
		} catch( ForumThreadNotFoundException ftnfe ) {}
		if( thread == null ) {
			threadNotFound = true;
		}
	}
%>

<%	///////////////////////
	// Try loading up the root message
	ForumMessage rootMessage = null;
	int rootMessageID = -1;
	rootMessage = thread.getRootMessage();
	rootMessageID = rootMessage.getID();
%>

<%	/////////////////////
	// global error check
	boolean errors = (invalidForumID || invalidThreadID 
		|| notAuthorizedToViewForum || forumNotFound 
		|| threadNotFound || rootMessageNotFound || (forum==null) );
%>

<%	/////////////////////
	// check for errors
	if( errors ) {
		if( invalidForumID ) {
			errorMessage = "您没有指定论坛或者您指定的论坛ID非法  .";
		}
		else if( notAuthorizedToViewForum ) {
			errorMessage = "您没有权利访问这个论坛 .";
		}
		else if( forumNotFound ) {
			errorMessage = "被请求的论坛在系统中不存在.";
		}
		else if( threadNotFound ) {
			errorMessage = "被请求的线索在系统中不存在 .";
		}
		else if( rootMessageNotFound ) {
			errorMessage = "被请求的信息在系统中不存在 .";
		}
		else {
			errorMessage = "发生常规错误 .请联系   "
				+ "管理员求助 .";
		}
		request.setAttribute("message",errorMessage);
		response.sendRedirect("error.jsp");
		return;
	}
%>

<%	//////////////////////
	// get forum properties (assumed no errors at this point)
	String forumName = forum.getName();
	String threadName = thread.getName();
%>

<%	//////////////////////////////
	// get root message properties
	
	User author = rootMessage.getUser();
	int rootMsgAuthorID = author.getID();
	String userName = null;
	String authorName = null;
	String authorEmail = null;
	authorName = author.getName();
	userName = author.getUsername();
	authorEmail = author.getEmail();
	Date creationDate = rootMessage.getCreationDate();
	boolean rootMsgIsAnonymous = rootMessage.isAnonymous();
	//if( authorName == null ) {
	//	rootMsgIsAnonymous = true;
	//}
	String rootMsgSubject = rootMessage.getSubject();
	String rootMsgBody = rootMessage.getBody();
%>

<%	////////////////////
	// page title variable for header
	String title = "交通论坛: " + forumName + ": " + threadName;
%>
<%	/////////////////////
	// page header
%>
<%@ include file="header.jsp" %>


<%	////////////////////
	// breadcrumb variable
	String[][] breadcrumbs = {
		{ "论坛首页", "index.jsp" },
		{ forumName, ("viewForum.jsp?forum="+forumID) },
		{ threadName, "" }
	};
%>
<%@ include file="breadcrumb.jsp" %>


<%	///////////////////
	// toolbar variables
	boolean showToolbar = true;
	String viewLink = "viewForum.jsp?forum="+forumID;
	String postLink = "post.jsp?mode=new&forum="+forumID;
	String replyLink = "post.jsp?reply=true&forum="+forumID+"&thread="+threadID+"&message="+rootMessageID;
	String searchLink = "search.jsp?forum="+forumID;
	String accountLink = "userAccount.jsp";
%>
<%@ include file="toolbar.jsp" %>
<%@ page contentType="text/html;charset=gb2312"%>
<p>

<%-- root message --%>
<table bgcolor="#cccccc" cellpadding="0" cellspacing="0" border="0" width="100%" align="right">
<td><table bgcolor="#cccccc" cellpadding="4" cellspacing="1" border="0" width="100%">
	<tr bgcolor="#eeeeee">
		<td width="1%" nowrap>
			<span class="messageHeader">
			<%= rootMsgSubject %>
			</span>
			<br>
            <span class="messageAuthor"> 
            <%	if( rootMsgIsAnonymous ) { 
					String savedName = rootMessage.getProperty("name");
					String savedEmail = rootMessage.getProperty("email");
					if( savedEmail != null && savedName != null ) {
						authorName = "<a href=\"mailto:" + savedEmail + "\">" + savedName + "</a>";
					}
					else {
						if( savedName == null ) {
							authorName = "<i>匿名</i>";
						}
						else {
							authorName = savedName;
						}
					}
			%>
            发帖人: <%= authorName %> 
            <%	} else { %>
            <%	if( author.isEmailVisible() ) { %>
            <% userName = "<a href=\"mailto:" + authorEmail + "\">" + userName + "</a>"; %>
            <%	} %>
            发表人:<%= userName %> 
            <%	if( author.isNameVisible() && (authorName!=null && !authorName.equals("")) ) { %>
            ( 
            <%	if( author.isEmailVisible() ) { %>
            &nbsp;<i><a href="<a href=mailto:<%= authorEmail %>"> 
            <% } %>
            <%= authorName %> 
            <% if( author.isEmailVisible()) { %>
            </a></i> 
            <% } %>
            ) 
            <%	} %>
            <%	} %>
            </span> </td>
		<td width="98%" align="center">
			<a href="post.jsp?reply=true&forum=<%= forumID %>&thread=<%= threadID %>&message=<%= rootMessageID %>"
			><img src="images/reply.gif" width="50" height="19" alt="点击这里回复这个消息 " border="0"></a>
		</td>
		  <td width="1%" nowrap align="center"> <small class="date"> 发表于<%= SkinUtils.dateToText(creationDate) %> 
            <br>
            <i><%= dateFormatter.format(creationDate) %></i>
			</small>
		</td>
	</tr>
	<tr><td bgcolor="#ffffff" colspan="3">
		<table cellpadding="5" cellspacing="0" border="0" width="100%">
		<td><%= (rootMsgBody!=null)?rootMsgBody:"" %></td>
		</table>
		</td>
	</tr>
</table>
</td>
</table>
<%-- /root message --%>

<br clear="all">
<br>
<%	/////////////////////
	// print out the number of replies
	int numReplies = thread.getMessageCount()-1;
%>
<b>回复帖子数:<%= numReplies %> </b> 
<p>

<%	/////////////////////////
	// print out all child messages:
	
	// if there are children to display:
	if( numReplies > 0 ) {
		StringBuffer buf = new StringBuffer();
		TreeWalker treeWalker = thread.treeWalker();
		int numChildren = treeWalker.getChildCount(rootMessage);
		int indentation = 1;
		for( int i=0; i<numChildren; i++ ) {
			buf.append( 
				printChildren( treeWalker, forum, thread, treeWalker.getChild(rootMessage,i), indentation, mode )
			);
		}
%>
		<%= buf.toString() %>
<%	} %>

<br clear="all">

<%	/////////////////////
	// page footer 
%>
<%@ include file="footer.jsp" %>



⌨️ 快捷键说明

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