org.apache.tiles.request.Request Java Examples

The following examples show how to use org.apache.tiles.request.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TilesView.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	Assert.state(this.renderer != null, "No Renderer set");

	exposeModelAsRequestAttributes(model, request);
	if (this.exposeJstlAttributes) {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
	if (this.alwaysInclude) {
		request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
	}

	Request tilesRequest = createTilesRequest(request, response);
	this.renderer.render(getUrl(), tilesRequest);
}
 
Example #2
Source File: TilesConfigurerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleBootstrap() {
	MockServletContext servletContext = new MockServletContext();

	TilesConfigurer tc = new TilesConfigurer();
	tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
	tc.setCheckRefresh(true);
	tc.setServletContext(servletContext);
	tc.afterPropertiesSet();

	ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext);

	BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext);
	Request requestContext = new ServletRequest(container.getApplicationContext(),
			new MockHttpServletRequest(), new MockHttpServletResponse());
	assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));

	tc.destroy();
}
 
Example #3
Source File: TilesConfigurerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void simpleBootstrap() {
	MockServletContext servletContext = new MockServletContext();

	TilesConfigurer tc = new TilesConfigurer();
	tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
	tc.setCheckRefresh(true);
	tc.setServletContext(servletContext);
	tc.afterPropertiesSet();

	ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext);

	BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext);
	Request requestContext = new ServletRequest(container.getApplicationContext(),
			new MockHttpServletRequest(), new MockHttpServletResponse());
	assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));

	tc.destroy();
}
 
Example #4
Source File: TilesView.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	Assert.state(this.renderer != null, "No Renderer set");

	exposeModelAsRequestAttributes(model, request);
	if (this.exposeJstlAttributes) {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
	if (this.alwaysInclude) {
		request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
	}

	Request tilesRequest = createTilesRequest(request, response);
	this.renderer.render(getUrl(), tilesRequest);
}
 
Example #5
Source File: TilesView.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public boolean checkResource(final Locale locale) throws Exception {
	Assert.state(this.renderer != null, "No Renderer set");

	HttpServletRequest servletRequest = null;
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes instanceof ServletRequestAttributes) {
		servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
	}

	Request request = new ServletRequest(this.applicationContext, servletRequest, null) {
		@Override
		public Locale getRequestLocale() {
			return locale;
		}
	};

	return this.renderer.isRenderable(getUrl(), request);
}
 
Example #6
Source File: TilesConfigurerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void simpleBootstrap() {
	MockServletContext servletContext = new MockServletContext();

	TilesConfigurer tc = new TilesConfigurer();
	tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
	tc.setCheckRefresh(true);
	tc.setServletContext(servletContext);
	tc.afterPropertiesSet();

	ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext);

	BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext);
	Request requestContext = new ServletRequest(container.getApplicationContext(),
			new MockHttpServletRequest(), new MockHttpServletResponse());
	assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));

	tc.destroy();
}
 
Example #7
Source File: TilesView.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public boolean checkResource(final Locale locale) throws Exception {
	Assert.state(this.renderer != null, "No Renderer set");

	HttpServletRequest servletRequest = null;
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes instanceof ServletRequestAttributes) {
		servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
	}

	Request request = new ServletRequest(this.applicationContext, servletRequest, null) {
		@Override
		public Locale getRequestLocale() {
			return locale;
		}
	};

	return this.renderer.isRenderable(getUrl(), request);
}
 
Example #8
Source File: TilesView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a Tiles {@link Request}.
 * <p>This implementation creates a {@link ServletRequest}.
 * @param request the current request
 * @param response the current response
 * @return the Tiles request
 */
protected Request createTilesRequest(final HttpServletRequest request, HttpServletResponse response) {
	return new ServletRequest(this.applicationContext, request, response) {
		@Override
		public Locale getRequestLocale() {
			return RequestContextUtils.getLocale(request);
		}
	};
}
 
Example #9
Source File: TilesTemplateViewPreparer.java    From lognavigator with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Request tilesContext, AttributeContext attributeContext) {
	
	try {
		// Get authorized log access configs for current user 
		Authentication authorizedUser = SecurityContextHolder.getContext().getAuthentication();
		Set<LogAccessConfig> allLogAccessConfigs = configService.getLogAccessConfigs();
		Set<LogAccessConfig> authorizedLogAccessConfigs = authorizationService.getAuthorizedLogAccessConfigs(allLogAccessConfigs, authorizedUser);
		
		// Create map <displayGroup> -> <logAccessConfig>
		Map<String, Set<LogAccessConfig>> logAccessConfigsMap = new TreeMap<String, Set<LogAccessConfig>>();
		for (LogAccessConfig logAccessConfig : authorizedLogAccessConfigs) {
			String displayGroup = logAccessConfig.getDisplayGroup() != null ? logAccessConfig.getDisplayGroup() : "";
			Set<LogAccessConfig> logAccessConfigIds = logAccessConfigsMap.get(displayGroup);
			if (logAccessConfigIds == null) {
				logAccessConfigIds = new TreeSet<LogAccessConfig>();
				logAccessConfigsMap.put(displayGroup, logAccessConfigIds);
			}
			logAccessConfigIds.add(logAccessConfig);
		}
		
		// Inject logAccessConfigIds map into request scope
		tilesContext.getContext(Request.REQUEST_SCOPE).put(LOG_ACCESS_CONFIG_IDS_BY_DISPLAY_GROUP_KEY, logAccessConfigsMap);
	}
	catch (ConfigException e) {
		LOGGER.error("Error while loading configuration", e);
	}
}
 
Example #10
Source File: TilesViewTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void render() throws Exception {
	Map<String, Object> model = new HashMap<String, Object>();
	model.put("modelAttribute", "modelValue");
	view.render(model, request, response);
	assertEquals("modelValue", request.getAttribute("modelAttribute"));
	verify(renderer).render(eq(VIEW_PATH), isA(Request.class));
}
 
Example #11
Source File: TilesViewResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
	given(this.renderer.isRenderable(eq("/template.test"), isA(Request.class))).willReturn(true);
	given(this.renderer.isRenderable(eq("/nonexistent.test"), isA(Request.class))).willReturn(false);

	assertTrue(this.viewResolver.resolveViewName("/template.test", Locale.ITALY) instanceof TilesView);
	assertNull(this.viewResolver.resolveViewName("/nonexistent.test", Locale.ITALY));

	verify(this.renderer).isRenderable(eq("/template.test"), isA(Request.class));
	verify(this.renderer).isRenderable(eq("/nonexistent.test"), isA(Request.class));
}
 
Example #12
Source File: SpringLocaleResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Locale resolveLocale(Request request) {
	try {
		HttpServletRequest servletRequest = ServletUtil.getServletRequest(request).getRequest();
		if (servletRequest != null) {
			return RequestContextUtils.getLocale(servletRequest);
		}
	}
	catch (NotAServletEnvironmentException e) {
		// Ignore
	}
	return super.resolveLocale(request);
}
 
Example #13
Source File: TilesView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Tiles {@link Request}.
 * <p>This implementation creates a {@link ServletRequest}.
 * @param request the current request
 * @param response the current response
 * @return the Tiles request
 */
protected Request createTilesRequest(final HttpServletRequest request, HttpServletResponse response) {
	return new ServletRequest(this.applicationContext, request, response) {
		@Override
		public Locale getRequestLocale() {
			return RequestContextUtils.getLocale(request);
		}
	};
}
 
Example #14
Source File: TilesView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	exposeModelAsRequestAttributes(model, request);
	if (this.exposeJstlAttributes) {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
	if (this.alwaysInclude) {
		request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
	}

	Request tilesRequest = createTilesRequest(request, response);
	this.renderer.render(getUrl(), tilesRequest);
}
 
Example #15
Source File: TilesView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkResource(final Locale locale) throws Exception {
	HttpServletRequest servletRequest = null;
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes instanceof ServletRequestAttributes) {
		servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
	}
	Request request = new ServletRequest(this.applicationContext, servletRequest, null) {
		@Override
		public Locale getRequestLocale() {
			return locale;
		}
	};
	return this.renderer.isRenderable(getUrl(), request);
}
 
Example #16
Source File: SpringLocaleResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Locale resolveLocale(Request request) {
	try {
		HttpServletRequest servletRequest = ServletUtil.getServletRequest(request).getRequest();
		if (servletRequest != null) {
			return RequestContextUtils.getLocale(servletRequest);
		}
	}
	catch (NotAServletEnvironmentException ex) {
		// ignore
	}
	return super.resolveLocale(request);
}
 
Example #17
Source File: TilesViewTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void render() throws Exception {
	Map<String, Object> model = new HashMap<>();
	model.put("modelAttribute", "modelValue");
	view.render(model, request, response);
	assertEquals("modelValue", request.getAttribute("modelAttribute"));
	verify(renderer).render(eq(VIEW_PATH), isA(Request.class));
}
 
Example #18
Source File: TilesView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	exposeModelAsRequestAttributes(model, request);
	if (this.exposeJstlAttributes) {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
	if (this.alwaysInclude) {
		request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
	}

	Request tilesRequest = createTilesRequest(request, response);
	this.renderer.render(getUrl(), tilesRequest);
}
 
Example #19
Source File: TilesView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean checkResource(final Locale locale) throws Exception {
	HttpServletRequest servletRequest = null;
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes instanceof ServletRequestAttributes) {
		servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
	}
	Request request = new ServletRequest(this.applicationContext, servletRequest, null) {
		@Override
		public Locale getRequestLocale() {
			return locale;
		}
	};
	return this.renderer.isRenderable(getUrl(), request);
}
 
Example #20
Source File: TilesView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a Tiles {@link Request}.
 * <p>This implementation creates a {@link ServletRequest}.
 * @param request the current request
 * @param response the current response
 * @return the Tiles request
 */
protected Request createTilesRequest(final HttpServletRequest request, HttpServletResponse response) {
	return new ServletRequest(this.applicationContext, request, response) {
		@Override
		public Locale getRequestLocale() {
			return RequestContextUtils.getLocale(request);
		}
	};
}
 
Example #21
Source File: TilesViewTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void render() throws Exception {
	Map<String, Object> model = new HashMap<>();
	model.put("modelAttribute", "modelValue");
	view.render(model, request, response);
	assertEquals("modelValue", request.getAttribute("modelAttribute"));
	verify(renderer).render(eq(VIEW_PATH), isA(Request.class));
}
 
Example #22
Source File: TilesViewResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
	given(this.renderer.isRenderable(eq("/template.test"), isA(Request.class))).willReturn(true);
	given(this.renderer.isRenderable(eq("/nonexistent.test"), isA(Request.class))).willReturn(false);

	assertTrue(this.viewResolver.resolveViewName("/template.test", Locale.ITALY) instanceof TilesView);
	assertNull(this.viewResolver.resolveViewName("/nonexistent.test", Locale.ITALY));

	verify(this.renderer).isRenderable(eq("/template.test"), isA(Request.class));
	verify(this.renderer).isRenderable(eq("/nonexistent.test"), isA(Request.class));
}
 
Example #23
Source File: SpringLocaleResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Locale resolveLocale(Request request) {
	try {
		HttpServletRequest servletRequest = ServletUtil.getServletRequest(request).getRequest();
		if (servletRequest != null) {
			return RequestContextUtils.getLocale(servletRequest);
		}
	}
	catch (NotAServletEnvironmentException ex) {
		// ignore
	}
	return super.resolveLocale(request);
}
 
Example #24
Source File: TilesView.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a Tiles {@link Request}.
 * <p>This implementation creates a {@link ServletRequest}.
 * @param request the current request
 * @param response the current response
 * @return the Tiles request
 */
protected Request createTilesRequest(final HttpServletRequest request, HttpServletResponse response) {
	return new ServletRequest(this.applicationContext, request, response) {
		@Override
		public Locale getRequestLocale() {
			return RequestContextUtils.getLocale(request);
		}
	};
}
 
Example #25
Source File: SpringLocaleResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Locale resolveLocale(Request request) {
	try {
		HttpServletRequest servletRequest = ServletUtil.getServletRequest(request).getRequest();
		if (servletRequest != null) {
			return RequestContextUtils.getLocale(servletRequest);
		}
	}
	catch (NotAServletEnvironmentException ex) {
		// ignore
	}
	return super.resolveLocale(request);
}
 
Example #26
Source File: TilesViewResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
	given(this.renderer.isRenderable(eq("/template.test"), isA(Request.class))).willReturn(true);
	given(this.renderer.isRenderable(eq("/nonexistent.test"), isA(Request.class))).willReturn(false);

	assertTrue(this.viewResolver.resolveViewName("/template.test", Locale.ITALY) instanceof TilesView);
	assertNull(this.viewResolver.resolveViewName("/nonexistent.test", Locale.ITALY));

	verify(this.renderer).isRenderable(eq("/template.test"), isA(Request.class));
	verify(this.renderer).isRenderable(eq("/nonexistent.test"), isA(Request.class));
}