ReloadDefinitionsAction xref

View Javadoc

    1   /*
    2    * $Id: ReloadDefinitionsAction.java 471754 2006-11-06 14:55:09Z husted $
    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 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  }