List of usage examples for org.springframework.web.servlet.view RedirectView RedirectView
public RedirectView(String url)
From source file:ru.org.linux.user.UserEventController.java
@RequestMapping(value = "/show-replies.jsp", method = RequestMethod.GET) public ModelAndView showReplies(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "nick", required = false) String nick, @RequestParam(value = "offset", defaultValue = "0") int offset, @ModelAttribute("notifications") Action action) throws Exception { Template tmpl = Template.getTemplate(request); boolean feedRequested = request.getParameterMap().containsKey("output"); if (nick == null) { if (tmpl.isSessionAuthorized()) { return new ModelAndView(new RedirectView("/notifications")); }//from w w w . j a v a2 s . co m throw new AccessViolationException("not authorized"); } else { User.checkNick(nick); if (!tmpl.isSessionAuthorized() && !feedRequested) { throw new AccessViolationException("not authorized"); } if (tmpl.isSessionAuthorized() && nick.equals(tmpl.getCurrentUser().getNick()) && !feedRequested) { return new ModelAndView(new RedirectView("/notifications")); } if (!feedRequested && !tmpl.isModeratorSession()) { throw new AccessViolationException( "? ? ?"); } } Map<String, Object> params = new HashMap<>(); params.put("nick", nick); if (offset < 0) { offset = 0; } boolean firstPage = offset == 0; int topics = tmpl.getProf().getTopics(); if (feedRequested) { topics = 50; } if (topics > 200) { topics = 200; } params.put("firstPage", firstPage); params.put("topics", topics); params.put("offset", offset); /* define timestamps for caching */ long time = System.currentTimeMillis(); int delay = firstPage ? 90 : 60 * 60; response.setDateHeader("Expires", time + 1000 * delay); User user = userDao.getUser(nick); boolean showPrivate = tmpl.isModeratorSession(); User currentUser = tmpl.getCurrentUser(); params.put("currentUser", currentUser); if (currentUser != null && currentUser.getId() == user.getId()) { showPrivate = true; params.put("unreadCount", user.getUnreadEvents()); response.addHeader("Cache-Control", "no-cache"); } List<UserEvent> list = userEventService.getRepliesForUser(user, showPrivate, topics, offset, UserEventFilterEnum.ALL); List<PreparedUserEvent> prepared = userEventService.prepare(list, feedRequested, request.isSecure()); params.put("isMyNotifications", false); params.put("topicsList", prepared); params.put("hasMore", list.size() == topics); ModelAndView result = new ModelAndView("show-replies", params); if (feedRequested) { result.addObject("feed-type", "rss"); if ("atom".equals(request.getParameter("output"))) { result.addObject("feed-type", "atom"); } result.setView(feedView); } return result; }
From source file:com.bsg.pcms.provision.contract.ContractController.java
@RequestMapping(value = "createAction", method = RequestMethod.POST) public ModelAndView createAction(ContractDTOEx cde) throws SQLException { ModelAndView mav = new ModelAndView(new RedirectView("list.do")); mav.addObject("result", contractService.createContract(cde)); return mav;//from ww w . j ava2 s . c o m }
From source file:alpha.portal.webapp.controller.PasswordHintController.java
/** * Handle request.//w ww .j a v a 2s.c o m * * @param request * the request * @return the model and view * @throws Exception * the exception */ @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(final HttpServletRequest request) throws Exception { this.log.debug("entering 'handleRequest' method..."); final String username = request.getParameter("username"); final MessageSourceAccessor text = new MessageSourceAccessor(this.messageSource, request.getLocale()); // ensure that the username has been sent if (username == null) { this.log.warn("Username not specified, notifying user that it's a required field."); request.setAttribute("error", text.getMessage("errors.required", text.getMessage("user.username"))); return new ModelAndView("login"); } this.log.debug("Processing Password Hint..."); // look up the user's information try { final User user = this.userManager.getUserByUsername(username); final StringBuffer msg = new StringBuffer(); msg.append("Your password hint is: ").append(user.getPasswordHint()); msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(request)); this.message.setTo(user.getEmail()); final String subject = '[' + text.getMessage("webapp.name") + "] " + text.getMessage("user.passwordHint"); this.message.setSubject(subject); this.message.setText(msg.toString()); this.mailEngine.send(this.message); this.saveMessage(request, text.getMessage("login.passwordHint.sent", new Object[] { username, user.getEmail() })); } catch (final UsernameNotFoundException e) { this.log.warn(e.getMessage()); this.saveError(request, text.getMessage("login.passwordHint.error", new Object[] { username })); } catch (final MailException me) { this.log.warn(me.getMessage()); this.saveError(request, me.getCause().getLocalizedMessage()); } return new ModelAndView(new RedirectView(request.getContextPath())); }
From source file:it.cnr.isti.hpc.dexter.annotate.controller.SuccessController.java
@RequestMapping(value = "/accessDeniedAction") public ModelAndView accessDeniedAction(final HttpServletRequest request, HttpServletResponse response) throws Exception { RedirectView view = new RedirectView("index.html"); ModelAndView mv = new ModelAndView(view); return mv;/* w w w . j a v a 2s . c o m*/ }
From source file:ru.org.linux.topic.TopicController.java
private ModelAndView getMessageNew(Section section, WebRequest webRequest, HttpServletRequest request, HttpServletResponse response, int page, String filter, String groupName, int msgid) throws Exception { Topic topic = messageDao.getById(msgid); Template tmpl = Template.getTemplate(request); PreparedTopic preparedMessage = messagePrepareService.prepareTopic(topic, request.isSecure(), tmpl.getCurrentUser());// w ww . j a v a 2s.c o m Group group = preparedMessage.getGroup(); if (!group.getUrlName().equals(groupName) || group.getSectionId() != section.getId()) { return new ModelAndView(new RedirectView(topic.getLink())); } Map<String, Object> params = new HashMap<>(); boolean showDeleted = request.getParameter("deleted") != null; if (showDeleted) { page = -1; } boolean rss = request.getParameter("output") != null && "rss".equals(request.getParameter("output")); if (rss && topic.isExpired()) { throw new MessageNotFoundException(topic.getId(), "no more comments"); } if (!tmpl.isModeratorSession()) { if (showDeleted && !"POST".equals(request.getMethod())) { return new ModelAndView(new RedirectView(topic.getLink())); } } if (page == -1 && !tmpl.isSessionAuthorized()) { return new ModelAndView(new RedirectView(topic.getLink())); } int pages = topic.getPageCount(tmpl.getProf().getMessages()); if (page >= pages && (page > 0 || pages > 0)) { if (pages == 0) { return new ModelAndView(new RedirectView(topic.getLink())); } else { return new ModelAndView(new RedirectView(topic.getLinkPage(pages - 1))); } } if (showDeleted) { if (!tmpl.isSessionAuthorized()) { throw new BadInputException(" ??"); } } params.put("showDeleted", showDeleted); User currentUser = AuthUtil.getCurrentUser(); if (topic.isExpired() && showDeleted && !tmpl.isModeratorSession()) { throw new MessageNotFoundException(topic.getId(), "? ? ? "); } permissionService.checkView(topic, currentUser); if (group.getCommentsRestriction() == -1 && !tmpl.isSessionAuthorized()) { throw new AccessViolationException(" ? ? ?"); } params.put("message", topic); params.put("preparedMessage", preparedMessage); if (topic.isExpired()) { response.setDateHeader("Expires", System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L); } CommentList comments = commentService.getCommentList(topic, showDeleted); if (!rss) { params.put("page", page); params.put("group", group); params.put("showAdsense", !tmpl.isSessionAuthorized() || !tmpl.getProf().isHideAdsense()); if (!tmpl.isSessionAuthorized()) { // because users have IgnoreList and memories String etag = getEtag(topic, tmpl); response.setHeader("Etag", etag); if (request.getHeader("If-None-Match") != null) { if (etag.equals(request.getHeader("If-None-Match"))) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return null; } } else if (checkLastModified(webRequest, topic)) { return null; } } params.put("messageMenu", messagePrepareService.getTopicMenu(preparedMessage, currentUser, request.isSecure(), tmpl.getProf(), true)); Set<Integer> ignoreList; if (currentUser != null) { ignoreList = ignoreListDao.get(currentUser); } else { ignoreList = ImmutableSet.of(); } int defaultFilterMode = getDefaultFilter(tmpl.getProf(), ignoreList.isEmpty()); int filterMode; if (filter != null) { filterMode = CommentFilter.parseFilterChain(filter); if (!ignoreList.isEmpty() && filterMode == CommentFilter.FILTER_ANONYMOUS) { filterMode += CommentFilter.FILTER_IGNORED; } } else { filterMode = defaultFilterMode; } params.put("filterMode", CommentFilter.toString(filterMode)); params.put("defaultFilterMode", CommentFilter.toString(defaultFilterMode)); loadTopicScroller(params, topic, currentUser, !ignoreList.isEmpty()); Set<Integer> hideSet = commentService.makeHideSet(comments, filterMode, ignoreList); CommentFilter cv = new CommentFilter(comments); boolean reverse = tmpl.getProf().isShowNewFirst(); List<Comment> commentsFiltred = cv.getCommentsForPage(reverse, page, tmpl.getProf().getMessages(), hideSet); List<Comment> commentsFull = cv.getCommentsForPage(reverse, page, tmpl.getProf().getMessages(), ImmutableSet.<Integer>of()); params.put("unfilteredCount", commentsFull.size()); List<PreparedComment> commentsPrepared = prepareService.prepareCommentList(comments, commentsFiltred, request.isSecure(), tmpl, topic); params.put("commentsPrepared", commentsPrepared); IPBlockInfo ipBlockInfo = ipBlockDao.getBlockInfo(request.getRemoteAddr()); params.put("ipBlockInfo", ipBlockInfo); if (pages > 1 && !showDeleted) { params.put("pages", buildPages(topic, tmpl.getProf().getMessages(), filterMode, defaultFilterMode, page)); } } else { CommentFilter cv = new CommentFilter(comments); List<Comment> commentsFiltred = cv.getCommentsForPage(true, 0, RSS_DEFAULT, ImmutableSet.<Integer>of()); List<PreparedRSSComment> commentsPrepared = prepareService.prepareCommentListRSS(commentsFiltred, request.isSecure()); params.put("commentsPrepared", commentsPrepared); LorURL lorURL = new LorURL(configuration.getMainURI(), configuration.getMainUrl()); params.put("mainURL", lorURL.fixScheme(request.isSecure())); } return new ModelAndView(rss ? "view-message-rss" : "view-message", params); }
From source file:com.example.WebController.java
private RedirectView buildStatusView(String statusMessage) { RedirectView view = new RedirectView("/"); view.addStaticAttribute("statusMessage", statusMessage); return view;//from www .j a va 2 s. co m }
From source file:fr.hoteia.qalingo.web.mvc.controller.user.UserController.java
@RequestMapping(value = BoUrls.USER_DETAILS_URL, method = RequestMethod.GET) public ModelAndView userDetails(final HttpServletRequest request, final Model model) throws Exception { ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request), BoUrls.USER_DETAILS.getVelocityPage()); final String userId = request.getParameter(RequestConstants.REQUEST_PARAMETER_USER_ID); if (StringUtils.isNotEmpty(userId)) { final User user = userService.getUserById(userId); if (user != null) { initUserDetailsPage(request, model, modelAndView, user); } else {/* ww w . ja va2s.c o m*/ final String url = requestUtil.getLastRequestUrl(request); return new ModelAndView(new RedirectView(url)); } } else { User user = requestUtil.getCurrentUser(request); if (user != null) { // Refresh Data cause CurrentUser is from Session or Spring Security user = userService.getUserById(user.getId().toString()); initUserDetailsPage(request, model, modelAndView, user); } else { final String url = requestUtil.getLastRequestUrl(request); return new ModelAndView(new RedirectView(url)); } } formFactory.buildUserQuickSearchForm(request, modelAndView); return modelAndView; }
From source file:ru.org.linux.user.UserFilterController.java
@RequestMapping(value = "/user-filter/ignore-user", method = RequestMethod.POST, params = "del") public ModelAndView listDel(ServletRequest request, @RequestParam int id) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isSessionAuthorized()) { throw new AccessViolationException("Not authorized"); }/*from ww w . j av a2 s . co m*/ User user = tmpl.getCurrentUser(); user.checkAnonymous(); User delUser = userDao.getUserCached(id); ignoreListDao.remove(user, delUser); return new ModelAndView(new RedirectView("/user-filter")); }
From source file:com.ut.healthelink.controller.orgProfileController.java
/** * The '/{cleanURL}' POST request will handle submitting changes for the organization profile. * * @param organization The object containing the organization form fields * @param result The validation result * @param redirectAttr The variable that will hold values that can be read after the redirect * @param action The variable that holds which button was pressed * * @return Will return the organization list page on "Save & Close" Will return the organization details page on "Save" Will return the organization create page on error * * @Objects (1) The object containing all the information for the clicked org (2) The 'id' of the clicked org that will be used in the menu and action bar * @throws Exception/*w w w . jav a2 s . c o m*/ */ @RequestMapping(value = "/editProfile", method = RequestMethod.POST) public ModelAndView updateOrganization(@Valid Organization organization, BindingResult result, RedirectAttributes redirectAttr) throws Exception { //Get a list of states USStateList stateList = new USStateList(); if (result.hasErrors()) { ModelAndView mav = new ModelAndView(); mav.setViewName("/OrgProfile/editProfile"); //Get the object that will hold the states mav.addObject("stateList", stateList.getStates()); return mav; } Organization currentOrg = organizationManager.getOrganizationById(organization.getId()); organization.setparsingTemplate(currentOrg.getparsingTemplate()); if (!currentOrg.getcleanURL().trim().equals(organization.getcleanURL().trim())) { List<Organization> existing = organizationManager.getOrganizationByName(organization.getcleanURL()); if (!existing.isEmpty()) { ModelAndView mav = new ModelAndView(); mav.setViewName("/OrgProfile/editProfile"); mav.addObject("existingOrg", "Organization " + organization.getOrgName().trim() + " already exists."); //Get the object that will hold the states mav.addObject("stateList", stateList.getStates()); return mav; } } //Update the organization organizationManager.updateOrganization(organization); //This variable will be used to display the message on the details form redirectAttr.addFlashAttribute("savedStatus", "updated"); ModelAndView mav = new ModelAndView(new RedirectView("/OrgProfile/editProfile")); return mav; }
From source file:org.openmrs.web.controller.person.RelationshipTypeFormController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db//w ww . jav a 2 s . c o m * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { RelationshipType relationshipType = (RelationshipType) obj; PersonService ps = Context.getPersonService(); //to save the relationship type if (request.getParameter("save") != null) { ps.saveRelationshipType(relationshipType); view = getSuccessView(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "RelationshipType.saved"); } // if the user is retiring out the relationshipType else if (request.getParameter("retire") != null) { String retireReason = request.getParameter("retireReason"); if (relationshipType.getRelationshipTypeId() != null && !(StringUtils.hasText(retireReason))) { errors.reject("retireReason", "general.retiredReason.empty"); return showForm(request, response, errors); } ps.retireRelationshipType(relationshipType, retireReason); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "RelationshipType.retiredSuccessfully"); view = getSuccessView(); } // if the user is purging the relationshipType else if (request.getParameter("purge") != null) { try { ps.purgeRelationshipType(relationshipType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "RelationshipType.purgedSuccessfully"); view = getSuccessView(); } catch (DataIntegrityViolationException e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.object.inuse.cannot.purge"); return showForm(request, response, errors); } catch (APIException e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.general: " + e.getLocalizedMessage()); return showForm(request, response, errors); } } // if the user unretiring relationship type else if (request.getParameter("unretire") != null) { ps.unretireRelationshipType(relationshipType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "RelationshipType.unretiredSuccessfully"); view = getSuccessView(); } } return new ModelAndView(new RedirectView(view)); }