%@ page import="java.io.*,
java.util.*,
java.text.*,
com.Yasna.forum.*,
com.Yasna.forum.util.*"
%>
<%@ include file="../authenticate_i.jsp" %>
<%! ////////////////
// global variables
SimpleDateFormat dateFormatter
= new SimpleDateFormat("EEEEE MMMMM d, '@'hh:mm:ss z");
/**
* Print a child message
*/
private String printChildMessage( Forum forum, ForumThread thread, ForumMessage message, int indentation, String mode, boolean canReply )
{
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("
");
// buf.append("");
buf.append("");
buf.append("");
buf.append("");
buf.append(" ");
buf.append("");
if( msgIsAnonymous ) {
String displayName = "Anonymous";
String savedName = message.getProperty("name");
String savedEmail = message.getProperty("email");
if( savedName != null ) {
displayName = "" + savedName + "";
}
if( savedEmail != null ) {
displayName = "" + displayName + "";
}
buf.append("posted by " + displayName);
} else {
if( author.isEmailVisible() ) {
userName = "" + userName + "";
}
buf.append("posted by ").append(userName);
if( author.isNameVisible() && (authorName!=null && !authorName.equals("") && !authorName.equals(author.getUsername())) ) {
buf.append(" ( ");
if( author.isEmailVisible() ) {
buf.append("");
}
buf.append(authorName);
if( author.isEmailVisible() ) {
buf.append("");
}
buf.append(" )");
}
}
//if( authorEmail != null && !authorEmail.equals("") ) {
// buf.append(" ").append(authorEmail).append("");
//}
buf.append(" on " + dateFormatter.format(creationDate) + "");
if (canReply) {
buf.append("
");
}
buf.append(" | ");
buf.append(" ");
buf.append("| ");
buf.append( (msgBody!=null)?msgBody:" " );
buf.append(" | ");
buf.append(" ");
// buf.append(" ");
// buf.append(" | ");
// buf.append("
");
// buf.append("
\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, boolean canReply )
{
StringBuffer buf = new StringBuffer();
buf.append( printChildMessage( forum, thread, message, indentation, mode, canReply ) );
// recursive call
int numChildren = walker.getChildCount(message);
if( numChildren > 0 ) {
for( int i=0; i
<% //////////////////////
// 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 = "No forum specified or invalid forum ID.";
}
else if( notAuthorizedToViewForum ) {
errorMessage = "No permission to view this forum.";
}
else if( forumNotFound ) {
errorMessage = "Requested forum was not found in the system.";
}
else if( threadNotFound ) {
errorMessage = "Requested thread was not found in the system.";
}
else if( rootMessageNotFound ) {
errorMessage = "Requested message was not found in the system.";
}
else {
errorMessage = "General error occured. Please contact the "
+ "administrator and bug him/her.";
}
request.setAttribute("message",errorMessage);
response.sendRedirect("../error/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();
%>
<%
boolean canReply = false;
boolean canPost = false;
try {
canReply = forum.hasPermission(ForumPermissions.CREATE_MESSAGE);
} catch (Exception ignore) {}
try {
canPost = forum.hasPermission(ForumPermissions.CREATE_THREAD);
} catch (Exception ignore) {}
%>
<% /////////////
// Header
// The header file looks for the following variables.
String pageTitle = "[Boulder Biodiesel] " + threadName;
%>
<%@ include file="../header_i.jsp" %>
<% /////////////
// Toolbar
// The toolbar file looks for the following variables. To make a particular
// "button" not appear, set a variable to null.
boolean showToolbar = true;
String viewLink = "../forum/?forum=" + forumID;
String postLink = (canPost) ? "../forum/post.jsp?forum=" + forumID : null;
String replyLink = (canReply) ? "../forum/post.jsp?reply=true&forum=" + forumID + "&thread=" + threadID + "&message=" + rootMessageID : null;
String searchLink = null;
// we can show a link to a user account if the user is logged in (handled
// in the toolbar jsp)
String accountLink = "../forum/userAccount.jsp";
%>
<%@ include file="../toolbar_i.jsp" %>
<% ////////////////////
// breadcrumb variable
String[][] breadcrumbs = {
{ "Home", "../" },
{ "Forum", "../forum" },
{ threadName, "" }
};
%>
<%@ include file="../breadcrumb_i.jsp" %>
<%@ include file="../forum/search_i.jsp" %>
<%-- root message --%>
<% if( rootMsgIsAnonymous ) {
String savedName = rootMessage.getProperty("name");
String savedEmail = rootMessage.getProperty("email");
if( savedEmail != null && savedName != null ) {
authorName = "" + savedName + "";
}
else {
if( savedName == null ) {
authorName = "Anonymous";
}
else {
authorName = savedName;
}
}
%>
posted by <%= authorName %>
<% } else { %>
<% if( author.isEmailVisible() ) { %>
<% userName = "" + userName + ""; %>
<% } %>
posted by <%= userName %>
<% if( author.isNameVisible() && (authorName!=null && !authorName.equals("") && !authorName.equals(author.getUsername())) ) { %>
( <% if( author.isEmailVisible() ) { %>
<% } %><%= authorName %><% if( author.isEmailVisible()) { %>
<% } %> )
<% } %>
<% } %>
on <%= dateFormatter.format(creationDate) %>
<% if (canReply) { %>
<% } %>
|
| <%= (rootMsgBody!=null) ? rootMsgBody : " " %> |
<% /////////////////////
// print out the number of replies
int numReplies = thread.getMessageCount()-1;
%><%--
// There <%= (numReplies==1) ? "is" : "are" %> <%= numReplies %> <%= (numReplies==1) ? "reply" : "replies" %> to this message.
--%>
<% /////////////////////////
// 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
<%= buf.toString() %>
<% } %>
|
<% /////////////////////
// page footer
%>
<%@ include file="../footer_i.jsp" %>