1 /*
2 * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 package org.apache.struts2.dispatcher.ng;
22
23 import org.apache.struts2.dispatcher.Dispatcher;
24 import org.apache.struts2.dispatcher.StaticContentLoader;
25 import org.apache.struts2.dispatcher.mapper.ActionMapping;
26 import org.apache.struts2.RequestUtils;
27
28 import javax.servlet.ServletContext;
29 import javax.servlet.ServletException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.IOException;
33
34 /**
35 * Contains execution operations for filters
36 */
37 public class ExecuteOperations {
38 private ServletContext servletContext;
39 private Dispatcher dispatcher;
40
41 public ExecuteOperations(ServletContext servletContext, Dispatcher dispatcher) {
42 this.dispatcher = dispatcher;
43 this.servletContext = servletContext;
44 }
45
46 /**
47 * Tries to execute a request for a static resource
48 * @return True if it was handled, false if the filter should fall through
49 * @throws IOException
50 * @throws ServletException
51 */
52 public boolean executeStaticResourceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
53 // there is no action in this request, should we look for a static resource?
54 String resourcePath = RequestUtils.getServletPath(request);
55
56 if ("".equals(resourcePath) && null != request.getPathInfo()) {
57 resourcePath = request.getPathInfo();
58 }
59
60 StaticContentLoader staticResourceLoader = dispatcher.getContainer().getInstance(StaticContentLoader.class);
61 if (staticResourceLoader.canHandle(resourcePath)) {
62 staticResourceLoader.findStaticResource(resourcePath, request, response);
63 // The framework did its job here
64 return true;
65
66 } else {
67 // this is a normal request, let it pass through
68 return false;
69 }
70 }
71
72 /**
73 * Executes an action
74 * @throws ServletException
75 */
76 public void executeAction(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException {
77 dispatcher.serviceAction(request, response, servletContext, mapping);
78 }
79 }