global.jsp

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

JSP
478
字号
<%/** *	$RCSfile: global.jsp,v $ *	$Revision: 1.19 $ *	$Date: 2002/08/09 22:39:46 $ */%><%@ page import="java.text.*,                 java.util.*,                 com.jivesoftware.util.*,                 com.jivesoftware.forum.*,                 com.jivesoftware.forum.util.*"%><%! // global variables    // default number of threads to show    static final int DEFAULT_THREAD_RANGE = 15;    // default number of messages to show    static final int DEFAULT_MESSAGE_RANGE = 15;    // possible values for a thread range    static final int[] THREAD_RANGES = {15, 30, 50, 100};    // possible values for message ranges    static final int[] MESSAGE_RANGES = {5, 15, 30, 50, 100};    // Date constants    static final long MONTH = JiveGlobals.DAY * 30;%><%  // Get the Jive locale:    Locale locale = JiveGlobals.getLocale();    // Check to see if Jive Forums is properly installed    if (!"true".equals(JiveGlobals.getJiveProperty("setup"))) {        throw new Exception(SkinUtils.getLocalizedString("skin.default.global.jive_not_setup",locale));    }    // Check to see if a Jive authorization token exists    Authorization authToken = null;    try {        authToken = AuthorizationFactory.getAuthorization(request, response);    }    catch (UnauthorizedException ue) {        authToken = AuthorizationFactory.getAnonymousAuthorization();    }    // Indicate if the user is a guest:    boolean isGuest = authToken.isAnonymous();    // Get the forum factory object.    ForumFactory forumFactory = ForumFactory.getInstance(authToken);    // Get the user of this page    User pageUser = null;    if (!isGuest) {	    pageUser = forumFactory.getUserManager().getUser(authToken.getUserID());        // Check if the user has a custom locale specified:        if ("true".equals(JiveGlobals.getJiveProperty("skin.default.usersChooseLocale"))) {            Locale userLocale = SkinUtils.localeCodeToLocale(pageUser.getProperty("jiveLocale"));            if (userLocale != null) {                locale = userLocale;            }        }    }    else {        // See if the guest has a custom locale specified:        if ("true".equals(JiveGlobals.getJiveProperty("skin.default.usersChooseLocale"))) {            Cookie cookie = SkinUtils.getCookie(request,"jiveLocale");            if (cookie != null) {                Locale userLocale = SkinUtils.localeCodeToLocale(cookie.getValue());                if (userLocale != null) {                    locale = userLocale;                }            }        }    }    // The last time the user visited this page    Date lastVisited = new Date(SkinUtils.getLastVisited(request,response));    // The number of messages a user wants to show per page    int userMessageRange = getMessageRange(request,response,pageUser);%><%! // global methods    // Returns the URL path of the JiveServlet    private static String getPathToJiveServlet(HttpServletRequest request) {        String uri = request.getRequestURI();        String serv = request.getServletPath();        int pos = uri.indexOf(serv);        String path = null;        if (pos == -1) {            pos = uri.lastIndexOf("/");            if (pos > -1) {                path = uri.substring(0, uri.lastIndexOf("/"));            } else {                path = "/";            }        } else {            path = uri.substring(0, pos);        }        return path;    }    // Sets the URL we should redirect to in the session:    private static void setRedirectURL(HttpServletRequest request) {        StringBuffer fullURL = HttpUtils.getRequestURL(request);        if (request.getQueryString() != null) {            fullURL.append("?").append(request.getQueryString());        }        request.getSession().setAttribute("jive.redirect", fullURL.toString());    }    /**     * Returns true if the page user is a moderator.     */    private boolean isModerator(ForumFactory factory, Forum forum) {        boolean isModerator = false;        if (factory.hasPermission(ForumPermissions.SYSTEM_ADMIN)                || factory.hasPermission(ForumPermissions.FORUM_ADMIN)                || factory.hasPermission(ForumPermissions.MODERATE_THREADS)                || factory.hasPermission(ForumPermissions.MODERATE_MESSAGES))        {            isModerator = true;        }        else if (forum.hasPermission(ForumPermissions.SYSTEM_ADMIN)                || forum.hasPermission(ForumPermissions.FORUM_ADMIN)                || forum.hasPermission(ForumPermissions.MODERATE_THREADS)                || forum.hasPermission(ForumPermissions.MODERATE_MESSAGES))        {            isModerator = true;        }        if (!isModerator) {            // Check the category as a final check:            ForumCategory cat = forum.getForumCategory();            if (cat.hasPermission(ForumPermissions.SYSTEM_ADMIN)                || cat.hasPermission(ForumPermissions.CATEGORY_ADMIN)                || cat.hasPermission(ForumPermissions.FORUM_ADMIN)                || cat.hasPermission(ForumPermissions.MODERATE_THREADS)                || cat.hasPermission(ForumPermissions.MODERATE_MESSAGES))            {                isModerator = true;            }        }        return isModerator;    }	// Returns the number of threads per forum listing to display for the user	private static int getThreadRange(HttpServletRequest request,			HttpServletResponse response, User user)	{		int threadRange = ParamUtils.getIntParameter(request,"thRange",-1);		if (threadRange > -1) {			return threadRange;		} else {			threadRange = DEFAULT_THREAD_RANGE;			if (user != null) {				try {					threadRange = Integer.parseInt(user.getProperty("jiveThreadRange"));				} catch (Exception e) {}			}			else {				try {                    threadRange = Integer.parseInt(SkinUtils.getCookie(request,"jiveThreadRange").getValue().trim());				} catch (Exception e) {}			}			return threadRange;		}	}	// Returns the number of messages to display.	private static int getMessageRange(HttpServletRequest request,			HttpServletResponse response, User user)	{		int messageRange = ParamUtils.getIntParameter(request,"msRange",-1);		if (messageRange > -1) {			return messageRange;		} else {			messageRange = DEFAULT_MESSAGE_RANGE;			if (user != null) {				try {					messageRange = Integer.parseInt(user.getProperty("jiveMessageRange"));				} catch (Exception e) {}			}			else {				try {                    messageRange = Integer.parseInt(SkinUtils.getCookie(request,"jiveMessageRange").getValue().trim());				} catch (Exception e) {}			}			return messageRange;		}	}	// Prints out a group of links to paginate through thread listings, ie:	// "X page(s) [ 1 2 3 4 5 ... 30 | > ]"	private static String getForumPaginator(long forumID, int topicCount,			int numPages, int start, int range, Locale locale)	{        // If there is only one page, we won't show any pagination:        if (numPages == 1) {            return "";        }		StringBuffer buf = new StringBuffer();		// "["        buf.append(" ");		buf.append(SkinUtils.getLocalizedString("skin.default.global.left_bracket",locale));        buf.append(" ");		// Print out a left arrow if necessary		if (start > 0) {			buf.append("<a href=\"forum.jsp?forum=");			buf.append(forumID);			buf.append("&start=");			buf.append((start-range));			buf.append("&thRange=");			buf.append(range);			buf.append("\" class=\"forum\" title=\"");            buf.append(SkinUtils.getLocalizedString("skin.default.global.previous_page",locale));            buf.append("\">");            buf.append("<img src=\"images/prev.gif\" width=\"10\" height=\"10\" hspace=\"2\" border=\"0\">");            buf.append("</a>");            buf.append("<img src=\"images/blank.gif\" width=\"5\" height=\"1\" border=\"0\">");		}		// Calculate the starting point & end points (the range of pages to display)		int currentPage = (start/range)+1;		int lo = currentPage - 5;		if (lo <= 0) {			lo = 1;		}		int hi = currentPage + 5;		// print out a link to the first page if we're beyond that page		if (lo > 2) {			buf.append("<a href=\"forum.jsp?forum=");			buf.append(forumID);			buf.append("&start=0\" class=\"forum\" title=\"");            buf.append(SkinUtils.getLocalizedString("skin.default.thread.go_first_page",locale));

⌨️ 快捷键说明

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