List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:org.sventon.web.ctrl.template.ListDirectoryContentsControllerTest.java
@Test public void testSvnHandle() throws Exception { final RepositoryService mockService = EasyMock.createMock(RepositoryService.class); final MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter("rowNumber", "12"); final List<DirEntry> entries = TestUtils.getFileEntriesDirectoryList(); final BaseCommand command = new BaseCommand(); command.setName(new RepositoryName("test")); command.setRevision(Revision.create(12)); final ListDirectoryContentsController ctrl = new ListDirectoryContentsController(); ctrl.setRepositoryService(mockService); expect(mockService.list(null, command.getPath(), command.getRevisionNumber())) .andStubReturn(new DirList(entries, new Properties())); replay(mockService);/*from w w w. j a v a 2s . c o m*/ final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, request, null, null); final Map model = modelAndView.getModel(); verify(mockService); assertEquals(2, model.size()); assertEquals(entries.get(0), ((List<DirEntry>) model.get("dirEntries")).get(0)); assertNull(modelAndView.getViewName()); }
From source file:com.thoughtworks.go.server.web.TabInterceptor.java
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object controller, ModelAndView modelAndView) throws Exception { if (modelAndView == null) { return;/*from w w w . j a va 2 s . c o m*/ } String requestUri = request.getRequestURI(); TabConfiguration tabConfiguration = findCurrentTab(requestUri); if (tabConfiguration != null) { if (StringUtils.isEmpty(modelAndView.getViewName()) && modelAndView.getView() == null) { modelAndView.setViewName(tabConfiguration.getViewName()); } modelAndView.addObject("currentTab", tabConfiguration); modelAndView.addObject("tabs", tabs); modelAndView.addObject("cssFiles", tabConfiguration.getCssFiles()); } }
From source file:org.tangram.components.spring.SpringViewUtilities.java
public void render(Writer writer, Map<String, Object> model, String view) throws IOException { ServletRequest request = (ServletRequest) model.get(Constants.ATTRIBUTE_REQUEST); ServletResponse response = (ServletResponse) model.get(Constants.ATTRIBUTE_RESPONSE); ViewContext vc = viewContextFactory.createViewContext(model, view); ModelAndView mav = SpringViewUtilities.createModelAndView(vc); View effectiveView = mav.getView(); LOG.debug("render() effectiveView={}", effectiveView); try {/* w ww . j a va 2 s .c o m*/ if (effectiveView == null) { String viewName = mav.getViewName(); if (viewName == null) { viewName = Constants.DEFAULT_VIEW; } // if effectiveView = viewHandler.resolveView(viewName, mav.getModel(), Locale.getDefault(), request); } // if if (writer != null) { writer.flush(); } // if LOG.debug("render() model={}", mav.getModel()); LOG.debug("render({}) effectiveView={}", mav.getViewName(), effectiveView); effectiveView.render(mav.getModel(), (HttpServletRequest) request, (HttpServletResponse) response); } catch (Exception e) { LOG.error("render() #" + view, e); if (writer != null) { writer.write(e.getLocalizedMessage()); } // if } // try/catch }
From source file:com.erudika.scoold.utils.ScooldRequestInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (modelAndView == null || StringUtils.startsWith(modelAndView.getViewName(), "redirect:")) { return; // skip if redirect }/*from ww w.java2 s . c o m*/ /*============================* * COMMON MODEL FOR ALL PAGES * *============================*/ // Misc modelAndView.addObject("HOMEPAGE", HOMEPAGE); modelAndView.addObject("APPNAME", Config.APP_NAME); modelAndView.addObject("CDN_URL", CDN_URL); modelAndView.addObject("DESCRIPTION", Config.getConfigParam("meta_description", "")); modelAndView.addObject("KEYWORDS", Config.getConfigParam("meta_keywords", "")); modelAndView.addObject("IN_PRODUCTION", Config.IN_PRODUCTION); modelAndView.addObject("IN_DEVELOPMENT", !Config.IN_PRODUCTION); modelAndView.addObject("MAX_ITEMS_PER_PAGE", Config.MAX_ITEMS_PER_PAGE); modelAndView.addObject("SESSION_TIMEOUT_SEC", Config.SESSION_TIMEOUT_SEC); modelAndView.addObject("TOKEN_PREFIX", TOKEN_PREFIX); modelAndView.addObject("FB_APP_ID", Config.FB_APP_ID); modelAndView.addObject("GMAPS_API_KEY", Config.getConfigParam("gmaps_api_key", "")); modelAndView.addObject("GOOGLE_CLIENT_ID", Config.getConfigParam("google_client_id", "")); modelAndView.addObject("GOOGLE_ANALYTICS_ID", Config.getConfigParam("google_analytics_id", "")); modelAndView.addObject("includeHighlightJS", Config.getConfigBoolean("code_highlighting_enabled", true)); modelAndView.addObject("isAjaxRequest", utils.isAjaxRequest(request)); modelAndView.addObject("reportTypes", ReportType.values()); modelAndView.addObject("returnto", StringUtils.removeStart(request.getRequestURI(), CONTEXT_PATH)); // Configurable constants modelAndView.addObject("MAX_TEXT_LENGTH", MAX_TEXT_LENGTH); modelAndView.addObject("MAX_TAGS_PER_POST", MAX_TAGS_PER_POST); modelAndView.addObject("MAX_REPLIES_PER_POST", MAX_REPLIES_PER_POST); modelAndView.addObject("MAX_FAV_TAGS", MAX_FAV_TAGS); modelAndView.addObject("ANSWER_VOTEUP_REWARD_AUTHOR", ANSWER_VOTEUP_REWARD_AUTHOR); modelAndView.addObject("QUESTION_VOTEUP_REWARD_AUTHOR", QUESTION_VOTEUP_REWARD_AUTHOR); modelAndView.addObject("VOTEUP_REWARD_AUTHOR", VOTEUP_REWARD_AUTHOR); modelAndView.addObject("ANSWER_APPROVE_REWARD_AUTHOR", ANSWER_APPROVE_REWARD_AUTHOR); modelAndView.addObject("ANSWER_APPROVE_REWARD_VOTER", ANSWER_APPROVE_REWARD_VOTER); modelAndView.addObject("POST_VOTEDOWN_PENALTY_AUTHOR", POST_VOTEDOWN_PENALTY_AUTHOR); modelAndView.addObject("POST_VOTEDOWN_PENALTY_VOTER", POST_VOTEDOWN_PENALTY_VOTER); modelAndView.addObject("VOTER_IFHAS", VOTER_IFHAS); modelAndView.addObject("COMMENTATOR_IFHAS", COMMENTATOR_IFHAS); modelAndView.addObject("CRITIC_IFHAS", CRITIC_IFHAS); modelAndView.addObject("SUPPORTER_IFHAS", SUPPORTER_IFHAS); modelAndView.addObject("GOODQUESTION_IFHAS", GOODQUESTION_IFHAS); modelAndView.addObject("GOODANSWER_IFHAS", GOODANSWER_IFHAS); modelAndView.addObject("ENTHUSIAST_IFHAS", ENTHUSIAST_IFHAS); modelAndView.addObject("FRESHMAN_IFHAS", FRESHMAN_IFHAS); modelAndView.addObject("SCHOLAR_IFHAS", SCHOLAR_IFHAS); modelAndView.addObject("TEACHER_IFHAS", TEACHER_IFHAS); modelAndView.addObject("PROFESSOR_IFHAS", PROFESSOR_IFHAS); modelAndView.addObject("GEEK_IFHAS", GEEK_IFHAS); // Cookies modelAndView.addObject("localeCookieName", LOCALE_COOKIE); modelAndView.addObject("csrfCookieName", CSRF_COOKIE); // Paths modelAndView.addObject("imageslink", IMAGESLINK); // do not add context path prefix! modelAndView.addObject("scriptslink", SCRIPTSLINK); // do not add context path prefix! modelAndView.addObject("styleslink", STYLESLINK); // do not add context path prefix! modelAndView.addObject("peoplelink", CONTEXT_PATH + PEOPLELINK); modelAndView.addObject("profilelink", CONTEXT_PATH + PROFILELINK); modelAndView.addObject("searchlink", CONTEXT_PATH + SEARCHLINK); modelAndView.addObject("signinlink", CONTEXT_PATH + SIGNINLINK); modelAndView.addObject("signoutlink", CONTEXT_PATH + SIGNOUTLINK); modelAndView.addObject("aboutlink", CONTEXT_PATH + ABOUTLINK); modelAndView.addObject("privacylink", CONTEXT_PATH + PRIVACYLINK); modelAndView.addObject("termslink", CONTEXT_PATH + TERMSLINK); modelAndView.addObject("tagslink", CONTEXT_PATH + TAGSLINK); modelAndView.addObject("settingslink", CONTEXT_PATH + SETTINGSLINK); modelAndView.addObject("translatelink", CONTEXT_PATH + TRANSLATELINK); modelAndView.addObject("reportslink", CONTEXT_PATH + REPORTSLINK); modelAndView.addObject("adminlink", CONTEXT_PATH + ADMINLINK); modelAndView.addObject("votedownlink", CONTEXT_PATH + VOTEDOWNLINK); modelAndView.addObject("voteuplink", CONTEXT_PATH + VOTEUPLINK); modelAndView.addObject("questionlink", CONTEXT_PATH + QUESTIONLINK); modelAndView.addObject("questionslink", CONTEXT_PATH + QUESTIONSLINK); modelAndView.addObject("commentlink", CONTEXT_PATH + COMMENTLINK); modelAndView.addObject("postlink", CONTEXT_PATH + POSTLINK); modelAndView.addObject("revisionslink", CONTEXT_PATH + REVISIONSLINK); modelAndView.addObject("feedbacklink", CONTEXT_PATH + FEEDBACKLINK); modelAndView.addObject("languageslink", CONTEXT_PATH + LANGUAGESLINK); // Visual customization modelAndView.addObject("navbarFixedClass", Config.getConfigBoolean("fixed_nav", false) ? "navbar-fixed" : "none"); modelAndView.addObject("showBranding", Config.getConfigBoolean("show_branding", true)); modelAndView.addObject("logoUrl", Config.getConfigParam("logo_url", IMAGESLINK + "/logo.svg")); modelAndView.addObject("logoWidth", Config.getConfigInt("logo_width", 90)); modelAndView.addObject("stylesheetUrl", Config.getConfigParam("stylesheet_url", STYLESLINK + "/style.css")); // Auth & Badges Profile authUser = (Profile) request.getAttribute(AUTH_USER_ATTRIBUTE); modelAndView.addObject("infoStripMsg", authUser == null ? Config.getConfigParam("welcome_message", "") : ""); modelAndView.addObject("authenticated", authUser != null); modelAndView.addObject("canComment", utils.canComment(authUser, request)); modelAndView.addObject("isMod", utils.isMod(authUser)); modelAndView.addObject("isAdmin", utils.isAdmin(authUser)); modelAndView.addObject("utils", Utils.getInstance()); modelAndView.addObject("scooldUtils", utils); modelAndView.addObject("authUser", authUser); modelAndView.addObject("badgelist", utils.checkForBadges(authUser, request)); modelAndView.addObject("request", request); // Spaces modelAndView.addObject("currentSpace", utils.getValidSpaceId(authUser, getCookieValue(request, SPACE_COOKIE))); // Language Locale currentLocale = utils.getCurrentLocale(utils.getLanguageCode(request), request); modelAndView.addObject("currentLocale", currentLocale); modelAndView.addObject("lang", utils.getLang(currentLocale)); modelAndView.addObject("langDirection", utils.isLanguageRTL(currentLocale.getLanguage()) ? "RTL" : "LTR"); // Pagination // check for AJAX pagination requests if (utils.isAjaxRequest(request) && (utils.param(request, "page") || utils.param(request, "page1") || utils.param(request, "page2"))) { modelAndView.setViewName("pagination"); // switch to page fragment view } // CSP, HSTS, etc, headers. See https://securityheaders.com utils.setSecurityHeaders(request, response); // default metadata for social meta tags if (!modelAndView.getModel().containsKey("title")) { modelAndView.addObject("title", Config.APP_NAME); } if (!modelAndView.getModel().containsKey("description")) { modelAndView.addObject("description", Config.getConfigParam("meta_description", "")); } if (!modelAndView.getModel().containsKey("ogimage")) { modelAndView.addObject("ogimage", IMAGESLINK + "/logowhite.png"); } }
From source file:de.uni_koeln.spinfo.maalr.webapp.util.DebugInterceptor.java
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (enabled) { long startTime = (Long) request.getAttribute("startTime"); long endTime = System.currentTimeMillis(); long executeTime = endTime - startTime; if (modelAndView != null) { logger.debug(/*from www . j a va 2 s .c o m*/ "Execution Time for view '" + modelAndView.getViewName() + "': " + executeTime + " ms."); } else { //logger.debug("Execution Time for request: " + executeTime + " ms."); } } }
From source file:org.zilverline.web.TestIndexController.java
public void testIndexController() throws Exception { assertTrue(applicationContext.containsBean("indexController")); assertTrue(applicationContext.containsBean("collectionMan")); IndexController ixC = (IndexController) applicationContext.getBean("indexController"); CollectionManager colM = (CollectionManager) applicationContext.getBean("collectionMan"); assertEquals(ixC.getCollectionManager(), colM); log.debug(ixC.getApplicationContext().getBeanDefinitionNames()); CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); log.debug("Index is at: " + colMan.getIndexBaseDir()); // get the testdata collection FileSystemCollection col = (FileSystemCollection) colMan.getCollectionByName("testdata"); assertNotNull(col);/*from w ww . j a va2 s . c o m*/ CollectionForm cf = new CollectionForm(); cf.setNames(new String[] { col.getName() }); // full index cf.setFullIndex(true); ModelAndView mv = ixC.onSubmit(cf); assertTrue(col.isIndexValid()); while (col.isIndexingInProgress()) { Thread.sleep(100); // col.stopRequest(); log.debug("zzz"); } assertEquals("14 docs", 14, col.getNumberOfDocs()); assertEquals("returned correct view name", mv.getViewName(), "collections"); assertTrue(mv.getModel().containsKey("collections")); }
From source file:cherry.foundation.springmvc.OperationLogHandlerInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { StringBuilder builder = createBasicInfo(request); if (modelAndView == null) { builder.append(" ModelAndView=null"); } else if (modelAndView.hasView()) { builder.append(" viewName=").append(modelAndView.getViewName()); } else {//from w ww . ja v a 2 s.c om builder.append(" noView"); } loggerMiddle.info(builder.toString()); }
From source file:com.ctc.storefront.interceptors.beforeview.CmsPageBeforeViewHandler.java
protected void assignViewForPreviewPage(final ModelAndView modelAndView, final AbstractPageModel requestedPage, final AbstractPageModel previewPage) { // Check to see if we are using the default view for the page if (modelAndView.getViewName() != null && modelAndView.getViewName().equals(getViewForPage(requestedPage))) { final String viewForPreviewPage = getViewForPage(previewPage); if (viewForPreviewPage != null && !viewForPreviewPage.equals(modelAndView.getViewName())) { // Change the view name LOG.info("Changing view from [" + modelAndView.getViewName() + "] to preview view [" + viewForPreviewPage + "]"); modelAndView.setViewName(viewForPreviewPage); }/* www. j a va2 s. co m*/ } }
From source file:org.duracloud.account.app.controller.UserControllerTest.java
@Test public void testGetNewForm() { HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class); HttpSession session = EasyMock.createMock(HttpSession.class); EasyMock.expect(session.getAttribute("redemptionCode")).andReturn(null).anyTimes(); EasyMock.expect(request.getSession()).andReturn(session).anyTimes(); replayMocks();/*from www . java 2 s.c o m*/ EasyMock.replay(request, session); ModelAndView mv = userController.getNewForm(request); Assert.assertEquals(UserController.NEW_USER_VIEW, mv.getViewName()); Map<String, Object> map = mv.getModel(); Assert.assertNotNull(map); Assert.assertTrue(map.containsKey(UserController.NEW_USER_FORM_KEY)); Object obj = map.get(UserController.NEW_USER_FORM_KEY); Assert.assertNotNull(obj); Assert.assertTrue(obj instanceof NewUserForm); EasyMock.verify(request, session); }