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.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 private static final long serialVersionUID = -5469130834431018931L; 49 50 /** 51 * Process the specified HTTP request, and create the corresponding HTTP 52 * response (or forward to another web component that will create it), 53 * with provision for handling exceptions thrown by the business logic. 54 * 55 * @param mapping The ActionMapping used to select this instance 56 * @param form The optional ActionForm bean for this request (if any) 57 * @param request The HTTP request we are processing 58 * @param response The HTTP response we are creating 59 * 60 * @exception Exception if the application business logic throws 61 * an exception 62 * @since Struts 1.1 63 */ 64 public ActionForward execute(ActionMapping mapping, 65 ActionForm form, 66 HttpServletRequest request, 67 HttpServletResponse response) 68 throws Exception 69 { 70 response.setContentType("text/plain"); 71 PrintWriter writer = response.getWriter(); 72 73 try { 74 ServletContext context = getServlet().getServletContext(); 75 DefinitionsFactory factory = 76 TilesUtil.getDefinitionsFactory(request, context ); 77 writer.println( factory.toString() ); 78 } catch (Exception e) { 79 writer.println("FAIL - " + e.toString()); 80 getServlet().log("ReloadAction", e); 81 } 82 83 writer.flush(); 84 85 return (null); 86 } 87 }