1 /*
2 * $Id$
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
22 package org.apache.struts.tiles;
23
24 import java.io.IOException;
25
26 import jakarta.servlet.RequestDispatcher;
27 import jakarta.servlet.ServletContext;
28 import jakarta.servlet.ServletException;
29 import jakarta.servlet.http.HttpServletRequest;
30 import jakarta.servlet.http.HttpServletResponse;
31
32 /**
33 * Tiles controller including a local URL.
34 */
35 public class UrlController implements Controller {
36 private static final long serialVersionUID = -3427605980038213048L;
37
38 /**
39 * URL associated with this controller.
40 */
41 protected String url = null;
42
43 /**
44 * Constructor.
45 * @param url URL.
46 */
47 public UrlController(String url) {
48 this.url = url;
49 }
50
51 /**
52 * Method associated to a tile and called immediately before the tile
53 * is included. This implementation calls an <code>Action</code>.
54 * No servlet is set by this method.
55 *
56 * @param tileContext Current tile context.
57 * @param request Current request.
58 * @param response Current response.
59 * @param servletContext Current servlet context.
60 * @deprecated Use execute() instead. This will be removed after
61 * Struts 1.2.
62 */
63 @Deprecated
64 public void perform(
65 ComponentContext tileContext,
66 HttpServletRequest request,
67 HttpServletResponse response,
68 ServletContext servletContext)
69 throws ServletException, IOException {
70
71 RequestDispatcher rd = servletContext.getRequestDispatcher(url);
72 if (rd == null) {
73 throw new ServletException(
74 "Controller can't find url '" + url + "'.");
75 }
76
77 rd.include(request, response);
78 }
79
80 /**
81 * @see org.apache.struts.tiles.Controller#execute(org.apache.struts.tiles.ComponentContext, jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletContext)
82 */
83 public void execute(
84 ComponentContext tileContext,
85 HttpServletRequest request,
86 HttpServletResponse response,
87 ServletContext servletContext)
88 throws Exception {
89
90 RequestDispatcher rd = servletContext.getRequestDispatcher(url);
91 if (rd == null) {
92 throw new ServletException(
93 "Controller can't find url '" + url + "'.");
94 }
95
96 rd.include(request, response);
97 }
98 }