KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > tiles > actions > ReloadDefinitionsAction


1 /*
2  * $Id: ReloadDefinitionsAction.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
20 package org.apache.struts.tiles.actions;
21
22 import java.io.PrintWriter JavaDoc;
23
24 import javax.servlet.ServletContext JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.tiles.DefinitionsFactory;
33 import org.apache.struts.tiles.DefinitionsFactoryException;
34 import org.apache.struts.tiles.TilesUtil;
35
36
37
38 /**
39  * <p>A standard <strong>Action</strong> that calls the
40  * <code>reload()</code> method of our controller servlet to
41  * reload its configuration information from the configuration
42  * files (which have presumably been updated) dynamically.</p>
43  *
44  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
45  */

46
47 public class ReloadDefinitionsAction extends Action {
48
49     /**
50      * Process the specified HTTP request, and create the corresponding HTTP
51      * response (or forward to another web component that will create it),
52      * with provision for handling exceptions thrown by the business logic.
53      *
54      * @param mapping The ActionMapping used to select this instance
55      * @param form The optional ActionForm bean for this request (if any)
56      * @param request The HTTP request we are processing
57      * @param response The HTTP response we are creating
58      *
59      * @exception Exception if the application business logic throws
60      * an exception
61      * @since Struts 1.1
62      */

63     public ActionForward execute(ActionMapping mapping,
64                                  ActionForm form,
65                                  HttpServletRequest JavaDoc request,
66                                  HttpServletResponse JavaDoc response)
67         throws Exception JavaDoc
68     {
69         response.setContentType("text/plain");
70         PrintWriter JavaDoc writer = response.getWriter();
71
72         try {
73           ServletContext JavaDoc context = getServlet().getServletContext();
74             DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(request, context);
75             factory.setConfig(factory.getConfig(), context);
76             writer.println("OK");
77         } catch (ClassCastException JavaDoc e) {
78             writer.println("FAIL - " + e.toString());
79             getServlet().log("ReloadAction", e);
80         } catch (DefinitionsFactoryException e) {
81             writer.println("FAIL - " + e.toString());
82             getServlet().log("ReloadAction", e);
83         }
84
85         writer.flush();
86         writer.close();
87
88         return (null);
89
90     }
91
92 }
93
94
Popular Tags