postutils.jsp

来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· JSP 代码 · 共 129 行

JSP
129
字号
<%/** *	$RCSfile: postUtils.jsp,v $ *	$Revision: 1.2 $ *	$Date: 2002/07/30 14:53:58 $ */%><%@ page import="com.jivesoftware.forum.*,                 com.jivesoftware.forum.util.*"%><%! // Utility methods for posting messages.        /**     * Determines if the current user has permission to post in the given forum.     *      * @param isReply a boolean which indicates if this user is posting a reply     * or is creating a new topic.     * @param user the User object posting this message or null if it is a guest.     * @param forumFactory the ForumFactory object (used for perm checking).     * @param forum the Forum we're posting in (used for perm checking).     */    private boolean userHasPostPermission(boolean isReply, User user,            ForumFactory forumFactory, Forum forum)            throws UnauthorizedException    {           // Check if the user is an admin first:        if (forum.hasPermission(ForumPermissions.SYSTEM_ADMIN)                || forum.hasPermission(ForumPermissions.FORUM_ADMIN)                || forum.getForumCategory().hasPermission(ForumPermissions.CATEGORY_ADMIN))        {               return true;        }        boolean hasPermission = false;        if (isReply) {            if (forum.hasPermission(ForumPermissions.CREATE_MESSAGE)                    || forumFactory.hasPermission(ForumPermissions.CREATE_MESSAGE))            {                   hasPermission = true;            }            else {                if (user != null) {                    // throw an UnauthorizedException because this user does                    // not have permission to post a message.                    throw new UnauthorizedException("No permission to post replies in this forum");                }            }        }        // check to see if this use can create new topics        else {            if (forum.hasPermission(ForumPermissions.CREATE_THREAD)                    || forumFactory.hasPermission(ForumPermissions.CREATE_THREAD))            {                   hasPermission = true;            }            else {                if (user != null) {                    // throw an UnauthorizedException because this user does                    // not have permission to post a new topic.                    throw new UnauthorizedException("No permission to post topics in this forum");                }            }        }        return hasPermission;    }        /**     *     */    private ForumMessage postMessage(HttpServletRequest request, boolean isReply,            ForumFactory forumFactory, Forum forum, ForumThread thread,            long messageID, User user, String guestName, String guestEmail,            String subject, String body)            throws ForumMessageNotFoundException, UnauthorizedException    {           // The new message to return.        ForumMessage newMessage = null;        // The parent message we're replying to (if this is a reply).	    ForumMessage parentMessage = null;	    if (isReply) {            if (messageID == -1L) {                parentMessage = thread.getRootMessage();                messageID = parentMessage.getID();            } else {                parentMessage = thread.getMessage(messageID);            }    	}        // Create the new message object        if (user == null) {            newMessage = forumFactory.createMessage();        } else {            newMessage = forumFactory.createMessage(user);        }        newMessage.setSubject(subject);        newMessage.setBody(body);        // set message properties if this is a guest posting        if (user == null) {            if (guestName != null) { newMessage.setProperty("name", guestName); }            if (guestEmail != null) { newMessage.setProperty("email", guestEmail); }        }                // Track the IP if requested        String trackIPs = JiveGlobals.getJiveProperty("skin.default.trackIP");        if (trackIPs == null || "true".equals(trackIPs)) {            String IPAddr = request.getRemoteAddr();            if (IPAddr != null) {                newMessage.setProperty("IP",IPAddr);            }        }                // if this is a reply, add it to the thread        if (isReply) {            thread.addMessage(parentMessage,newMessage);        }        else {            // it is a new posting            thread = forumFactory.createThread(newMessage);            forum.addThread(thread);            // Note: We have to reset the message to be the root message of the            // thread. This call is made in order to get a message object with            // the correct permissions.            newMessage = thread.getRootMessage();        }                return newMessage;    }%>

⌨️ 快捷键说明

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