|
What this is
Other links
The source code/* * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/CategoryWebHandler.java,v 1.13.2.1 2005/06/17 17:34:56 minhnn Exp $ * $Author: minhnn $ * $Revision: 1.13.2.1 $ * $Date: 2005/06/17 17:34:56 $ * * ==================================================================== * * 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: Minh Nguyen minhnn@MyVietnam.net * @author: Mai Nguyen mai.nh@MyVietnam.net */ package com.mvnforum.admin; import java.sql.Timestamp; import java.util.Collection; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.mvnforum.MVNForumResourceBundle; import com.mvnforum.MyUtil; import com.mvnforum.auth.*; import com.mvnforum.db.CategoryBean; import com.mvnforum.db.DAOFactory; import net.myvietnam.mvncore.exception.*; import net.myvietnam.mvncore.filter.DisableHtmlTagFilter; import net.myvietnam.mvncore.util.*; class CategoryWebHandler { private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance(); CategoryWebHandler() { } /* * @todo: check permission */ void processAdd(HttpServletRequest request, HttpServletResponse response) throws BadInputException, CreateException, DatabaseException, DuplicateKeyException, ForeignKeyNotFoundException, AuthenticationException, AssertionException { OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); MVNForumPermission permission = onlineUser.getPermission(); permission.ensureCanAddCategory(); MyUtil.saveVNTyperMode(request, response); Timestamp now = DateUtil.getCurrentGMTTimestamp(); int parentCategoryID = 0; String categoryName = ParamUtil.getParameterSafe(request, "CategoryName", true); categoryName = DisableHtmlTagFilter.filter(categoryName); String categoryDesc = ParamUtil.getParameterSafe(request, "CategoryDesc", false); categoryDesc = DisableHtmlTagFilter.filter(categoryDesc); int categoryOption = 0;//@todo review and support it later int categoryStatus = 0;//@todo review and support it later DAOFactory.getCategoryDAO().create(parentCategoryID, categoryName, categoryDesc, now/*categoryCreationDate*/, now/*categoryModifiedDate*/, 0/*categoryOrder*/, categoryOption, categoryStatus); request.setAttribute("CategoryName", categoryName); } void prepareDelete(HttpServletRequest request) throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException { OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); MVNForumPermission permission = onlineUser.getPermission(); permission.ensureCanDeleteCategory(); // primary key column(s) int categoryID = ParamUtil.getParameterInt(request, "category"); Locale locale = I18nUtil.getLocaleInRequest(request); Collection forumsInCategory = DAOFactory.getForumDAO().getForums_inCategory(categoryID); if (forumsInCategory.isEmpty() == false) { String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_not_empty_category"); throw new BadInputException(localizedMessage); //throw new BadInputException("Cannot delete a not-empty category. Please delete all forums in this category first."); } CategoryBean categoryBean = DAOFactory.getCategoryDAO().getCategory(categoryID); request.setAttribute("CategoryBean", categoryBean); } void processDelete(HttpServletRequest request) throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException { OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); MVNForumPermission permission = onlineUser.getPermission(); // user must have been authenticated before he can delete permission.ensureIsAuthenticated(); permission.ensureCanDeleteCategory(); Locale locale = I18nUtil.getLocaleInRequest(request); // primary key column(s) int categoryID = ParamUtil.getParameterInt(request, "category"); Collection forumsInCategory = DAOFactory.getForumDAO().getForums_inCategory(categoryID); if (forumsInCategory.isEmpty() == false) { String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_not_empty_category"); throw new BadInputException(localizedMessage); //throw new BadInputException("Cannot delete a not-empty category. Please delete all forums in this category first."); } // now check the password MyUtil.ensureCorrectCurrentPassword(request); /* try { GroupCategoryWebHelper.deleteGroupCategory_inCategory(categoryID); } catch (ObjectNotFoundException ex) {} */ DAOFactory.getWatchDAO().delete_inCategory(categoryID); DAOFactory.getCategoryDAO().delete(categoryID); } /* * @todo: check permission */ void prepareEdit(HttpServletRequest request) throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException { OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); MVNForumPermission permission = onlineUser.getPermission(); permission.ensureCanEditCategory(); // primary key column(s) int categoryID = ParamUtil.getParameterInt(request, "category"); CategoryBean categoryBean = DAOFactory.getCategoryDAO().getCategory(categoryID); request.setAttribute("CategoryBean", categoryBean); } /* * @todo: check permission */ void processUpdate(HttpServletRequest request, HttpServletResponse response) throws BadInputException, DatabaseException, DuplicateKeyException, ObjectNotFoundException, AuthenticationException, AssertionException { OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); MVNForumPermission permission = onlineUser.getPermission(); permission.ensureCanEditCategory(); MyUtil.saveVNTyperMode(request, response); Locale locale = I18nUtil.getLocaleInRequest(request); Timestamp now = DateUtil.getCurrentGMTTimestamp(); // primary key column(s) int categoryID = ParamUtil.getParameterInt(request, "CategoryID"); // column(s) to update String categoryName = ParamUtil.getParameterSafe(request, "CategoryName", true); categoryName = DisableHtmlTagFilter.filter(categoryName); String categoryDesc = ParamUtil.getParameterSafe(request, "CategoryDesc", false); categoryDesc = DisableHtmlTagFilter.filter(categoryDesc); int categoryOrder = ParamUtil.getParameterUnsignedInt(request, "CategoryOrder"); int categoryOption = 0;// @todo review and support it later int categoryStatus = 0;// @todo review and support it later DAOFactory.getCategoryDAO().update(categoryID, // primary key categoryName, categoryDesc, now/*categoryModifiedDate*/, categoryOrder, categoryOption, categoryStatus); } /* * @todo: check permission */ void processUpdateCategoryOrder(HttpServletRequest request) throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException, AssertionException { OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); MVNForumPermission permission = onlineUser.getPermission(); permission.ensureCanEditCategory(); Locale locale = I18nUtil.getLocaleInRequest(request); Timestamp now = DateUtil.getCurrentGMTTimestamp(); // primary key column(s) int categoryID = ParamUtil.getParameterInt(request, "category"); String action = ParamUtil.getParameterSafe(request, "action", true); if (action.equals("up")) { DAOFactory.getCategoryDAO().decreaseCategoryOrder(categoryID, now); } else if (action.equals("down")) { DAOFactory.getCategoryDAO().increaseCategoryOrder(categoryID, now); } else { String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_update_category.unknown_action", new Object[] {action}); throw new BadInputException(localizedMessage); //throw new BadInputException("Cannot update CategoryOrder: unknown action: " + action); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.