1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.struts.tiles.actions;
24
25 import java.io.PrintWriter;
26
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35 import org.apache.struts.tiles.DefinitionsFactory;
36 import org.apache.struts.tiles.DefinitionsFactoryException;
37 import org.apache.struts.tiles.TilesUtil;
38
39
40
41 /**
42 * <p>A standard <strong>Action</strong> that calls the
43 * <code>reload()</code> method of our controller servlet to
44 * reload its configuration information from the configuration
45 * files (which have presumably been updated) dynamically.</p>
46 *
47 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
48 */
49
50 public class ReloadDefinitionsAction extends Action {
51
52 /**
53 * Process the specified HTTP request, and create the corresponding HTTP
54 * response (or forward to another web component that will create it),
55 * with provision for handling exceptions thrown by the business logic.
56 *
57 * @param mapping The ActionMapping used to select this instance
58 * @param form The optional ActionForm bean for this request (if any)
59 * @param request The HTTP request we are processing
60 * @param response The HTTP response we are creating
61 *
62 * @exception Exception if the application business logic throws
63 * an exception
64 * @since Struts 1.1
65 */
66 public ActionForward execute(ActionMapping mapping,
67 ActionForm form,
68 HttpServletRequest request,
69 HttpServletResponse response)
70 throws Exception
71 {
72 response.setContentType("text/plain");
73 PrintWriter writer = response.getWriter();
74
75 try {
76 ServletContext context = getServlet().getServletContext();
77 DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(request, context);
78 factory.setConfig(factory.getConfig(), context);
79 writer.println("OK");
80 } catch (ClassCastException e) {
81 writer.println("FAIL - " + e.toString());
82 getServlet().log("ReloadAction", e);
83 } catch (DefinitionsFactoryException e) {
84 writer.println("FAIL - " + e.toString());
85 getServlet().log("ReloadAction", e);
86 }
87
88 writer.flush();
89 writer.close();
90
91 return (null);
92
93 }
94
95 }