View Javadoc

1   /*
2    * $Id: ViewDefinitionsAction.java 421151 2006-07-12 06:07:14Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  package org.apache.struts.tiles.actions;
21  
22  import java.io.PrintWriter;
23  
24  import javax.servlet.ServletContext;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  
28  import org.apache.struts.action.Action;
29  import org.apache.struts.action.ActionForm;
30  import org.apache.struts.action.ActionForward;
31  import org.apache.struts.action.ActionMapping;
32  import org.apache.struts.tiles.DefinitionsFactory;
33  import org.apache.struts.tiles.TilesUtil;
34  
35  
36  
37  /***
38   * <p>An <strong>Action</strong> that writes the
39   * definitions of the Tiles factory.
40   * Useful to check what is effectivly loaded in a
41   * Tiles factory
42   */
43  
44  public class ViewDefinitionsAction extends Action {
45  
46      /***
47       * Process the specified HTTP request, and create the corresponding HTTP
48       * response (or forward to another web component that will create it),
49       * with provision for handling exceptions thrown by the business logic.
50       *
51       * @param mapping The ActionMapping used to select this instance
52       * @param form The optional ActionForm bean for this request (if any)
53       * @param request The HTTP request we are processing
54       * @param response The HTTP response we are creating
55       *
56       * @exception Exception if the application business logic throws
57       *  an exception
58       * @since Struts 1.1
59       */
60      public ActionForward execute(ActionMapping mapping,
61                                   ActionForm form,
62                                   HttpServletRequest request,
63                                   HttpServletResponse response)
64          throws Exception
65      {
66          response.setContentType("text/plain");
67          PrintWriter writer = response.getWriter();
68  
69          try {
70            ServletContext context = getServlet().getServletContext();
71              DefinitionsFactory factory = 
72                  TilesUtil.getDefinitionsFactory(request, context );
73              writer.println( factory.toString() );
74          } catch (Exception e) {
75              writer.println("FAIL - " + e.toString());
76              getServlet().log("ReloadAction", e);
77          }
78  
79          writer.flush();
80          writer.close();
81  
82          return (null);
83  
84      }
85  
86  }