List of usage examples for org.apache.commons.fileupload FileItem setFieldName
void setFieldName(String name);
From source file:com.enonic.cms.web.portal.services.ContentServicesProcessor_operation_CreateTest.java
@Test public void handlerCreate_uploadfile_input_using_basekey_for_backwards_compatability() throws RemoteException { // This test sends the binary in the "unrequired"-field instead of the now recommended "unrequired_new" // setup content type ContentTypeConfigBuilder ctyconf = new ContentTypeConfigBuilder("MyContentType3", "title"); ctyconf.startBlock("General"); ctyconf.addInput("title", "text", "contentdata/title", "Title", true); ctyconf.addInput("unrequired", "uploadfile", "contentdata/unrequired", "Unrequired", true); ctyconf.endBlock();/*from w w w . j a v a2 s .com*/ createAndSaveContentTypeAndCategory("MyContentType3", "MyCategory3", ctyconf); fixture.save(factory.createCategoryAccessForUser("MyCategory3", "testuser", "read, create")); fixture.flushAndClearHibernateSession(); Mockito.when(userServicesRedirectUrlResolver.resolveRedirectUrlToPage(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.any(MultiValueMap.class))).thenReturn("http://anyurl"); // execise: create the content String categoryName = "MyCategory3"; ExtendedMap formItems = new ExtendedMap(true); formItems.putString("categorykey", fixture.findCategoryByName(categoryName).getKey().toString()); formItems.putString("title", "Title"); FileItem testFile = new MockFileItem("thisIsATestFile".getBytes()); testFile.setFieldName("testFile"); formItems.put("unrequired", testFile); customContentHandlerController.handlerCreate(request, response, session, formItems, null, siteKey_1); fixture.flushAndClearHibernateSession(); verifyRedirectOk(); CustomContentData contentData = getCustomContentDataResult(categoryName); assertEquals("Title", ((TextDataEntry) contentData.getEntry("title")).getValue()); assertTrue("Unrequired", contentData.getEntry("unrequired") != null); assertNotNull(((BinaryDataEntry) contentData.getEntry("unrequired")).getExistingBinaryKey()); }
From source file:com.enonic.vertical.userservices.CustomContentHandlerController_operation_CreateTest.java
@Test public void handlerCreate_uploadfile_input_using_basekey_for_backwards_compatability() throws RemoteException { // This test sends the binary in the "unrequired"-field instead of the now recommended "unrequired_new" // setup content type ContentTypeConfigBuilder ctyconf = new ContentTypeConfigBuilder("MyContentType3", "title"); ctyconf.startBlock("General"); ctyconf.addInput("title", "text", "contentdata/title", "Title", true); ctyconf.addInput("unrequired", "uploadfile", "contentdata/unrequired", "Unrequired", true); ctyconf.endBlock();/*from w ww .j a v a 2 s . co m*/ createAndSaveContentTypeAndCategory("MyContentType3", "MyCategory3", ctyconf); fixture.save(factory.createCategoryAccessForUser("MyCategory3", "testuser", "read, create")); fixture.flushAndClearHibernateSesssion(); Mockito.when(userServicesRedirectUrlResolver.resolveRedirectUrlToPage(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.any(MultiValueMap.class))).thenReturn("http://anyurl"); // execise: create the content String categoryName = "MyCategory3"; ExtendedMap formItems = new ExtendedMap(true); formItems.putString("categorykey", fixture.findCategoryByName(categoryName).getKey().toString()); formItems.putString("title", "Title"); FileItem testFile = new MockFileItem("thisIsATestFile".getBytes()); testFile.setFieldName("testFile"); formItems.put("unrequired", testFile); customContentHandlerController.handlerCreate(request, response, session, formItems, null, siteKey_1); fixture.flushAndClearHibernateSesssion(); verifyRedirectOk(); CustomContentData contentData = getCustomContentDataResult(categoryName); assertEquals("Title", ((TextDataEntry) contentData.getEntry("title")).getValue()); assertTrue("Unrequired", contentData.getEntry("unrequired") != null); assertNotNull(((BinaryDataEntry) contentData.getEntry("unrequired")).getExistingBinaryKey()); }
From source file:com.uniquesoft.uidl.servlet.UploadServlet.java
/** * This method parses the submit action, puts in session a listener where the * progress status is updated, and eventually stores the received data in * the user session.// w w w. jav a 2 s. c o m * * returns null in the case of success or a string with the error * */ @SuppressWarnings("unchecked") protected String parsePostRequest(HttpServletRequest request, HttpServletResponse response) { try { String delay = request.getParameter(PARAM_DELAY); uploadDelay = Integer.parseInt(delay); } catch (Exception e) { } HttpSession session = request.getSession(); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received."); AbstractUploadListener listener = getCurrentListener(request); if (listener != null) { if (listener.isFrozen() || listener.isCanceled() || listener.getPercent() >= 100) { removeCurrentListener(request); } else { String error = getMessage("busy"); logger.error("UPLOAD-SERVLET (" + session.getId() + ") " + error); return error; } } // Create a file upload progress listener, and put it in the user session, // so the browser can use ajax to query status of the upload process listener = createNewListener(request); List<FileItem> uploadedItems; try { // Call to a method which the user can override checkRequest(request); // Create the factory used for uploading files, FileItemFactory factory = getFileItemFactory(getContentLength(request)); ServletFileUpload uploader = new ServletFileUpload(factory); uploader.setSizeMax(maxSize); uploader.setProgressListener(listener); // Receive the files logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsing HTTP POST request "); uploadedItems = uploader.parseRequest(request); session.removeAttribute(getSessionLastFilesKey(request)); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsed request, " + uploadedItems.size() + " items received."); // Received files are put in session List<FileItem> sessionFiles = getMySessionFileItems(request); if (sessionFiles == null) { sessionFiles = new ArrayList<FileItem>(); } String error = ""; if (uploadedItems.size() > 0) { // We append to the field name the sequence of the uploaded file int cnt = 0; for (FileItem i : uploadedItems) { if (!i.isFormField()) { i.setFieldName(i.getFieldName().replace(UConsts.MULTI_SUFFIX, "") + "-" + cnt++); } } sessionFiles.addAll(uploadedItems); String msg = ""; for (FileItem i : sessionFiles) { msg += i.getFieldName() + " => " + i.getName() + "(" + i.getSize() + " bytes),"; } logger.debug("UPLOAD-SERVLET (" + session.getId() + ") puting items in session: " + msg); session.setAttribute(getSessionFilesKey(request), sessionFiles); session.setAttribute(getSessionLastFilesKey(request), uploadedItems); } else { logger.error("UPLOAD-SERVLET (" + session.getId() + ") error NO DATA received "); error += getMessage("no_data"); } return error.length() > 0 ? error : null; // So much silly questions in the list about this issue. } catch (LinkageError e) { logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Exception: " + e.getMessage() + "\n" + stackTraceToString(e)); RuntimeException ex = new UploadActionException(getMessage("restricted", e.getMessage()), e); listener.setException(ex); throw ex; } catch (SizeLimitExceededException e) { RuntimeException ex = new UploadSizeLimitException(e.getPermittedSize(), e.getActualSize()); listener.setException(ex); throw ex; } catch (UploadSizeLimitException e) { listener.setException(e); throw e; } catch (UploadCanceledException e) { listener.setException(e); throw e; } catch (UploadTimeoutException e) { listener.setException(e); throw e; } catch (Throwable e) { logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Unexpected Exception -> " + e.getMessage() + "\n" + stackTraceToString(e)); e.printStackTrace(); RuntimeException ex = new UploadException(e); listener.setException(ex); throw ex; } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Parses the parameters and calls the web service operation * * @throws java.lang.Exception when an Exception error occurs *//*w w w .ja v a 2 s .co m*/ protected void parseAddRecord() throws Exception { java.util.Enumeration e = pmRequest.getParameterNames(); Vector vAttachments = new Vector(); getStructure(); Record r = new Record(); Field fAux; String paramName; String fieldType; String fieldName; String fieldId; while (e.hasMoreElements()) { paramName = (String) e.nextElement(); fAux = new Field(); if (paramName.startsWith("fd_")) { fieldId = paramName.substring(3); fieldName = ((FieldDef) vFieldDefs.get(Integer.parseInt(fieldId))).getName(); fieldType = getFieldDef(fieldName).getType(); if (fieldType.equals("image") || fieldType.equals("sound")) { FileItem fi = pmRequest.getFileItem(paramName); String sNomFitxer; if (fi.getSize() != 0) //case there is no attachment { sNomFitxer = Utils.getFileName(fi.getName()); fi.setFieldName(fieldName); vAttachments.add(fi); } else { sNomFitxer = "null"; } fAux.setName(fieldName); fAux.setValue(sNomFitxer); } else { fAux.setName(fieldName); fAux.setValue(pmRequest.getParameter(paramName)); } r.addField(fAux); } else if (paramName.startsWith("fdYYYY_")) { fieldId = paramName.substring(7); fieldName = ((FieldDef) vFieldDefs.get(Integer.parseInt(fieldId))).getName(); String sDay = pmRequest.getParameter("fdDD_" + fieldId); String sMonth = pmRequest.getParameter("fdMM_" + fieldId); String sYear = pmRequest.getParameter("fdYYYY_" + fieldId); fAux.setName(fieldName); fAux.setValue(sYear + "-" + sMonth + "-" + sDay); r.addField(fAux); } } addRecord(r, vAttachments); }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Parses the parameters and calls the web service operation * * @throws java.lang.Exception when an Exception error occurs *///from w w w .j a v a 2 s .c om protected void parseModifyRecord() throws Exception { java.util.Enumeration e = pmRequest.getParameterNames(); Vector vAttachments = new Vector(); getStructure(); Record r = new Record(); r.setId(Integer.parseInt(pmRequest.getParameter("idRecord"))); Field fAux; String paramName; String fieldType; String fieldName; String fieldId; while (e.hasMoreElements()) { paramName = (String) e.nextElement(); fAux = new Field(); if (paramName.startsWith("fd_")) { fieldId = paramName.substring(3); fieldName = ((FieldDef) vFieldDefs.get(Integer.parseInt(fieldId))).getName(); fieldType = getFieldDef(fieldName).getType(); if (fieldType.equals("image") || fieldType.equals("sound")) { FileItem fi = pmRequest.getFileItem(paramName); String sNomFitxer; if (pmRequest.getParameter("del_" + fieldId).equals("true")) { sNomFitxer = "delete"; } else if (fi.getSize() != 0) //case there is no attachment { sNomFitxer = Utils.getFileName(fi.getName()); fi.setFieldName(fieldName); vAttachments.add(fi); } else { sNomFitxer = "null"; } fAux.setName(fieldName); fAux.setValue(sNomFitxer); } else { fAux.setName(fieldName); fAux.setValue(pmRequest.getParameter(paramName)); } r.addField(fAux); } else if (paramName.startsWith("fdYYYY_")) { fieldId = paramName.substring(7); fieldName = ((FieldDef) vFieldDefs.get(Integer.parseInt(fieldId))).getName(); String sDay = pmRequest.getParameter("fdDD_" + fieldId); String sMonth = pmRequest.getParameter("fdMM_" + fieldId); String sYear = pmRequest.getParameter("fdYYYY_" + fieldId); fAux.setName(fieldName); fAux.setValue(sYear + "-" + sMonth + "-" + sDay); r.addField(fAux); } } modifyRecord(r, vAttachments); }
From source file:web.CarryonupdateController.java
/** * 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/*from w ww. ja va2 s . c om*/ * @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); } outOfSession(request, response); if (RegexStrUtil.isNull(login) && RegexStrUtil.isNull(member)) { return handleUserpageError("Login & member are null."); } String category = request.getParameter(DbConstants.CATEGORY); boolean isCobrand = false; if (!RegexStrUtil.isNull(request.getParameter(DbConstants.IS_COBRAND))) { isCobrand = request.getParameter(DbConstants.IS_COBRAND).equals((Object) "1"); } if ((!RegexStrUtil.isNull(category) && category.equals(DbConstants.FILE_CATEGORY)) || isCobrand) { if (!GlobalConst.hddomain.contains(DbConstants.INDIA_CENTURY)) { if (!WebUtil.isLicenseProfessional(login)) { return handleError( "Cannot access user carryon features or cobrand user in deluxe version." + login); } } } if (RegexStrUtil.isNull(category)) { return handleError("category is null in CarryonupdateController. " + login); } // *************************************************************************** // This is the only line of code you need to get all session info initialized! // Always be the first line before anything else is done. Add to each controller's // handlRequest method. Also remember to extend SessionObject. // *************************************************************************** /** * map blob dao */ if (getDaoMapper() == null) { return handleError("DaoMapper is null in carryon update."); } CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("CarryonDao is null for carryon update."); } byte[] blob = null; String mtype = null; if (!RegexStrUtil.isNull(category)) { int catVal = new Integer(category).intValue(); if (catVal < GlobalConst.categoryMinSize || catVal > GlobalConst.categoryMaxSize) { return handleError("category values are not correct" + catVal); } } List fileList = null; DiskFileUpload upload = null; try { boolean isMultipart = FileUpload.isMultipartContent(request); // Create a new file upload handler upload = new DiskFileUpload(); /** originally set to 10MB **/ if (!DiaryAdmin.isDiaryAdmin(login)) { upload.setSizeMax((long) 10000000); } else { upload.setSizeMax(GlobalConst.maxUploadSize); } // Parse the request fileList = upload.parseRequest(request); } catch (Exception e) { return handleError("Exception occurred in uploading the photo file.", e); } long fieldsize = 0; String fieldname, fieldvalue; fieldname = fieldvalue = null; // educate the fieldnames to this form by using the setFieldName() String label = "btitle"; String caption = ""; String tagsLabel = DbConstants.USER_TAGS; String fileName = null; String usertags = null; String btitle = null; for (int i = 0; i < fileList.size(); i++) { FileItem fileItem = (FileItem) fileList.get(i); if (fileItem.isFormField()) { fileItem.setFieldName(label); fieldname = fileItem.getFieldName(); if (fieldname.equalsIgnoreCase(DbConstants.USER_TAGS)) { usertags = fileItem.getString(); //logger.info("usertags = " + usertags); label = ""; } else { if (fieldname.equalsIgnoreCase("btitle")) { btitle = fileItem.getString(); label = DbConstants.CAPTION; //logger.info("btitle = " + btitle); //fileItem.setFieldName(tagsLabel); } else { if (fieldname.equalsIgnoreCase("caption")) { caption = fileItem.getString(); label = DbConstants.USER_TAGS; } else { fieldvalue = fileItem.getString(); } } } /* set the filename */ } else { blob = fileItem.get(); mtype = fileItem.getContentType(); long maxSize = upload.getSizeMax(); /* filename */ fileName = fileItem.getName(); fieldsize = fileItem.getSize(); } } if (RegexStrUtil.isNull(btitle)) { btitle = fileName; } if ((fieldsize <= 0) || (RegexStrUtil.isNull(mtype)) || (RegexStrUtil.isNull(btitle)) || (blob == null)) { return handleError("fieldsize/mtype/btitle/blob one of them is empty, cannot upload files."); } CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleError("cobrandDao is null for CarryonupdateController"); } DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE); if (displayDao == null) { return handleError("displayDao is null for CarryonupdateController"); } try { if (isCobrand) { String ftype = request.getParameter(DbConstants.TYPE); if (RegexStrUtil.isNull(ftype)) { return handleError("ftype is null, CarryonUpdateController() "); } if (ftype.equals(DbConstants.COBRAND_HEADER) || ftype.equals(DbConstants.COBRAND_FOOTER)) { cobrandDao.addUserCobrand(blob, ftype, loginInfo.getValue(DbConstants.LOGIN_ID), login); } else { return handleError("cobrand type is not a header or footer in CarryonUpdateController "); } } else { if (btitle.length() > GlobalConst.blobTitleSize) { btitle = btitle.substring(0, GlobalConst.blobTitleSize); } int zoom = 100; if (!RegexStrUtil.isNull(usertags)) { if (usertags.length() > GlobalConst.usertagsSize) { usertags = usertags.substring(0, GlobalConst.usertagsSize); } usertags = RegexStrUtil.goodText(usertags); } if (!RegexStrUtil.isNull(caption)) { if (caption.length() > GlobalConst.refererSize) { caption = caption.substring(0, GlobalConst.refererSize); } caption = RegexStrUtil.goodText(caption); } boolean publishPhoto = displayDao.getDisplayPhotos(login, DbConstants.READ_FROM_SLAVE); carryonDao.addCarryon(fieldsize, category, mtype, RegexStrUtil.goodText(btitle), blob, zoom, loginInfo.getValue(DbConstants.LOGIN_ID), login, usertags, caption, publishPhoto); } } catch (BaseDaoException e) { return handleError("Exception occurred in addCarryon/addCobrandUserStreamBlo()", e); } /** * list the files */ String loginId = loginInfo.getValue(DbConstants.LOGIN_ID); List carryon = null; List tagList = null; HashSet tagSet = null; try { carryon = carryonDao.getCarryonByCategory(loginId, category, DbConstants.READ_FROM_MASTER); tagList = carryonDao.getTags(loginId, DbConstants.READ_FROM_MASTER); tagSet = carryonDao.getUniqueTags(tagList); } catch (BaseDaoException e) { return handleError( "Exception occurred in getCarryonByCategory()/getTags carryon update for login " + login, e); } /** * this is resolved to the name of the jsp using ViewResolver * if not blob type is images, display files */ if (carryon == null) { return handleError("carryon is null."); } /** * display information about the files, if the category of the blobs is files category(1) */ String viewName = DbConstants.EDIT_PHOTOS; if (category.equals(DbConstants.FILE_CATEGORY)) { viewName = DbConstants.EDIT_FILES; } Displaypage displaypage = null; Userpage cobrand = null; try { displaypage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_SLAVE); cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID)); } catch (BaseDaoException e) { return handleError("Exception occurred in getDisplaypage() for login " + login, e); } Map myModel = new HashMap(); myModel.put(viewName, carryon); myModel.put(DbConstants.COBRAND, cobrand); if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } myModel.put(DbConstants.LOGIN_INFO, loginInfo); 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.BUSINESS_EXISTS, isBizExists(login)); return new ModelAndView(viewName, "model", myModel); }
From source file:web.DirectoryaddblobController.java
/** * 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/* w w w. j a v a2 s.c o m*/ * @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.getMessage(), e); } if (!WebUtil.isLicenseProfessional(login)) { return handleError("Cannot manage directory feature in deluxe version."); } // *************************************************************************** // This is the only line of code you need to get all session info initialized! // Always be the first line before anything else is done. Add to each controller's // handlRequest method. Also remember to extend SessionObject. // *************************************************************************** outOfSession(request, response); if (RegexStrUtil.isNull(login) || (loginInfo == null)) { return handleUserpageError("Login/loginInfo is null."); } String directoryid = request.getParameter(DbConstants.DIRECTORY_ID); DirectoryDao directoryDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY); if (directoryDao == null) { return handleError("DirectoryDao null, DirectoryaddblobController, login " + login + " directoryid = " + directoryid); } /** * if the user quota is enabled, check if the user quota is set * If the user quota is not yet set, dont allow the user * to upload the files. * If the user quota is set, check if the user has exceeded the limit for the * quota, if he has don't allow the user to upload the files */ String userUsedQuota = null; String userQuotaSize = null; List userStructureList = null; if (WebUtil.isUserQuotaEnabled()) { String quotaSize = directoryDao.getQuotaSize(loginInfo.getValue(DbConstants.LOGIN_ID)); if (RegexStrUtil.isNull(quotaSize) || quotaSize.equals("0")) { return handleError("user quota is net yet set, so cannot upload the files"); } else { List qNames = null; String[] qTypes = null; LdapApi ldapConnection = null; try { ldapConnection = new LdapApi(); if (ldapConnection == null) { return handleError("ldapConnection is null, UserpageController"); } } catch (Exception e) { return handleError("error ldapConnection, for login " + login + e.getMessage(), e); } try { String email = null; if (loginInfo != null) { email = loginInfo.getValue(DbConstants.EMAIL); logger.info("email = " + email); } qNames = ldapConnection.getUserStructure(LdapConstants.ldapAttrMail, email); qTypes = LdapUtil.getQTypes(); logger.info("qNames = " + qNames.toString()); logger.info("qTypes = " + qTypes[0] + " " + qTypes[1] + " " + qTypes[2] + " " + qTypes[3] + " " + qTypes[4]); } catch (Exception e) { return handleError("ldapException, getUserStructure() for login " + login + e.getMessage(), e); } /** * If directoryid is null or not specified, show the * top of the directory */ String quotaMsg = null; try { // based on dirname=login Directory directory = null; String directoryId = directoryDao.getDirectoryId(login); if (!RegexStrUtil.isNull(directoryId)) { directory = directoryDao.viewDirectory(directoryId, loginInfo.getValue(DbConstants.LOGIN_ID), login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_SLAVE, DbConstants.WEBSITE_READ_FROM_SLAVE); } else { return handleError("directoryId is null, for dirname=" + login); } String loginId = loginInfo.getValue(DbConstants.LOGIN_ID); userQuotaSize = directoryDao.getQuotaSize(loginId); logger.info("userQuotaSize = " + userQuotaSize); userStructureList = directoryDao.getUserQuotas(loginId, qTypes, qNames, DbConstants.READ_FROM_SLAVE); logger.info("userStructureList = " + userStructureList.toString()); try { //SanUtils sanUtils = new SanUtils(); //userUsedQuota = sanUtils.getUsedQuota(login, SanConstants.sanPath, directory.getValue(DbConstants.DIRPATH)); String totalSize = directoryDao.getDirUsedQuota(loginInfo.getValue(DbConstants.LOGIN_ID)); logger.info("totalSize = " + totalSize); userUsedQuota = LdapUtil.getSizeWithType(totalSize); logger.info("userUsedQuota = " + userUsedQuota); } catch (SanException e) { return handleError("getUsedQuota(),login=" + login + e.getMessage(), e); } try { boolean exceeds = LdapUtil.checkMaxLimit(userQuotaSize, userStructureList, userUsedQuota); logger.info("users's used quota exceeds the quota limit " + exceeds); if (exceeds) { return handleError(login + " exceeds quota, usedQuota=" + userUsedQuota); } } catch (Exception e) { return handleError( "Exception LdapUtil.checkUserQuotaLimit() member " + login + " " + e.getMessage(), e); } } catch (Exception e) { return handleError( "Exception login in either viewDirectory()/getUserQuotas() " + login + e.getMessage(), e); } } } // remember any request parameters have to be added thru the field list. // cannot use request.getParameter in this program. boolean isDirectory = false; if ((request.getParameter(DbConstants.IS_DIRECTORY) != null) && request.getParameter(DbConstants.IS_DIRECTORY).equals((Object) "1")) { isDirectory = true; } String collabrumid = request.getParameter(DbConstants.COLLABRUM_ID); if (isDirectory) { if (RegexStrUtil.isNull(directoryid)) { return handleError("directoryid is null in DirectoryaddblobController"); } directoryid = RegexStrUtil.goodNameStr(directoryid); } else { if (RegexStrUtil.isNull(collabrumid)) { return handleError("collabrumid is null in DirectoryaddblobController"); } collabrumid = RegexStrUtil.goodNameStr(collabrumid); } Integer blobtype = new Integer(request.getParameter(DbConstants.BLOBTYPE)); if (blobtype < GlobalConst.categoryMinSize || blobtype > GlobalConst.categoryMaxSize) { return handleUserpageError( "category or blobtype is not appropriate type in DirectoryaddblobController"); } byte[] blob = null; String mtype = null; String btitle = null; int zoom = 100; List fileList = null; DiskFileUpload upload = null; try { boolean isMultipart = FileUpload.isMultipartContent(request); // Create a new file upload handler upload = new DiskFileUpload(); //upload.setSizeMax((long)10000000); //upload.setSizeMax(webConstants.getFileuploadsize()); upload.setSizeMax(GlobalConst.fileUploadSize); // Parse the request fileList = upload.parseRequest(request); } catch (Exception e) { return handleError("Exception occurred in uploading the photo file." + e.getMessage(), e); } long fieldsize = 0; String fieldname, fieldvalue; fieldname = fieldvalue = null; // educate the fieldnames to this form by using the setFieldName() String label = "btitle"; String fileName = ""; String tagsLabel = DbConstants.USER_TAGS; String usertags = ""; String caption = ""; for (int i = 0; i < fileList.size(); i++) { FileItem fileItem = (FileItem) fileList.get(i); if (fileItem.isFormField()) { fileItem.setFieldName(label); fieldname = fileItem.getFieldName(); if (fieldname.equalsIgnoreCase(DbConstants.USER_TAGS)) { usertags = fileItem.getString(); label = ""; } else { if (fieldname.equalsIgnoreCase("btitle")) { btitle = fileItem.getString(); label = DbConstants.CAPTION; } else { if (fieldname.equalsIgnoreCase("caption")) { caption = fileItem.getString(); label = DbConstants.USER_TAGS; } else { fieldvalue = fileItem.getString(); } } } } else { blob = fileItem.get(); mtype = fileItem.getContentType(); long maxSize = upload.getSizeMax(); fileName = fileItem.getName(); fieldsize = fileItem.getSize(); } } logger.info("mtype = " + mtype); //logger.info("fileMimeTypes = " + GlobalConst.fileMimeTypes); if (RegexStrUtil.isNull(btitle)) { btitle = fileName; } boolean addBlob = true; if ((fieldsize <= 0) || (RegexStrUtil.isNull(mtype)) || (RegexStrUtil.isNull(btitle)) || (blob == null)) { addBlob = false; } logger.info("mtype = " + mtype); if (addBlob) { if (WebUtil.isUserQuotaEnabled()) { try { String newUsedQuota = LdapUtil.addUserSize(userUsedQuota, fieldsize); boolean exceeds = LdapUtil.checkMaxLimit(userQuotaSize, userStructureList, newUsedQuota); if (exceeds) { return handleError(login + " file uploading exceeds quota, fileSize=" + fieldsize + " newusedQuota=" + newUsedQuota); } else { logger.info("file upload does not exceed the size fileSize=" + fieldsize + " newUsedQuota=" + newUsedQuota); } } catch (Exception e) { return handleError( "Exception LdapUtil.addUserSize()/checkMaxLimit() login " + login + e.getMessage(), e); } } } /** * Donot allow the user to upload the files of these types * check if certain types of mime types are excluded * in the xml configuration. */ /* String contentType = MimeUtil.mimeType(blob); logger.info("contentType = " + contentType); mtype = contentType; logger.info("mtype = " + mtype); */ if (GlobalConst.isFileMimeTypeEnabled) { if (WebUtil.isFileMimeTypeExcluded(mtype)) { return handleError( "contentType is not supported in this configuration, to update the support file types, look at the xml configuration in web app. contentType= " + mtype); } } logger.info("addBlob = " + addBlob); if (!RegexStrUtil.isNull(btitle)) { btitle = RegexStrUtil.goodDirName(btitle); } String loginid = loginInfo.getValue(DbConstants.LOGIN_ID); if (getDaoMapper() == null) { return handleError("DaoMapper is null in DirectoryaddblobController"); } /** * get the collabrum dao */ CollabrumDao collDao = null; if (!isDirectory) { collDao = (CollabrumDao) getDaoMapper().getDao(DbConstants.COLLABRUM); if (collDao == null) { return handleError("CollabrumDao is null for daoMapper, DirectoryaddblobController"); } } CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleError("cobrandDao is null for DirectoryaddblobController"); } String ftype = request.getParameter(DbConstants.TYPE); boolean isCobrand = false; if (!RegexStrUtil.isNull(request.getParameter(DbConstants.IS_COBRAND))) { isCobrand = request.getParameter(DbConstants.IS_COBRAND).equals((Object) "1"); } if (isCobrand) { if (RegexStrUtil.isNull(ftype)) { return handleError("ftype is null for DirectoryaddblobController"); } if (!ftype.equals(DbConstants.COBRAND_HEADER) && !ftype.equals(DbConstants.COBRAND_FOOTER)) { return handleError("cobrand filetype is neither a header nor footer DirectoryaddblobController"); } } if (isDirectory) { if (directoryid.length() > GlobalConst.directoryidSize) { return handleError( "directoryid.length() > WebConstants.directoryidSize,in DirectoryaddblobController"); } } /** * If the blob information is provided by the user, add the blob */ Directory newDir = null; String blobtypeStr = request.getParameter(DbConstants.BLOBTYPE); String isOrganizer = "0"; List tagList = null; List photos = null; Directory dir = null; if (isDirectory) { try { logger.info("calling viewDirectory"); dir = directoryDao.viewDirectory(directoryid, loginid, login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_MASTER, DbConstants.WEBSITE_READ_FROM_SLAVE); } catch (BaseDaoException e) { return handleError("Exception occured in viewDirectory() for directoryid = " + directoryid + " loginid = " + loginid + " ErrorMsg = " + e.getMessage(), e); } if (dir == null) { return handleError("directory is null, viewDirectory() for directoryid = " + directoryid + " loginid = " + loginid); } } /** * Blob has to be added either to directory or collabrum */ if (addBlob) { /** * addblob to directory and get the new directory */ logger.info("adding the blob"); if (isDirectory) { DirectoryStreamBlobDao platzBlobDao = (DirectoryStreamBlobDao) getDaoMapper() .getDao(DbConstants.DIR_BLOB); if (platzBlobDao == null) { return handleError("DirectoryStreamBlobDao is null for daoMapper"); } try { if (isCobrand) { cobrandDao.addCobrandDirStreamBlob(blob, directoryid, ftype, loginid, login); } else { logger.info("adding stream blob" + btitle); platzBlobDao.addStreamBlob(fieldsize, (int) blobtype, mtype, btitle, blob, zoom, loginid, directoryid, login, usertags, caption, dir.getValue(DbConstants.DIRPATH), dir.getValue(DbConstants.DIRNAME)); logger.info("getting the update onthe directory"); newDir = directoryDao.viewDirectory(directoryid, loginid, login, DbConstants.READ_FROM_MASTER, DbConstants.BLOB_READ_FROM_MASTER, DbConstants.WEBSITE_READ_FROM_SLAVE); if (blobtype == 1) { tagList = platzBlobDao.getAllTags(directoryid, DbConstants.READ_FROM_MASTER); } } } catch (BaseDaoException e) { return handleError("Exception occurred in addBlob() directoryStreamBlob " + e.getMessage(), e); } } else { /** * addblob to collabrum and get collabrum view */ if (!RegexStrUtil.isNull(collabrumid)) { try { if (collabrumid.length() > GlobalConst.collabrumidSize) { return handleError("collabrumid.length > WebConstants.collabrumidSize"); } if (isCobrand) { cobrandDao.addCollabrumCobrand(blob, collabrumid, ftype, loginid, login); } else { collDao.addStreamBlob(fieldsize, (int) blobtype, mtype, btitle, blob, zoom, loginid, collabrumid, login, usertags, caption); } } catch (BaseDaoException e) { return handleError("Exception occurred in addStreamBlob() for collabrum " + e.getMessage(), e); } } } } /** * When the blob could not be added, send the existing directory */ if (newDir == null) { newDir = dir; } Collabrum collabrum = null; if (!isDirectory) { try { collabrum = collDao.viewCollabrum(collabrumid, loginid, login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_MASTER); photos = collDao.getBlobsByCategory(collabrumid, blobtypeStr, DbConstants.BLOB_READ_FROM_MASTER); if (blobtype == 1) { tagList = collDao.getAllTags(collabrumid, DbConstants.READ_FROM_MASTER); } if (loginInfo != null) { String loginId = loginInfo.getValue(DbConstants.LOGIN_ID); if (collDao.isOrganizerCollabrum(collabrumid, login, loginId)) { isOrganizer = "1"; } } } catch (BaseDaoException e) { return handleError("Exception occurred in viewCollabrum() for collabrum " + e.getMessage(), e); } if (collabrum == null) { return handleError("collabrum is null, viewCollabrum() for collabrum "); } } Directory dirCobrand = null; Collabrum collCobrand = null; if (isDirectory) { try { dirCobrand = cobrandDao.getDirCobrand(directoryid); } catch (Exception e) { return handleError("exception getDirCobrand(), DirectorygetblobController " + e.getMessage(), e); } } else { try { collCobrand = cobrandDao.getCollCobrand(collabrumid); } catch (Exception e) { return handleError("exception getDirCobrand(), DirectorygetblobController " + e.getMessage(), e); } } /** * put the model and view */ StringBuffer sb = new StringBuffer(); if (tagList != null && tagList.size() > 0) { for (int i = 0; i < tagList.size(); i++) { Photo photo = (Photo) tagList.get(i); if (photo != null) { sb.append(photo.getValue(DbConstants.USER_TAGS)); sb.append(" "); } } } Map myModel = new HashMap(); if (isCobrand) { String viewName = DbConstants.VIEW_DIRECTORY; if (isDirectory) { myModel.put(DbConstants.DIRECTORY, newDir); myModel.put(DbConstants.COBRAND, dirCobrand); } else { viewName = DbConstants.VIEW_COLLABRUM; myModel.put(DbConstants.COLLABRUM, collabrum); myModel.put(DbConstants.COBRAND, collCobrand); } myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); return new ModelAndView(viewName, "model", myModel); } else { String viewName = null; String pageNum = "1"; if (isDirectory) { if (blobtypeStr.equals(DbConstants.FILE_CATEGORY)) { viewName = DbConstants.EDIT_DIR_BLOB_FILE; myModel.put(DbConstants.IS_DIRECTORY, "1"); } else { viewName = DbConstants.DIR_PHOTO_FOLDER; //viewName = DbConstants.EDIT_DIR_BLOB_FILE; myModel.put(DbConstants.IS_DIRECTORY, "1"); myModel.put(DbConstants.USER_TAGS, sb.toString()); } myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.DIRECTORY, newDir); myModel.put(DbConstants.DIRECTORY_ID, directoryid); myModel.put(DbConstants.PAGE_NUM, pageNum); myModel.put(DbConstants.COBRAND, dirCobrand); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); myModel.put(DbConstants.SORT_BY, DbConstants.DATEDESC); myModel.put(DbConstants.SELECTION, DbConstants.DATE_DESC_STR); return new ModelAndView(viewName, "model", myModel); } else { /** collabrum */ if (blobtypeStr.equals(DbConstants.FILE_CATEGORY)) { viewName = DbConstants.EDIT_BLOB_FILE; } else { viewName = DbConstants.COLL_PHOTO_FOLDER; myModel.put(DbConstants.USER_TAGS, sb.toString()); } if (sb != null) { myModel.put(DbConstants.USER_TAGS, sb.toString()); } myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(viewName, photos); myModel.put(DbConstants.COBRAND, collCobrand); myModel.put(DbConstants.STYLE, collabrum.getValue(DbConstants.STYLE)); myModel.put(DbConstants.COL_NAME, collabrum.getValue(DbConstants.NAME)); myModel.put(DbConstants.IS_ORGANIZER, isOrganizer); myModel.put(DbConstants.COLLABRUM_ID, collabrumid); myModel.put(DbConstants.PAGE_NUM, pageNum); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); return new ModelAndView(viewName, "model", myModel); } } }
From source file:web.ZipUploadController.java
/** * 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/*www .ja v a 2 s . co m*/ * @throws IOException * @return ModelAndView this instance is returned to spring */ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { ModelAndView modelAndView = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest", e); } outOfSession(request, response); if (RegexStrUtil.isNull(login) && RegexStrUtil.isNull(member)) { return handleUserpageError("Login & member are null."); } String category = request.getParameter(DbConstants.CATEGORY); boolean isCobrand = false; if (!RegexStrUtil.isNull(request.getParameter(DbConstants.IS_COBRAND))) { isCobrand = request.getParameter(DbConstants.IS_COBRAND).equals((Object) "1"); } if ((!RegexStrUtil.isNull(category) && category.equals(DbConstants.FILE_CATEGORY)) || isCobrand) { if (!WebUtil.isLicenseProfessional(login)) { return handleError( "Cannot access user carryon features or cobrand user in deluxe version." + login); } } if (RegexStrUtil.isNull(category)) { return handleError("category is null in CarryonupdateController. " + login); } if (daoMapper == null) { return handleError("DaoMapper is null in carryon update."); } CarryonDao carryonDao = (CarryonDao) daoMapper.getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("CarryonDao is null for carryon update."); } byte[] blob = null; String mtype = null; if (!RegexStrUtil.isNull(category)) { int catVal = new Integer(category).intValue(); if (catVal < GlobalConst.categoryMinSize || catVal > GlobalConst.categoryMaxSize) { return handleError("category values are not correct" + catVal); } } CobrandDao cobrandDao = (CobrandDao) daoMapper.getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleError("cobrandDao is null for CarryonupdateController"); } DisplaypageDao displayDao = (DisplaypageDao) daoMapper.getDao(DbConstants.DISPLAY_PAGE); if (displayDao == null) { return handleError("displayDao is null for CarryonupdateController"); } Displaypage displaypage = null; Userpage cobrand = null; try { displaypage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_SLAVE); cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID)); } catch (BaseDaoException e) { return handleError("Exception occurred in getDisplaypage() for login " + login, e); } System.setProperty("jmagick.systemclassloader", "no"); List fileList = null; ServletFileUpload upload = null; try { // Check that we have a file upload request boolean isMultipart = FileUpload.isMultipartContent(request); if (isMultipart) { // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Set factory constraints factory.setSizeThreshold(maxMemorySize.intValue()); //factory.setRepository(new File(tempDirectory)); // Create a new file upload handler upload = new ServletFileUpload(factory); // Set overall request size constraint upload.setSizeMax(maxRequestSize.longValue()); // Parse the request fileList = upload.parseRequest(request); long fieldsize = 0; String fieldname, fieldvalue; fieldname = fieldvalue = null; // educate the fieldnames to this form by using the setFieldName() String label = "btitle"; String caption = ""; String tagsLabel = DbConstants.USER_TAGS; String fileName = null; String usertags = null; String btitle = null; // Process the uploaded items Iterator iter = fileList.iterator(); while (iter.hasNext()) { FileItem fileItem = (FileItem) iter.next(); if (fileItem.isFormField()) { fileItem.setFieldName(label); fieldname = fileItem.getFieldName(); logger.info("fieldname = " + fieldname); if (fieldname.equalsIgnoreCase(DbConstants.USER_TAGS)) { usertags = fileItem.getString(); label = ""; } else { if (fieldname.equalsIgnoreCase("btitle")) { btitle = fileItem.getString(); label = DbConstants.CAPTION; } else { if (fieldname.equalsIgnoreCase("caption")) { caption = fileItem.getString(); label = DbConstants.USER_TAGS; } else { fieldvalue = fileItem.getString(); } } } } else { logger.info("contentType = " + fileItem.getContentType()); if (fileItem.getContentType().contains("zip")) { List entries = zipUtil.getEntries(fileItem.get()); logger.info("num entries = " + entries.size()); Iterator iter1 = entries.iterator(); while (iter1.hasNext()) { Media media = (Media) iter1.next(); blob = media.getData(); mtype = mimeMap.getMimeType(zipUtil.getSuffix(media.getName())); fileName = media.getName(); fieldsize = media.getData().length; if (RegexStrUtil.isNull(btitle)) { btitle = fileName; } if ((fieldsize <= 0) || (RegexStrUtil.isNull(mtype)) || (RegexStrUtil.isNull(btitle)) || (blob == null)) { return handleError( "fieldsize/mtype/btitle/blob one of them is empty, cannot upload files."); } if (!isCobrand) { if (btitle.length() > GlobalConst.blobTitleSize) { btitle = btitle.substring(0, GlobalConst.blobTitleSize); } int zoom = 100; if (!RegexStrUtil.isNull(usertags)) { if (usertags.length() > GlobalConst.usertagsSize) { usertags = usertags.substring(0, GlobalConst.usertagsSize); } usertags = RegexStrUtil.goodText(usertags); } if (!RegexStrUtil.isNull(caption)) { if (caption.length() > GlobalConst.refererSize) { caption = caption.substring(0, GlobalConst.refererSize); } caption = RegexStrUtil.goodText(caption); } boolean publishPhoto = displayDao.getDisplayPhotos(login, DbConstants.READ_FROM_SLAVE); carryonDao.addCarryon(fieldsize, category, mtype, RegexStrUtil.goodText(btitle), blob, zoom, loginInfo.getValue(DbConstants.LOGIN_ID), login, usertags, caption, publishPhoto); } } } else { if (!validImage.isValid(fileItem.getContentType())) { logger.warn("Found unexpected content type in upload, ignoring " + fileItem.getContentType()); continue; } logger.debug("Is not a form field"); blob = fileItem.get(); mtype = fileItem.getContentType(); fileName = fileItem.getName(); fieldsize = fileItem.getSize(); if (RegexStrUtil.isNull(btitle)) { btitle = fileName; } if ((fieldsize <= 0) || (RegexStrUtil.isNull(mtype)) || (RegexStrUtil.isNull(btitle)) || (blob == null)) { return handleError( "fieldsize/mtype/btitle/blob one of them is empty, cannot upload files."); } if (isCobrand) break; if (!isCobrand) { if (btitle.length() > GlobalConst.blobTitleSize) { btitle = btitle.substring(0, GlobalConst.blobTitleSize); } int zoom = 100; if (!RegexStrUtil.isNull(usertags)) { if (usertags.length() > GlobalConst.usertagsSize) { usertags = usertags.substring(0, GlobalConst.usertagsSize); } usertags = RegexStrUtil.goodText(usertags); } if (!RegexStrUtil.isNull(caption)) { if (caption.length() > GlobalConst.refererSize) { caption = caption.substring(0, GlobalConst.refererSize); } caption = RegexStrUtil.goodText(caption); } boolean publishPhoto = displayDao.getDisplayPhotos(login, DbConstants.READ_FROM_SLAVE); carryonDao.addCarryon(fieldsize, category, mtype, RegexStrUtil.goodText(btitle), blob, zoom, loginInfo.getValue(DbConstants.LOGIN_ID), login, usertags, caption, publishPhoto); } } } } } else { return handleError("Did not get a multipart request"); } } catch (Exception e) { return handleError("Exception occurred in addCarryon/addCobrandUserStreamBlo()", e); } if (isCobrand) { try { String ftype = request.getParameter(DbConstants.TYPE); if (RegexStrUtil.isNull(ftype)) { return handleError("ftype is null, CarryonUpdateController() "); } if (ftype.equals(DbConstants.COBRAND_HEADER) || ftype.equals(DbConstants.COBRAND_FOOTER)) { cobrandDao.addUserCobrand(blob, ftype, loginInfo.getValue(DbConstants.LOGIN_ID), login); } else { return handleError("cobrand type is not a header or footer in CarryonUpdateController "); } } catch (BaseDaoException e) { return handleError("Exception occurred in addCobrandUserStreamBlo()", e); } } /** * list the files */ String loginId = loginInfo.getValue(DbConstants.LOGIN_ID); List carryon = null; List tagList = null; HashSet tagSet = null; try { carryon = carryonDao.getCarryonByCategory(loginId, category, DbConstants.READ_FROM_MASTER); tagList = carryonDao.getTags(loginId, DbConstants.READ_FROM_MASTER); tagSet = carryonDao.getUniqueTags(tagList); } catch (BaseDaoException e) { return handleError( "Exception occurred in getCarryonByCategory()/getTags carryon update for login " + login, e); } /** * display information about the files, if the category of the blobs is files category(1) */ String viewName = DbConstants.EDIT_PHOTOS; if (category.equals(DbConstants.FILE_CATEGORY)) { viewName = DbConstants.EDIT_FILES; } Map myModel = new HashMap(); myModel.put(viewName, carryon); myModel.put(DbConstants.COBRAND, cobrand); if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } myModel.put(DbConstants.LOGIN_INFO, loginInfo); 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.BUSINESS_EXISTS, isBizExists(login)); return new ModelAndView(viewName, "model", myModel); }