01: /*
02: * $Id: ReloadDefinitionsAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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.actions;
23:
24: import java.io.PrintWriter;
25:
26: import javax.servlet.ServletContext;
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29:
30: import org.apache.struts.action.Action;
31: import org.apache.struts.action.ActionForm;
32: import org.apache.struts.action.ActionForward;
33: import org.apache.struts.action.ActionMapping;
34: import org.apache.struts.tiles.DefinitionsFactory;
35: import org.apache.struts.tiles.DefinitionsFactoryException;
36: import org.apache.struts.tiles.TilesUtil;
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: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 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, HttpServletRequest request,
65: HttpServletResponse response) throws Exception {
66: response.setContentType("text/plain");
67: PrintWriter writer = response.getWriter();
68:
69: try {
70: ServletContext context = getServlet().getServletContext();
71: DefinitionsFactory factory = TilesUtil
72: .getDefinitionsFactory(request, context);
73: factory.setConfig(factory.getConfig(), context);
74: writer.println("OK");
75: } catch (ClassCastException e) {
76: writer.println("FAIL - " + e.toString());
77: getServlet().log("ReloadAction", e);
78: } catch (DefinitionsFactoryException e) {
79: writer.println("FAIL - " + e.toString());
80: getServlet().log("ReloadAction", e);
81: }
82:
83: writer.flush();
84: writer.close();
85:
86: return (null);
87:
88: }
89:
90: }
|