📄 yazdstate.java
字号:
/**
* Copyright (C) 2001 Yasna.com. All rights reserved.
*
* ===================================================================
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* Yasna.com (http://www.yasna.com)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Yazd" and "Yasna.com" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please
* contact yazd@yasna.com.
*
* 5. Products derived from this software may not be called "Yazd",
* nor may "Yazd" appear in their name, without prior written
* permission of Yasna.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of Yasna.com. For more information
* on Yasna.com, please see <http://www.yasna.com>.
*/
/**
* Copyright (C) 2000 CoolServlets.com. All rights reserved.
*
* ===================================================================
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* CoolServlets.com (http://www.coolservlets.com)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Jive" and "CoolServlets.com" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please
* contact webmaster@coolservlets.com.
*
* 5. Products derived from this software may not be called "Jive",
* nor may "Jive" appear in their name, without prior written
* permission of CoolServlets.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of CoolServlets.com. For more information
* on CoolServlets.com, please see <http://www.coolservlets.com>.
*/
package com.Yasna.forum.tags;
import java.util.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import com.Yasna.forum.*;
/**
* Maintains Yazd state information for the user session.
* Provides methods required for maintaining the
* user session state information.
*
* @see YazdRequest
*
* @author Glenn Nielsen
*/
public class YazdState implements HttpSessionBindingListener
{
private Authorization authorization = null;
// Keep track of user display preferences
private int message_depth = 1;
private int thread_depth = 3;
private int items_per_page = 25;
// Keep track of currently selected forum, thread, and message
// for forum navigation
private int forumID = -1;
private int threadID = -1;
private int messageID = -1;
private int parentID = -1;
// Flag whether the user is logged in
private boolean logged_in = false;
// Date of users last session
private Date lastVisit = null;
// Date of users last use of current session
private Date nextVisit = null;
// Variables for tracking last visist to a Forum
private Map nextForumVisit = new HashMap();
private Map lastForumVisit = new HashMap();
private Map lastForumVisitCookie = new HashMap();
// Variables for tracking previous messages page
private Map prevMessages = new HashMap();
// And some constants for use with extended user properties
public final static String LAST_VISIT = "lastVisitDate";
public final static String THREAD_DEPTH = "threadDepth";
public final static String MESSAGE_DEPTH = "messageDepth";
public final static String ITEMS_PER_PAGE = "itemsPerPage";
public final static String LAST_FORUM_VISIT = "lastForumVisitDate_";
public final static int COOKIE_EXPIRE = 60*60*24*365;
/**
* Required for implementing interface
* HttpSessionBindingListener
*/
public final void valueBound(HttpSessionBindingEvent e)
{
}
/**
* Required for implementing interface
* HttpSessionBindingListener, used to save the
* date and time of users lastVisit to Yazd.
* If forums were visited, save nextForumVisit date
* and time as an extended user property.
*/
public final void valueUnbound(HttpSessionBindingEvent e)
{
saveLastVisit();
}
/**
* If user is logged in save the
* date and time user last used current session
* as their lastVisist to Yazd.
* If forums were visited, save nextForumVisit date
* and time as an extended user property.
*/
public final void saveLastVisit()
{
if( nextVisit == null )return;
User user;
ForumFactory ff = ForumFactory.getInstance(authorization);
if( ff == null )return;
ProfileManager pm = ff.getProfileManager();
try {
user = pm.getUser(authorization.getUserID());
} catch( UserNotFoundException ex ) {
return;
}
if( user.isAnonymous() ) {
return;
}
user.setProperty(LAST_VISIT,"" + nextVisit.getTime());
// Save next lastForumVisit dates to extended user properties
String tmp;
Date last;
for( Iterator it=nextForumVisit.keySet().iterator(); it.hasNext(); ) {
tmp = (String)it.next();
last = (Date)nextForumVisit.get(tmp);
user.setProperty( tmp, "" + last.getTime());
}
}
/**
* Update users Authorization state information
* for current session.
*/
public final void setAuthorization(Authorization auth)
{
authorization = auth;
}
/**
* Get users Authorization state information
* for current session.
*
* @return users Authorization
*/
public final Authorization getAuthorization()
{
return authorization;
}
/**
* Set the users currently selected forum
* as session state information
*/
public final void setForumID(int id)
{
forumID=id;
}
/**
* Get the users currently selected forum
* from session state information
*
* @return forumID
*/
public final int getForumID()
{
return forumID;
}
/**
* Set the users currently selected thread
* as session state information
*/
public final void setThreadID(int id)
{
threadID=id;
}
/**
* Get the users currently selected thread
* from session state information
*
* @return threadID
*/
public final int getThreadID()
{
return threadID;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -