1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.ajax;
18
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
22 import org.apache.jetspeed.pipeline.PipelineException;
23 import org.apache.jetspeed.pipeline.valve.AbstractValve;
24 import org.apache.jetspeed.pipeline.valve.ValveContext;
25 import org.apache.jetspeed.request.RequestContext;
26
27 /***
28 * This should eventually replace the AJAX ServletFilter.
29 *
30 * @author <href a="mailto:weaver@apache.org">Scott T. Weaver </a>
31 *
32 */
33 public class AJAXValve extends AbstractValve
34 {
35 private AJAXService ajaxService;
36 private PortletActionSecurityBehavior securityBehavior;
37
38 public AJAXValve(AJAXService service, PortletActionSecurityBehavior securityBehavior)
39 {
40 super();
41 this.ajaxService = service;
42 this.securityBehavior = securityBehavior;
43 }
44
45 public void invoke( RequestContext request, ValveContext context )
46 throws PipelineException
47 {
48 HttpServletResponse response = request.getResponse();
49 try
50 {
51 response.setContentType("text/xml");
52 if (!securityBehavior.checkAccess(request, "edit"))
53 {
54 throw new AJAXException("Access Denied.");
55 }
56 AJAXRequest ajaxRequest = new AJAXRequestImpl(request.getRequest(), response, request.getConfig().getServletContext());
57 ajaxService.processRequest(ajaxRequest);
58 }
59 catch (AJAXException e)
60 {
61 try
62 {
63 response.sendError(500, e.getMessage());
64 }
65 catch (Exception e2)
66 {
67 throw new PipelineException(e2.getMessage(), e2);
68 }
69 }
70 catch(Exception e)
71 {
72 throw new PipelineException(e.getMessage(), e);
73 }
74
75
76 context.invokeNext(request);
77 }
78
79 public String toString()
80 {
81 return "AJAXValve";
82 }
83
84
85
86 }