📄 post.jsp
字号:
<%
/**
* $RCSfile: post.jsp,v $
* $Revision: 1.4 $
* $Date: 2000/12/27 22:39:45 $
*/
%>
<%@ page
import="java.text.*,
com.coolservlets.forum.*,
com.coolservlets.forum.util.*,
com.everstar.bbs.*"
errorPage="error.jsp"
%>
<%! final static String DEFAULT_REDIRECT_PAGE = "viewMessage.jsp";
final static String STR_TYPE_NEW = "new";
final static String STR_TYPE_REPLY = "reply";
final static String STR_TYPE_EDIT = "edit";
final static String STR_ACTION_DOPOST = "doPost";
final static int TYPE_NEW = 1;
final static int TYPE_REPLY = 2;
final static int TYPE_EDIT = 4;
final static int ACTION_DOPOST = 1;
//SimpleDateFormat dateFormatter = new SimpleDateFormat( "EEEE, MMM d, yyyy" );
//SimpleDateFormat timeFormatter = new SimpleDateFormat( "h:mm a, z" );
SimpleDateFormat dateFormatter = new SimpleDateFormat( "yyyy.MM.dd" );
SimpleDateFormat timeFormatter = new SimpleDateFormat( "HH:mm" );
//////////////////////////////////////////////////////////////
// Count: clickedtimes Author:Bruce Date:2001/3/28
DbMessageCount dbMessageCount = new DbMessageCount();
//////////////////////////////////////////////////////////////
%>
<% ////////////////////////
// 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 forumID = ParamUtils.getIntParameter(request, "forum", -1); // forumID: Forum to post to
int threadID = ParamUtils.getIntParameter(request, "thread", -1); // parentID: Parent message ID
int parentID = ParamUtils.getIntParameter(request, "message", -1); // threadID: Thread to post to
int iconID = ParamUtils.getIntParameter(request, "IconID", -1); //Added by Jack
String redirectPage = ParamUtils.getParameter(request, "redirectPage"); // redirectPage: Where to go when this post is successful
String postTypeStr = ParamUtils.getParameter(request, "postType"); // postType: either "new" or "reply" or "edit"
String postActionStr = ParamUtils.getParameter(request, "postAction"); // postAction: either blank or "doPost"
String subject = ParamUtils.getParameter(request, "subject"); // subject: subject of the message
String body = ParamUtils.getParameter(request, "body"); // body: body of the message
int postType = 0;
int postAction = 0;
if (redirectPage == null || redirectPage.length() == 0) {
redirectPage = DEFAULT_REDIRECT_PAGE;
}
// New is default postType
if (postTypeStr == null) {
postType = TYPE_NEW;
postTypeStr = STR_TYPE_NEW;
} else if (STR_TYPE_NEW.equals(postTypeStr)) {
postType = TYPE_NEW;
} else if (STR_TYPE_REPLY.equals(postTypeStr)) {
postType = TYPE_REPLY;
} else if (STR_TYPE_EDIT.equals(postTypeStr)) {
postType = TYPE_EDIT;
}
if (STR_ACTION_DOPOST.equals(postActionStr)) {
postAction = ACTION_DOPOST;
}
%>
<% // Get a ForumFactory object, check if it is null. If it is null, redirect to the error page.
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
// Get a forum object, redirect on error:
Forum forum = forumFactory.getForum(forumID);
// Get a profile manager and create the user object. If the userID of the authorization
// token can't be found, redirect to the error page
ProfileManager manager = forumFactory.getProfileManager();
User thisUser = manager.getUser( authToken.getUserID() );
%>
<% // If this is a reply, setup the parent message and the thread objects
ForumThread thread = null;
ForumMessage parentMessage = null;
if (postType == TYPE_REPLY || postType == TYPE_EDIT) {
thread = forum.getThread( threadID ); // throws ForumThreadNotFoundException
parentMessage = thread.getMessage( parentID ); // throws ForumMessageNotFoundException
}
%>
<% // Create the message only if we're posting or replying to a message:
if (postAction == ACTION_DOPOST) {
ForumMessage newMessage = null;
int messageID = -1;
if (subject == null || body == null) {
throw new Exception( "Please enter the " + (subject == null ? "subject " : "") + (body == null ? "message" : ""));
}
//////////////////////////////////////////////////////////////////////
//Added by Jack 2001-04-09.
int strNum = subject.indexOf("---[");
if(strNum==-1){
subject = subject + " ---["+String.valueOf(body.length())+" byte(s)]" ;
}else{
subject = subject.substring(0,strNum);
subject = subject + " ---["+String.valueOf(body.length())+" byte(s)]" ;
}
/////////////////////////////////////////////////////////////////////
//try {
if (postType == TYPE_EDIT) {
if (parentMessage.getUser().getID() != authToken.getUserID() ||
(System.currentTimeMillis() > parentMessage.getCreationDate().getTime() + 3 * 3600 * 1000)) {
throw new Exception( "The message can only be changed within 2-3 hours after creation" );
}
parentMessage.setSubject( subject );
parentMessage.setBody( body );
parentMessage.setProperty( "IP", request.getRemoteAddr() );
messageID = parentID;
} else {
newMessage = forum.createMessage( thisUser );
newMessage.setSubject( subject );
newMessage.setBody( body );
newMessage.setProperty( "IP", request.getRemoteAddr() );
messageID = newMessage.getID();
//////////////////////////////////////////////////////////////
// Insert a recorder to the jiveMsgCount Author:Bruce Date:2001/3/28
try {
dbMessageCount.insMsgCount(messageID);
}
catch( Exception tnfe ) {
//response.sendRedirect( "error.jsp?message=" + URLEncoder.encode("The thread does not exist") );
return;
}
// Insert icon Author :Jack Date:2001-04-09
dbMessageCount.saveForumIcon(messageID,iconID);
//////////////////////////////////////////////////////////////
if (postType == TYPE_REPLY) {
thread.addMessage( parentMessage, newMessage );
}
else if (postType == TYPE_NEW) {
// make new thread with the new message as the root.
thread = forum.createThread(newMessage);
forum.addThread(thread);
threadID = thread.getID();
}
}
//}
//catch( UnauthorizedException ue) {
// System.err.println( "servletforum/post.jsp: " + ue );
// response.sendRedirect( "error.jsp?message=" + URLEncoder.encode("Not authorized to post messages here.") );
// return;
//}
// at this point, the message was created and added successfully,
// so redirect to the redirect page:
response.sendRedirect( redirectPage + "?forum=" + forumID + "&thread=" + threadID + "&parent=" + parentID + "&message=" + messageID);
return;
}
%>
<% /////////////////
// header include
String title = "Jive: Post Message";
%>
<%@ include file="header.jsp" %>
<font face="verdana" size="2"><b><a href="index.jsp" class="normal">Home</a>
>
<a href="viewForum.jsp?forum=<%= forumID %>" class="normal"><%= forum.getName() %></a>
></b>
<% if (postType == TYPE_REPLY) { %>
Reply to: <b><%= parentMessage.getSubject() %></b>
<% } else if (postType == TYPE_NEW) { %>
Post a new message
<% } %>
</font>
<p>
<% if (postType == TYPE_REPLY || postType == TYPE_EDIT) { %>
<%-- 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%">
<font face="Trebuchet MS">
<b><%= parentMessage.getSubject() %></b>
</font>
<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -