alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/CompanyWebHandler.java,v 1.11 2005/01/26 18:46:52 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.11 $
 * $Date: 2005/01/26 18:46:52 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2005 by MyVietnam.net
 *
 * 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.
 *
 * 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 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@MyVietnam.net
 *
 * @author: Tran Van Giang trangiang1605@users.sourceforge.net
 * @author: Minh Nguyen    minhnn@MyVietnam.net
 */
package com.mvnforum.user;

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

import javax.servlet.http.HttpServletRequest;

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.I18nUtil;
import net.myvietnam.mvncore.util.ParamUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


class CompanyWebHandler {

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

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    CompanyWebHandler() {
    }

    void prepareView(HttpServletRequest 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 = ParamUtil.getParameter(request, "companyid", false);
        String strCompanyEmail = ParamUtil.getParameter(request, "companyemail", false);
        String strCompanyCreationDate = ParamUtil.getParameter(request, "companycreationdate", false);

        int companyID = 0;

        if (strCompanyID.length() > 0) {
            companyID = ParamUtil.getParameterInt(request, "companyid");
        } else if (strCompanyEmail.length() > 0) {
            String companyEmail = ParamUtil.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 = ParamUtil.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
     */
    void prepareListCompanies_forPublic(HttpServletRequest 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  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.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 = ParamUtil.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));
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.