commons pages behavoir (utf8, errors, etc.)
[aramzamzam-commons.git] / aramzamzam-commons / commons-pages-behavoir / src / main / java / net / aramzamzam / commons / pagesbehavoir / services / PagesBehavoirModule.java
bloba403738c761d781c3908e58bfc2319e8e0ede707
1 package net.aramzamzam.commons.pagesbehavoir.services;
3 import java.io.IOException;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
8 import org.apache.tapestry5.ioc.MappedConfiguration;
9 import org.apache.tapestry5.ioc.OrderedConfiguration;
10 import org.apache.tapestry5.ioc.annotations.InjectService;
11 import org.apache.tapestry5.services.ComponentEventResultProcessor;
12 import org.apache.tapestry5.services.HttpServletRequestFilter;
13 import org.apache.tapestry5.services.HttpServletRequestHandler;
14 import org.apache.tapestry5.services.Response;
16 public class PagesBehavoirModule {
18 @SuppressWarnings("unchecked")
19 public static void contributeComponentEventResultProcessor(
20 MappedConfiguration<Class, ComponentEventResultProcessor> configuration,
21 final Response response) {
22 configuration.add(HttpStatusCode.class,
23 new ComponentEventResultProcessor<HttpStatusCode>() {
24 public void processResultValue(HttpStatusCode value)
25 throws IOException {
26 if (!value.getLocation().isEmpty())
27 response.setHeader("Location", value.getLocation());
28 response.sendError(value.getStatusCode(), "");
30 });
33 /**
34 * UTF-8 в tapestry http://wiki.apache.org/tapestry/Tapestry5Utf8Encoding
35 * @param requestGlobals
36 * @return
39 public HttpServletRequestFilter buildUtf8Filter()
41 return new HttpServletRequestFilter()
43 @Override
44 public boolean service(HttpServletRequest request,
45 HttpServletResponse response,
46 HttpServletRequestHandler handler) throws IOException {
47 request.setCharacterEncoding("UTF-8");
48 return handler.service(request, response);
53 public void contributeHttpServletRequestHandler(
54 OrderedConfiguration<HttpServletRequestFilter> configuration,
55 @InjectService("Utf8Filter")
56 HttpServletRequestFilter utf8Filter)
58 configuration.add("Utf8Filter", utf8Filter, "before:MultipartFilter");