View Javadoc
1   /*
2    * $Id$
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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  
23  package org.apache.struts.tiles.actions;
24  
25  import java.io.PrintWriter;
26  
27  import jakarta.servlet.ServletContext;
28  import jakarta.servlet.http.HttpServletRequest;
29  import jakarta.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$ $Date$
48   */
49  
50  public class ReloadDefinitionsAction extends Action {
51      private static final long serialVersionUID = -7047330717130537765L;
52  
53      /**
54       * Process the specified HTTP request, and create the corresponding HTTP
55       * response (or forward to another web component that will create it),
56       * with provision for handling exceptions thrown by the business logic.
57       *
58       * @param mapping The ActionMapping used to select this instance
59       * @param form The optional ActionForm bean for this request (if any)
60       * @param request The HTTP request we are processing
61       * @param response The HTTP response we are creating
62       *
63       * @exception Exception if the application business logic throws
64       *  an exception
65       * @since Struts 1.1
66       */
67      public ActionForward execute(ActionMapping mapping,
68                                   ActionForm form,
69                                   HttpServletRequest request,
70                                   HttpServletResponse response)
71          throws Exception
72      {
73          response.setContentType("text/plain");
74          PrintWriter writer = response.getWriter();
75  
76          try {
77            ServletContext context = getServlet().getServletContext();
78              DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(request, context);
79              factory.setConfig(factory.getConfig(), context);
80              writer.println("OK");
81          } catch (ClassCastException e) {
82              writer.println("FAIL - " + e.toString());
83              getServlet().log("ReloadAction", e);
84          } catch (DefinitionsFactoryException e) {
85              writer.println("FAIL - " + e.toString());
86              getServlet().log("ReloadAction", e);
87          }
88  
89          writer.flush();
90  
91          return (null);
92      }
93  }