KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > user > CompanyWebHandler


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/CompanyWebHandler.java,v 1.15 2006/04/14 17:05:27 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.15 $
5  * $Date: 2006/04/14 17:05:27 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Tran Van Giang
39  * @author: Minh Nguyen
40  */

41 package com.mvnforum.user;
42
43 import java.util.Collection JavaDoc;
44 import java.util.Locale JavaDoc;
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 JavaDoc locale = I18nUtil.getLocaleInRequest(request);
76         String JavaDoc strCompanyID = GenericParamUtil.getParameter(request, "companyid", false);
77         String JavaDoc strCompanyEmail = GenericParamUtil.getParameter(request, "companyemail", false);
78         String JavaDoc 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 JavaDoc companyEmail = GenericParamUtil.getParameterEmail(request, "companyemail"); // check for better security
86
try {
87                 companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyEmail(companyEmail);
88             } catch (ObjectNotFoundException e) {
89                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_email", new Object JavaDoc[] {companyEmail});
90                 throw new ObjectNotFoundException(localizedMessage);
91             }
92         } else if (strCompanyCreationDate.length() > 0) {
93             java.util.Date JavaDoc companyCreationDate = GenericParamUtil.getParameterDateUtil(request, "companycreationdate");
94             try {
95                 companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyCreationDate(companyCreationDate);
96             } catch (ObjectNotFoundException e) {
97                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_creationdate", new Object JavaDoc[] {strCompanyCreationDate});
98                 throw new ObjectNotFoundException(localizedMessage);
99             }
100         } else {
101             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_get_info_to_view_company");
102             throw new BadInputException(localizedMessage);
103             //throw new BadInputException("Cannot get the information to view company.");
104
}
105
106         CompanyBean companyBean = null;
107         try {
108             companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
109         } catch (ObjectNotFoundException e) {
110             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(companyID)});
111             throw new ObjectNotFoundException(localizedMessage);
112         }
113         request.setAttribute("CompanyBean", companyBean);
114     }
115
116     /**
117      * This method supports sorting base on many criteria
118      */

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         //MVNForumPermission permission = onlineUser.getPermission();
128
//permission.ensureCanAdminSystem();
129
Locale JavaDoc locale = I18nUtil.getLocaleInRequest(request);
130
131         // for sort and order stuff
132
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
133         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
134         if (sort.length() == 0) sort = "CompanyCreationDate";
135         if (order.length()== 0) order = "DESC";
136
137         // we continue
138
int postsPerPage = onlineUser.getPostsPerPage();
139         int offset = 0;
140         try {
141             offset = GenericParamUtil.getParameterInt(request, "offset");
142         } catch (BadInputException e) {
143             // do nothing
144
}
145
146         int totalCompanies = DAOFactory.getCompanyDAO().getNumberOfCompanies();
147         if (offset > totalCompanies) {
148             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
149             throw new BadInputException(localizedMessage);
150             //throw new BadInputException("The offset is not allowed to be greater than total companies.");
151
}
152
153         Collection JavaDoc companyBeans = DAOFactory.getCompanyDAO().getCompanies_withSortSupport_limit(offset, postsPerPage, sort, order);
154
155         request.setAttribute("CompanyBeans", companyBeans);
156         request.setAttribute("TotalCompanies", new Integer JavaDoc(totalCompanies));
157         request.setAttribute("offset", new Integer JavaDoc(offset));
158     }
159 }
160
Popular Tags