当前位置: 首页>>代码示例>>Java>>正文


Java AbstractView类代码示例

本文整理汇总了Java中org.springframework.web.servlet.view.AbstractView的典型用法代码示例。如果您正苦于以下问题:Java AbstractView类的具体用法?Java AbstractView怎么用?Java AbstractView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AbstractView类属于org.springframework.web.servlet.view包,在下文中一共展示了AbstractView类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveViewName

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Override
public View resolveViewName(final String viewName, Locale locale) throws Exception {
	return new AbstractView () {
		@Override
		public String getContentType() {
			return null;
		}
		@Override
		protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
				HttpServletResponse response) throws Exception {
			for (String key : attrsToValidate.keySet()) {
				assertTrue("Model should contain attribute named " + key, model.containsKey(key));
				assertEquals(attrsToValidate.get(key), model.get(key));
				validatedAttrCount++;
			}
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:UriTemplateServletAnnotationControllerHandlerMethodTests.java

示例2: initialize

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
protected <V extends AbstractView> V initialize (V view) {
  if (attributes != null && !attributes.isEmpty ())
    view.setAttributesMap (attributes);
  if (applicationContext != null)
    view.setApplicationContext (applicationContext);
  if (beanName != null)
    view.setBeanName (beanName);
  if (contentType != null)
    view.setContentType (contentType);
  view.setExposePathVariables (exposePathVariables);
  if (requestContextAttribute != null)
    view.setRequestContextAttribute (requestContextAttribute);
  if (servletContext != null)
    view.setServletContext (servletContext);
  return view;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:17,代码来源:AbstractViewBuilder.java

示例3: validTemplateName

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Test
public void validTemplateName() throws Exception {
	FreeMarkerView fv = new FreeMarkerView();

	WebApplicationContext wac = mock(WebApplicationContext.class);
	MockServletContext sc = new MockServletContext();

	Map<String, FreeMarkerConfig> configs = new HashMap<String, FreeMarkerConfig>();
	FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
	configurer.setConfiguration(new TestConfiguration());
	configs.put("configurer", configurer);
	given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
	given(wac.getServletContext()).willReturn(sc);

	fv.setUrl("templateName");
	fv.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addPreferredLocale(Locale.US);
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	HttpServletResponse response = new MockHttpServletResponse();

	Map<String, Object> model = new HashMap<String, Object>();
	model.put("myattr", "myvalue");
	fv.render(model, request, response);

	assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, response.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:FreeMarkerViewTests.java

示例4: error

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Bean
public View error() {
	return new AbstractView() {
		@Override
		protected void renderMergedOutputModel(Map<String, Object> model,
				HttpServletRequest request, HttpServletResponse response)
						throws Exception {
			response.getWriter().write("ERROR_BEAN");
		}
	};
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:BasicErrorControllerMockMvcTests.java

示例5: jsonView

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Bean
public View jsonView() {
	return new AbstractView() {

		@Override
		protected void renderMergedOutputModel(Map<String, Object> model,
				HttpServletRequest request, HttpServletResponse response)
						throws Exception {
			response.getOutputStream().write("Hello World".getBytes());
		}
	};
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:WebMvcAutoConfigurationTests.java

示例6: resolveViewName

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
  switch (viewName) {
    case "owner/index":
      AbstractView view = new OwnerPdfView();
      view.setBeanName(viewName);
      return view;
  }

  return null;
}
 
开发者ID:puncha,项目名称:petclinic,代码行数:12,代码来源:PdfViewResolver.java

示例7: resolveViewName

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
  switch (viewName) {
    case "owner/index":
      AbstractView view = new OwnerAtomFeedView();
      view.setBeanName(viewName);
      return view;
  }

  return null;
}
 
开发者ID:puncha,项目名称:petclinic,代码行数:12,代码来源:AtomFeedViewResolver.java

示例8: resolveViewName

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
  switch (viewName) {
    case "owner/index":
      AbstractView view = new OwnerExcelView();
      view.setBeanName(viewName);
      return view;
  }

  return null;
}
 
开发者ID:puncha,项目名称:petclinic,代码行数:12,代码来源:ExcelViewResolver.java

示例9: testValidTemplateName

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Test
public void testValidTemplateName() throws Exception {
	FreeMarkerView fv = new FreeMarkerView();

	WebApplicationContext wac = mock(WebApplicationContext.class);
	MockServletContext sc = new MockServletContext();

	Map configs = new HashMap();
	FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
	configurer.setConfiguration(new TestConfiguration());
	configs.put("configurer", configurer);
	given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
	given(wac.getServletContext()).willReturn(sc);

	fv.setUrl("templateName");
	fv.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addPreferredLocale(Locale.US);
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	HttpServletResponse response = new MockHttpServletResponse();

	Map model = new HashMap();
	model.put("myattr", "myvalue");
	fv.render(model, request, response);

	assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, response.getContentType());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:30,代码来源:FreeMarkerViewTests.java

示例10: testExposeHelpers

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Test
public void testExposeHelpers() throws Exception {
	final String templateName = "test.vm";

	WebApplicationContext wac = mock(WebApplicationContext.class);
	given(wac.getServletContext()).willReturn(new MockServletContext());

	final Template expectedTemplate = new Template();
	VelocityConfig vc = new VelocityConfig() {
		@Override
		public VelocityEngine getVelocityEngine() {
			return new TestVelocityEngine(templateName, expectedTemplate);
		}
	};
	Map<String, VelocityConfig> configurers = new HashMap<String, VelocityConfig>();
	configurers.put("velocityConfigurer", vc);
	given(wac.getBeansOfType(VelocityConfig.class, true, false)).willReturn(configurers);


	// let it ask for locale
	HttpServletRequest req = mock(HttpServletRequest.class);
	given(req.getAttribute(View.PATH_VARIABLES)).willReturn(null);
	given(req.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).willReturn(new AcceptHeaderLocaleResolver());
	given(req.getLocale()).willReturn(Locale.CANADA);

	final HttpServletResponse expectedResponse = new MockHttpServletResponse();

	VelocityView vv = new VelocityView() {
		@Override
		protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
			assertTrue(template == expectedTemplate);
			assertTrue(response == expectedResponse);

			assertEquals("myValue", context.get("myHelper"));
			assertTrue(context.get("math") instanceof MathTool);

			assertTrue(context.get("dateTool") instanceof DateTool);
			DateTool dateTool = (DateTool) context.get("dateTool");
			assertTrue(dateTool.getLocale().equals(Locale.CANADA));

			assertTrue(context.get("numberTool") instanceof NumberTool);
			NumberTool numberTool = (NumberTool) context.get("numberTool");
			assertTrue(numberTool.getLocale().equals(Locale.CANADA));
		}

		@Override
		protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
			model.put("myHelper", "myValue");
		}
	};

	vv.setUrl(templateName);
	vv.setApplicationContext(wac);
	Map<String, Class<?>> toolAttributes = new HashMap<String, Class<?>>();
	toolAttributes.put("math", MathTool.class);
	vv.setToolAttributes(toolAttributes);
	vv.setDateToolAttribute("dateTool");
	vv.setNumberToolAttribute("numberTool");
	vv.setExposeSpringMacroHelpers(false);

	vv.render(new HashMap<String, Object>(), req, expectedResponse);

	assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, expectedResponse.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:65,代码来源:VelocityViewTests.java

示例11: testExposeHelpers

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
@Test
public void testExposeHelpers() throws Exception {
	final String templateName = "test.vm";

	WebApplicationContext wac = mock(WebApplicationContext.class);
	given(wac.getServletContext()).willReturn(new MockServletContext());

	final Template expectedTemplate = new Template();
	VelocityConfig vc = new VelocityConfig() {
		@Override
		public VelocityEngine getVelocityEngine() {
			return new TestVelocityEngine(templateName, expectedTemplate);
		}
	};
	Map<String, VelocityConfig> configurers = new HashMap<String, VelocityConfig>();
	configurers.put("velocityConfigurer", vc);
	given(wac.getBeansOfType(VelocityConfig.class, true, false)).willReturn(configurers);


	// let it ask for locale
	HttpServletRequest req = mock(HttpServletRequest.class);
	given(req.getAttribute(View.PATH_VARIABLES)).willReturn(null);
	given(req.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).willReturn(new AcceptHeaderLocaleResolver());
	given(req.getLocale()).willReturn(Locale.CANADA);

	final HttpServletResponse expectedResponse = new MockHttpServletResponse();

	VelocityView vv = new VelocityView() {
		@Override
		protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
			assertTrue(template == expectedTemplate);
			assertTrue(response == expectedResponse);

			assertEquals("myValue", context.get("myHelper"));
			assertTrue(context.get("math") instanceof MathTool);

			assertTrue(context.get("dateTool") instanceof DateTool);
			DateTool dateTool = (DateTool) context.get("dateTool");
			assertTrue(dateTool.getLocale().equals(Locale.CANADA));

			assertTrue(context.get("numberTool") instanceof NumberTool);
			NumberTool numberTool = (NumberTool) context.get("numberTool");
			assertTrue(numberTool.getLocale().equals(Locale.CANADA));
		}

		@Override
		protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
			model.put("myHelper", "myValue");
		}
	};

	vv.setUrl(templateName);
	vv.setApplicationContext(wac);
	Map<String, Class> toolAttributes = new HashMap<String, Class>();
	toolAttributes.put("math", MathTool.class);
	vv.setToolAttributes(toolAttributes);
	vv.setDateToolAttribute("dateTool");
	vv.setNumberToolAttribute("numberTool");
	vv.setExposeSpringMacroHelpers(false);

	vv.render(new HashMap<String, Object>(), req, expectedResponse);

	assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, expectedResponse.getContentType());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:65,代码来源:VelocityViewTests.java

示例12: applyLifecycleMethods

import org.springframework.web.servlet.view.AbstractView; //导入依赖的package包/类
private View applyLifecycleMethods(String viewName, AbstractView view) {
	return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
}
 
开发者ID:matiwinnetou,项目名称:spring-soy-view,代码行数:4,代码来源:SoyTemplateViewResolver.java


注:本文中的org.springframework.web.servlet.view.AbstractView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。