01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: private AJAXService ajaxService;
35: private PortletActionSecurityBehavior securityBehavior;
36:
37: public AJAXValve(AJAXService service,
38: PortletActionSecurityBehavior securityBehavior) {
39: super ();
40: this .ajaxService = service;
41: this .securityBehavior = securityBehavior;
42: }
43:
44: public void invoke(RequestContext request, ValveContext context)
45: throws PipelineException {
46: HttpServletResponse response = request.getResponse();
47: try {
48: response.setContentType("text/xml");
49: if (!securityBehavior.checkAccess(request, "edit")) {
50: throw new AJAXException("Access Denied.");
51: }
52: AJAXRequest ajaxRequest = new AJAXRequestImpl(request
53: .getRequest(), response, request.getConfig()
54: .getServletContext());
55: ajaxService.processRequest(ajaxRequest);
56: } catch (AJAXException e) {
57: try {
58: response.sendError(500, e.getMessage());
59: } catch (Exception e2) {
60: throw new PipelineException(e2.getMessage(), e2);
61: }
62: } catch (Exception e) {
63: throw new PipelineException(e.getMessage(), e);
64: }
65:
66: // Pass control to the next Valve in the Pipeline
67: context.invokeNext(request);
68: }
69:
70: public String toString() {
71: return "AJAXValve";
72: }
73:
74: }
|