1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.struts.tiles.actions;
21
22 import java.io.PrintWriter;
23
24 import javax.servlet.ServletContext;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
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: 421151 $ $Date: 2006-07-11 23:07:14 -0700 (Tue, 11 Jul 2006) $
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 request,
66 HttpServletResponse response)
67 throws Exception
68 {
69 response.setContentType("text/plain");
70 PrintWriter writer = response.getWriter();
71
72 try {
73 ServletContext context = getServlet().getServletContext();
74 DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(request, context);
75 factory.setConfig(factory.getConfig(), context);
76 writer.println("OK");
77 } catch (ClassCastException 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 }