1 41 package com.mvnforum.user; 42 43 import java.util.Collection ; 44 import java.util.Locale ; 45 46 import com.mvnforum.MVNForumConfig; 47 import com.mvnforum.MVNForumResourceBundle; 48 import com.mvnforum.auth.*; 49 import com.mvnforum.db.CompanyBean; 50 import com.mvnforum.db.DAOFactory; 51 import net.myvietnam.mvncore.exception.*; 52 import net.myvietnam.mvncore.util.GenericParamUtil; 53 import net.myvietnam.mvncore.util.I18nUtil; 54 import net.myvietnam.mvncore.web.GenericRequest; 55 import org.apache.commons.logging.Log; 56 import org.apache.commons.logging.LogFactory; 57 58 public class CompanyWebHandler { 59 60 private static Log log = LogFactory.getLog(CompanyWebHandler.class); 61 62 private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance(); 63 64 public CompanyWebHandler() { 65 } 66 67 public void prepareView(GenericRequest request) 68 throws BadInputException, ObjectNotFoundException, 69 DatabaseException, AssertionException { 70 71 if (MVNForumConfig.getEnableListCompanies() == false) { 72 throw new AssertionException("Cannot show company because LIST_COMPANIES feature is disabled by administrator."); 73 } 74 75 Locale locale = I18nUtil.getLocaleInRequest(request); 76 String strCompanyID = GenericParamUtil.getParameter(request, "companyid", false); 77 String strCompanyEmail = GenericParamUtil.getParameter(request, "companyemail", false); 78 String strCompanyCreationDate = GenericParamUtil.getParameter(request, "companycreationdate", false); 79 80 int companyID = 0; 81 82 if (strCompanyID.length() > 0) { 83 companyID = GenericParamUtil.getParameterInt(request, "companyid"); 84 } else if (strCompanyEmail.length() > 0) { 85 String companyEmail = GenericParamUtil.getParameterEmail(request, "companyemail"); try { 87 companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyEmail(companyEmail); 88 } catch (ObjectNotFoundException e) { 89 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_email", new Object [] {companyEmail}); 90 throw new ObjectNotFoundException(localizedMessage); 91 } 92 } else if (strCompanyCreationDate.length() > 0) { 93 java.util.Date companyCreationDate = GenericParamUtil.getParameterDateUtil(request, "companycreationdate"); 94 try { 95 companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyCreationDate(companyCreationDate); 96 } catch (ObjectNotFoundException e) { 97 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_creationdate", new Object [] {strCompanyCreationDate}); 98 throw new ObjectNotFoundException(localizedMessage); 99 } 100 } else { 101 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_get_info_to_view_company"); 102 throw new BadInputException(localizedMessage); 103 } 105 106 CompanyBean companyBean = null; 107 try { 108 companyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 109 } catch (ObjectNotFoundException e) { 110 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 111 throw new ObjectNotFoundException(localizedMessage); 112 } 113 request.setAttribute("CompanyBean", companyBean); 114 } 115 116 119 public void prepareListCompanies_forPublic(GenericRequest request) 120 throws DatabaseException, AssertionException, BadInputException, AuthenticationException{ 121 122 if (MVNForumConfig.getEnableListCompanies() == false) { 123 throw new AssertionException("Cannot show company because LIST_COMPANIES feature is disabled by administrator."); 124 } 125 126 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 127 Locale locale = I18nUtil.getLocaleInRequest(request); 130 131 String sort = GenericParamUtil.getParameter(request, "sort"); 133 String order = GenericParamUtil.getParameter(request, "order"); 134 if (sort.length() == 0) sort = "CompanyCreationDate"; 135 if (order.length()== 0) order = "DESC"; 136 137 int postsPerPage = onlineUser.getPostsPerPage(); 139 int offset = 0; 140 try { 141 offset = GenericParamUtil.getParameterInt(request, "offset"); 142 } catch (BadInputException e) { 143 } 145 146 int totalCompanies = DAOFactory.getCompanyDAO().getNumberOfCompanies(); 147 if (offset > totalCompanies) { 148 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 149 throw new BadInputException(localizedMessage); 150 } 152 153 Collection companyBeans = DAOFactory.getCompanyDAO().getCompanies_withSortSupport_limit(offset, postsPerPage, sort, order); 154 155 request.setAttribute("CompanyBeans", companyBeans); 156 request.setAttribute("TotalCompanies", new Integer (totalCompanies)); 157 request.setAttribute("offset", new Integer (offset)); 158 } 159 } 160 | Popular Tags |