View Javadoc

    1   /*
    2    * $Id: ViewDefinitionsAction.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.TilesUtil;
    37
    38
    39
    40  /**
    41   * <p>An <strong>Action</strong> that writes the
    42   * definitions of the Tiles factory.
    43   * Useful to check what is effectivly loaded in a
    44   * Tiles factory
    45   */
    46
    47  public class ViewDefinitionsAction 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 =
    75                  TilesUtil.getDefinitionsFactory(request, context );
    76              writer.println( factory.toString() );
    77          } catch (Exception e) {
    78              writer.println("FAIL - " + e.toString());
    79              getServlet().log("ReloadAction", e);
    80          }
    81
    82          writer.flush();
    83          writer.close();
    84
    85          return (null);
    86
    87      }
    88
    89  }