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
)
26 if (!value
.getLocation().isEmpty())
27 response
.setHeader("Location", value
.getLocation());
28 response
.sendError(value
.getStatusCode(), "");
34 * UTF-8 в tapestry http://wiki.apache.org/tapestry/Tapestry5Utf8Encoding
35 * @param requestGlobals
39 public HttpServletRequestFilter
buildUtf8Filter()
41 return new HttpServletRequestFilter()
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");