Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC" [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare 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 3 of the License, or * (at your option) 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, see <http://www.gnu.org/licenses/>. */ package web; import dao.*; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import model.Displaypage; import model.Hdlogin; import model.Userpage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import util.DbConstants; import util.GlobalConst; import util.RegexStrUtil; import util.WebUtil; /** * * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ public class CarryoneditController extends BaseController implements Controller { /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); /** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest", e); } /** * Error checking, don't check for session management * as mini album can be viewed out of session */ if (RegexStrUtil.isNull(login) && RegexStrUtil.isNull(member)) { return handleError("Login & member are null, CarryoneditController"); } String category = request.getParameter(DbConstants.CATEGORY); int catVal = 0; if (!RegexStrUtil.isNull(category)) { if (category.equals(DbConstants.FILE_CATEGORY)) { if (!GlobalConst.hddomain.contains(DbConstants.INDIA_CENTURY)) { if (!WebUtil.isLicenseProfessional(login) && !WebUtil.isLicenseProfessional(member)) { return handleError("Cannot access user file features in deluxe version. member = " + member + " login = " + login); } } catVal = 4; } else { if (category.equals(DbConstants.PHOTO_CATEGORY)) { catVal = 1; } else { return handleError("invalid category, CarryoneditController"); } } } else { return handleError("Category is null for CarryoneditController"); } /** * gets the daomapper */ if (getDaoMapper() == null) { return handleError("DaoMapper is null in carryon edit."); } String pageNum = request.getParameter(DbConstants.PAGE_NUM); String published = request.getParameter(DbConstants.PUBLISHED); Userpage cobrand = null; /** * logged in user, accessing another members files or photos * myself = false * logged in user, accessing own files or photos, * myself = true */ boolean myself = false; if (!RegexStrUtil.isNull(login)) { if (!RegexStrUtil.isNull(member) && login.equals(member)) { myself = true; } else { if (RegexStrUtil.isNull(member)) { myself = true; } } } /** * display information about the files, if the category !=1 (files) */ Displaypage displayPage = null; DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE); if (displayDao == null) { return handleError("displayDao is null in carryon edit for login " + login); } boolean displayPhotos, displayFiles; displayPhotos = displayFiles = false; try { if (myself) { displayPage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_MASTER); } else { displayPage = displayDao.getDisplaypage(member, DbConstants.READ_FROM_SLAVE); } } catch (BaseDaoException e) { return handleError("Exception occurred in getDisplaypage(), CarryoneditController ", e); } if ((displayPage != null) && (displayPage.getValue(DbConstants.FILES).equals("1"))) { displayFiles = true; } if ((displayPage != null) && (displayPage.getValue(DbConstants.PHOTOS).equals("1"))) { displayPhotos = true; } // DbConstants.PHOTO_CATEGORY if (!myself && (catVal == 1) && !displayPhotos) { return handleError("member does not give access to display photos to others" + member); } // DbConstants.FILES if (!myself && (catVal == 4) && !displayFiles) { return handleError("member does not give access to display files to others" + member); } CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleUserpageError("CobrandDao is null, CarryoneditController"); } CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null in carryon edit."); } List carryon = null; List tagList = null; HashSet tagSet = null; Hdlogin memberInfo = null; try { //if (!RegexStrUtil.isNull(login) && (!RegexStrUtil.isNull(member)) && (login.equals(member)) ) { if (myself) { if (loginInfo != null) { cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID)); carryon = carryonDao.getCarryonByCategory(loginInfo.getValue(DbConstants.LOGIN_ID), category, DbConstants.READ_FROM_SLAVE); tagList = carryonDao.getTags(loginInfo.getValue(DbConstants.LOGIN_ID), DbConstants.READ_FROM_SLAVE); tagSet = carryonDao.getUniqueTags(tagList); } memberInfo = loginInfo; } else { if (!RegexStrUtil.isNull(member)) { MemberDao memberDao = (MemberDao) getDaoMapper().getDao(DbConstants.MEMBER); if (memberDao == null) { return handleError("memberDao is null in CarryoeditController, for member= " + member); } memberInfo = memberDao.getMemberInfo(member); if (memberInfo != null) { cobrand = cobrandDao.getUserCobrand(memberInfo.getValue(DbConstants.LOGIN_ID)); carryon = carryonDao.getCarryonByCategory(memberInfo.getValue(DbConstants.LOGIN_ID), category, DbConstants.READ_FROM_SLAVE); tagList = carryonDao.getTags(memberInfo.getValue(DbConstants.LOGIN_ID), DbConstants.READ_FROM_SLAVE); tagSet = carryonDao.getUniqueTags(tagList); } } else { return handleError("Member is null in CarryoneditController"); } } } catch (BaseDaoException e) { return handleError( "Exception occurred in getCarryonByCategory(), category = + " + category + " in carryon edit ", e); } if (carryon == null) { return handleError("carryon is null, CarryoneditController."); } /** * editphotos/ editfiles - views resolved to the name of the jsp using ViewResolver */ String viewName = null; if (catVal == 1) { viewName = DbConstants.EDIT_PHOTOS; } else { viewName = DbConstants.EDIT_FILES; } Map myModel = new HashMap(); if (memberInfo != null) { myModel.put(DbConstants.MEMBER_INFO, memberInfo); } myModel.put(DbConstants.LOGIN_INFO, loginInfo); if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } myModel.put(DbConstants.PAGE_NUM, pageNum); myModel.put(DbConstants.PUBLISHED, published); myModel.put(DbConstants.DISPLAY_PAGE, displayPage); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); myModel.put(viewName, carryon); return new ModelAndView(viewName, "model", myModel); } /** * BaseDaoModel set by the spring framework. It maps the DAO implementation * to the pagetype. * * @param daoMapper set the BaseDaoModel instance */ public void setDaoMapper(BaseDaoModel daoMapper) { this.daoMapper = daoMapper; } /** * BaseDaoModel set by the spring framework. It maps the DAO implementation * to the pagetype. * * @return BaseDaoModel get the BaseDaoModel instance */ public BaseDaoModel getDaoMapper() { return daoMapper; } }