KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > tiles > UrlController


1 /*
2  * $Id: UrlController.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.struts.tiles;
20
21 import java.io.IOException JavaDoc;
22
23 import javax.servlet.RequestDispatcher JavaDoc;
24 import javax.servlet.ServletContext JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 /**
30  * Tiles controller including a local URL.
31  */

32 public class UrlController implements Controller {
33
34     /**
35      * URL associated with this controller.
36      */

37     protected String JavaDoc url = null;
38
39     /**
40      * Constructor.
41      * @param url URL.
42      */

43     public UrlController(String JavaDoc url) {
44         this.url = url;
45     }
46
47     /**
48      * Method associated to a tile and called immediately before the tile
49      * is included. This implementation calls an <code>Action</code>.
50      * No servlet is set by this method.
51      *
52      * @param tileContext Current tile context.
53      * @param request Current request.
54      * @param response Current response.
55      * @param servletContext Current servlet context.
56      */

57     public void perform(
58         ComponentContext tileContext,
59         HttpServletRequest JavaDoc request,
60         HttpServletResponse JavaDoc response,
61         ServletContext JavaDoc servletContext)
62         throws ServletException JavaDoc, IOException JavaDoc {
63
64         RequestDispatcher JavaDoc rd = servletContext.getRequestDispatcher(url);
65         if (rd == null) {
66             throw new ServletException JavaDoc(
67                 "Controller can't find url '" + url + "'.");
68         }
69
70         rd.include(request, response);
71     }
72
73     /**
74      * @see org.apache.struts.tiles.Controller#execute(org.apache.struts.tiles.ComponentContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext)
75      */

76     public void execute(
77         ComponentContext tileContext,
78         HttpServletRequest JavaDoc request,
79         HttpServletResponse JavaDoc response,
80         ServletContext JavaDoc servletContext)
81         throws Exception JavaDoc {
82             
83         RequestDispatcher JavaDoc rd = servletContext.getRequestDispatcher(url);
84         if (rd == null) {
85             throw new ServletException JavaDoc(
86                 "Controller can't find url '" + url + "'.");
87         }
88
89         rd.include(request, response);
90
91     }
92
93 }
94
Popular Tags