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

📄 companywebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/CompanyWebHandler.java,v 1.46 2006/04/14 17:05:25 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.46 $
 * $Date: 2006/04/14 17:05:25 $
 *
 * ====================================================================
 *
 * 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.admin;

import java.io.*;
import java.sql.Timestamp;
import java.util.*;

import javax.servlet.ServletContext;

import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.db.CompanyBean;
import com.mvnforum.db.DAOFactory;
import com.mvnforum.search.company.CompanyIndexer;
import com.mvnforum.search.company.CompanySearchQuery;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.*;
import net.myvietnam.mvncore.web.fileupload.FileItem;
import net.myvietnam.mvncore.web.fileupload.FileUploadException;
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 processAdd(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, CreateException, DatabaseException, DuplicateKeyException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException, IOException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        String companyName              = GenericParamUtil.getParameterSafe(request, "CompanyName", true);
        String companyAddress           = GenericParamUtil.getParameterSafe(request, "CompanyAddress", false);
        String companyCity              = GenericParamUtil.getParameterSafe(request, "CompanyCity", false);
        String companyCAP               = GenericParamUtil.getParameterSafe(request, "CompanyCAP", false);
        String companyProvince          = GenericParamUtil.getParameterSafe(request, "CompanyProvince", false);
        String companyRegion            = GenericParamUtil.getParameterSafe(request, "CompanyRegion", false);
        String companyPhone             = GenericParamUtil.getParameterSafe(request, "CompanyPhone", false);
        String companyFax               = GenericParamUtil.getParameterSafe(request, "CompanyFax", false);
        String companyWebsite           = GenericParamUtil.getParameterUrl(request, "CompanyWebsite");
        String companyEmail             = GenericParamUtil.getParameterEmail(request, "CompanyEmail");
        String companySpaceName         = GenericParamUtil.getParameterSafe(request, "CompanySpaceName", true);
        String companySpaceHeader       = GenericParamUtil.getParameterSafe(request, "CompanySpaceHeader", false);
        String companySpaceFooter       = GenericParamUtil.getParameterSafe(request, "CompanySpaceFooter", false);
        String companyVATNumber         = GenericParamUtil.getParameterSafe(request, "CompanyVATNumber", true);
        String companyLogo              = "";
        String companyCss               = "";
        Timestamp companyCreationDate   = now;
        Timestamp companyModifiedDate   = now;

        // First, check the alternate key of Company, ensure things is okie before adding Group
        try {
            //Check if alternate key already exists
            DAOFactory.getCompanyDAO().findByAlternateKey_CompanyName(companyName);
            //If so, then we have to throw an exception
            throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same <CompanyName> (" + companyName + ").");
        } catch(ObjectNotFoundException e) {
            //Otherwise we can go ahead
        }

        try {
            //Check if alternate key already exists
            DAOFactory.getCompanyDAO().findByAlternateKey_CompanyEmail(companyEmail);
            //If so, then we have to throw an exception
            throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same <CompanyEmail> (" + companyEmail + ").");
        } catch(ObjectNotFoundException e) {
            //Otherwise we can go ahead
        }

        try {
            //Check if alternate key already exists
            DAOFactory.getCompanyDAO().findByAlternateKey_CompanySpaceName(companySpaceName);
            //If so, then we have to throw an exception
            throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same <CompanySpaceName> (" + companySpaceName + ").");
        } catch(ObjectNotFoundException e) {
            //Otherwise we can go ahead
        }

        // Next, create group for this company
        String groupName        = MVNForumGlobal.COMPANY_GROUP_FREFIX + companyName;
        String groupDesc        = "This is the default generated group for company " + companyName;
        int groupOption         = 0;//@todo review it later

        DAOFactory.getGroupsDAO().create(""/*groupOwnerName*/, groupName, groupDesc,
                               groupOption, now/*groupCreationDate*/, now/*groupModifiedDate*/);

        int groupID = DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupName);

        // Finally, create the company now
        DAOFactory.getCompanyDAO().create(groupID, companyName, companyAddress,
                                companyCity, companyCAP, companyProvince,
                                companyRegion, companyPhone, companyFax,
                                companyWebsite, companyEmail, companySpaceName,
                                companySpaceHeader, companySpaceFooter, companyVATNumber,
                                companyLogo, companyCss, companyCreationDate,
                                companyModifiedDate);

        // create new folder for the company by companyID
        int companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyEmail(companyEmail);

        StringBuffer bufferCompanyFolder = new StringBuffer(128);
        bufferCompanyFolder.append(request.getRealPath(MVNForumGlobal.UPLOADED_COMPANY_DIR));
        bufferCompanyFolder.append(File.separatorChar).append(companyID);
        String companyFolder = bufferCompanyFolder.toString();
        FileUtil.createDir(companyFolder, true);

        // now, add to the Search Index
        CompanyBean justAddedCompanyBean = null;
        try {
            justAddedCompanyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
        } catch (ObjectNotFoundException e) {
            Locale locale = I18nUtil.getLocaleInRequest(request);
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        CompanyIndexer.scheduleAddCompanyTask(justAddedCompanyBean);
    }

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

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

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

        int companyID = 0;

        Locale locale = I18nUtil.getLocaleInRequest(request);

        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);

⌨️ 快捷键说明

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