⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 onlineuserimpl.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/OnlineUserImpl.java,v 1.46 2006/04/14 17:05:26 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.46 $
 * $Date: 2006/04/14 17:05:26 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * All copyright notices regarding mvnForum MUST remain 
 * intact in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in 
 * the footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Mai  Nguyen  
 */
package com.mvnforum.auth;

import java.awt.image.BufferedImage;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import com.mvnforum.*;
import com.mvnforum.common.MVNCaptchaService;
import com.mvnforum.db.*;
import com.octo.captcha.image.ImageCaptcha;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.util.GenericParamUtil;
import net.myvietnam.mvncore.web.GenericRequest;
import net.myvietnam.mvncore.web.impl.GenericRequestServletImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class OnlineUserImpl implements OnlineUser {

    private static long CHECK_NEW_MESSAGE_INTERVAL = 5 * DateUtil.MINUTE;// five minutes

    private static Log log = LogFactory.getLog(OnlineUserImpl.class);

    private int memberID = MVNForumConstant.MEMBER_ID_OF_GUEST;

    private String memberName = "";

    private int authenticationType = AUTHENTICATION_TYPE_UNAUTHENTICATED;

    private MVNForumPermission permission = null;

    private OnlineUserAction onlineUserAction = new OnlineUserAction();

    private int memberPostsPerPage = 10;
    private int memberMessagesPerPage = 10;

    private boolean invisible = false;

    private int newMessageCount = 0;

    private String memberCssPath = null;
    private String memberLogoPath = null;

    private double hourOffset = 0;
    /* private DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     * Igor: previous line should be: new SimpleDateFormat(..., Locale.US)
     * Otherwise won't work for users who don't have en/US as default.
     */
    private DateFormat timestampFormatter = null;
    private DateFormat dateFormatter = null;

    private Timestamp lastLogonTimestamp = null;

    private Timestamp lastCheckNewMessageTimestamp = null;

    private String lastLogonIP = null;

    private String localeName = "";

    private Locale locale = null;

    private boolean gender = true;

    private ImageCaptcha imageCaptcha = null;

    /**
     * Default access constructor, prevent outsite creation
     * NOTE: the implementation should init the following:
     * - Is Guest or not <br/>
     * - Call initRemoteAddr_UserAgent() <br/>
     * - The memberCssPath <br/>
     * - The memberLogoPath <br/>
     */
    OnlineUserImpl(HttpServletRequest request, boolean isGuest) throws DatabaseException {
        GenericRequest genericRequest = new GenericRequestServletImpl(request);
        init(genericRequest, isGuest);
    }

    OnlineUserImpl(GenericRequest request, boolean isGuest) throws DatabaseException {
        init(request, isGuest);
    }

    private void init(GenericRequest request, boolean isGuest) throws DatabaseException {
        if (isGuest) {
            setMemberID(MVNForumConstant.MEMBER_ID_OF_GUEST);
            setMemberName(MVNForumConfig.getDefaultGuestName());
        }
        getOnlineUserAction().initRemoteAddr_UserAgent(request);
        String contextPath = request.getContextPath();
        memberCssPath = contextPath + MVNForumGlobal.CSS_FULLPATH;
        memberLogoPath = contextPath + MVNForumGlobal.LOGO_FULLPATH;
        if (isGuest && MVNForumConfig.getEnableCompany()) {
            try {
                int companyID = GenericParamUtil.getParameterInt(request, "companyid");
                CompanyBean companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);

                // Load the css Path for this user
                memberCssPath = MyUtil.getCompanyCssPath(companyBean, request.getContextPath());

                // Load the logo Path for this user
                memberLogoPath = MyUtil.getCompanyLogoPath(companyBean, request.getContextPath());
            } catch (ObjectNotFoundException ex) {
                // cannot find the Company in the database, just ignore
            } catch (BadInputException ex) {
                // cannot find the companyid in the request, just ignore
            }
        }
    }

    public int getMemberID() {
        return memberID;
    }

    public String getMemberName() {
        return memberName;
    }

    public boolean isGuest() {
        return ( (memberID==0) || (memberID==MVNForumConstant.MEMBER_ID_OF_GUEST) );
    }

    public boolean isMember() {
        return !isGuest();
    }

    public boolean isInvisibleMember() {
        // @todo: temp implementation
        return this.invisible;
    }

    public int getAuthenticationType() {
        return authenticationType;
    }

    public MVNForumPermission getPermission() {
        return permission;
    }

    public void reloadPermission() {
        try {
            if (isGuest()) {
                permission = MVNForumPermissionFactory.getAnonymousPermission();
            } else {
                permission = MVNForumPermissionFactory.getAuthenticatedPermission(memberID);
            }
        } catch (Exception ex) {
            log.error("Error when reload permission in OnlineUserImpl for memberID = " + memberID , ex);
        }
    }

    public void reloadProfile() {
        try {
            if (isGuest()) {
                // currently just do nothing, implement later
            } else {
                MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forViewCurrentMember(memberID);

                double timeZone = memberBean.getMemberTimeZone();
                localeName = memberBean.getMemberLanguage();
                int postsPerPage = memberBean.getMemberPostsPerPage();

                setTimeZone(timeZone);
                setLocaleName(localeName);
                setGender(memberBean.getMemberGender() != 0);
                setPostsPerPage(postsPerPage);
                setInvisible(memberBean.isInvisible());
            }
        } catch (Exception ex) {
            log.error("Error when reload profile in OnlineUserImpl for memberID = " + memberID , ex);
        }
    }

    public boolean updateNewMessageCount(boolean forceUpdate) {

        if (isGuest()) return false;

        int currentMessageCount = newMessageCount;
        Timestamp now = DateUtil.getCurrentGMTTimestamp();
        long lastRequest = 0;
        if (lastCheckNewMessageTimestamp != null ) {
            lastRequest = lastCheckNewMessageTimestamp.getTime();
        }
        if ((lastCheckNewMessageTimestamp == null) ||
            forceUpdate ||
            ((lastRequest + CHECK_NEW_MESSAGE_INTERVAL) <= now.getTime())) {
            try {
                lastCheckNewMessageTimestamp = now;
                newMessageCount = DAOFactory.getMessageDAO().getNumberOfUnreadNonPublicMessages_inMember_inFolder(memberID, MVNForumConstant.MESSAGE_FOLDER_INBOX);
                if (currentMessageCount < newMessageCount) {
                    return true;
                }
            } catch (Exception ex) {
                log.error("Error when udpate new message count in OnlineUserImpl for memberID = " + memberID , ex);
            }
        }
        return false;
    }

⌨️ 快捷键说明

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