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

📄 companywebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/CompanyWebHandler.java,v 1.15 2006/04/14 17:05:27 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.15 $
 * $Date: 2006/04/14 17:05:27 $
 *
 * ====================================================================
 *
 * 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: Tran Van Giang 
 * @author: Minh Nguyen    
 */
package com.mvnforum.user;

import java.util.Collection;
import java.util.Locale;

import com.mvnforum.MVNForumConfig;
import com.mvnforum.MVNForumResourceBundle;
import com.mvnforum.auth.*;
import com.mvnforum.db.CompanyBean;
import com.mvnforum.db.DAOFactory;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.GenericParamUtil;
import net.myvietnam.mvncore.util.I18nUtil;
import net.myvietnam.mvncore.web.GenericRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CompanyWebHandler {

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

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    public CompanyWebHandler() {
    }

    public void prepareView(GenericRequest request)
        throws BadInputException, ObjectNotFoundException,
        DatabaseException, AssertionException {

        if (MVNForumConfig.getEnableListCompanies() == false) {
            throw new AssertionException("Cannot show company because LIST_COMPANIES feature is disabled by administrator.");
        }

        Locale locale = I18nUtil.getLocaleInRequest(request);
        String strCompanyID = GenericParamUtil.getParameter(request, "companyid", false);
        String strCompanyEmail = GenericParamUtil.getParameter(request, "companyemail", false);
        String strCompanyCreationDate = GenericParamUtil.getParameter(request, "companycreationdate", false);

        int companyID = 0;

        if (strCompanyID.length() > 0) {
            companyID = GenericParamUtil.getParameterInt(request, "companyid");
        } else if (strCompanyEmail.length() > 0) {
            String companyEmail = GenericParamUtil.getParameterEmail(request, "companyemail"); // check for better security
            try {
                companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyEmail(companyEmail);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_email", new Object[] {companyEmail});
                throw new ObjectNotFoundException(localizedMessage);
            }
        } else if (strCompanyCreationDate.length() > 0) {
            java.util.Date companyCreationDate = GenericParamUtil.getParameterDateUtil(request, "companycreationdate");
            try {
                companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyCreationDate(companyCreationDate);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_creationdate", new Object[] {strCompanyCreationDate});
                throw new ObjectNotFoundException(localizedMessage);
            }
        } else {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_get_info_to_view_company");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot get the information to view company.");
        }

        CompanyBean companyBean = null;
        try {
            companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        request.setAttribute("CompanyBean", companyBean);
    }

    /**
     * This method supports sorting base on many criteria
     */
    public void prepareListCompanies_forPublic(GenericRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException{

        if (MVNForumConfig.getEnableListCompanies() == false) {
            throw new AssertionException("Cannot show company because LIST_COMPANIES feature is disabled by administrator.");
        }

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        //MVNForumPermission permission = onlineUser.getPermission();
        //permission.ensureCanAdminSystem();
        Locale locale = I18nUtil.getLocaleInRequest(request);

        // for sort and order stuff
        String sort  = GenericParamUtil.getParameter(request, "sort");
        String order = GenericParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "CompanyCreationDate";
        if (order.length()== 0) order = "DESC";

        // we continue
        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = GenericParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalCompanies = DAOFactory.getCompanyDAO().getNumberOfCompanies();
        if (offset > totalCompanies) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("The offset is not allowed to be greater than total companies.");
        }

        Collection companyBeans = DAOFactory.getCompanyDAO().getCompanies_withSortSupport_limit(offset, postsPerPage, sort, order);

        request.setAttribute("CompanyBeans", companyBeans);
        request.setAttribute("TotalCompanies", new Integer(totalCompanies));
        request.setAttribute("offset", new Integer(offset));
    }
}

⌨️ 快捷键说明

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