KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > tiles > test > TestActionTileAction


1 /*
2  * $Id: TestActionTileAction.java 54929 2004-10-16 16:38:42Z germuska $
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 package org.apache.struts.webapp.tiles.test;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import org.apache.struts.action.Action;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.tiles.ComponentContext;
28 import org.apache.struts.tiles.ComponentDefinition;
29 import org.apache.struts.tiles.DefinitionsFactoryException;
30 import org.apache.struts.tiles.DefinitionsUtil;
31 import org.apache.struts.tiles.FactoryNotFoundException;
32 import org.apache.struts.tiles.NoSuchDefinitionException;
33
34
35 /**
36  * Implementation of <strong>Action</strong> that populates an instance of
37  * <code>SubscriptionForm</code> from the currently specified subscription.
38  *
39  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
40  */

41
42 public final class TestActionTileAction extends Action {
43
44
45     // --------------------------------------------------------- Public Methods
46

47
48     /**
49      * Process the specified HTTP request, and create the corresponding HTTP
50      * response (or forward to another web component that will create it).
51      * Return an <code>ActionForward</code> instance describing where and how
52      * control should be forwarded, or <code>null</code> if the response has
53      * already been completed.
54      *
55      * @param mapping The ActionMapping used to select this instance
56      * @param actionForm 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      */

63     public ActionForward execute(
64                  ActionMapping mapping,
65                  ActionForm form,
66                  HttpServletRequest JavaDoc request,
67                  HttpServletResponse JavaDoc response)
68     throws Exception JavaDoc {
69
70       // Try to retrieve tile context
71
ComponentContext context = ComponentContext.getContext( request );
72     if( context == null )
73       {
74       request.setAttribute( "actionError", "Can't get component context.");
75       return (mapping.findForward("failure"));
76       }
77       // Get requested test from tile parameter
78
String JavaDoc param;
79
80       // Set a definition in this action
81
param = (String JavaDoc)context.getAttribute( "set-definition-name" );
82     if( param != null )
83       {
84       try
85         {
86           // Read definition from factory, but we can create it here.
87
ComponentDefinition definition = DefinitionsUtil.getDefinition( param, request, getServlet().getServletContext() );
88         //definition.putAttribute( "attributeName", "aValue" );
89
DefinitionsUtil.setActionDefinition( request, definition);
90         }
91        catch( FactoryNotFoundException ex )
92         {
93         request.setAttribute( "actionError", "Can't get definition factory.");
94         return (mapping.findForward("failure"));
95         }
96        catch( NoSuchDefinitionException ex )
97         {
98         request.setAttribute( "actionError", "Can't get definition '" + param +"'.");
99         return (mapping.findForward("failure"));
100         }
101        catch( DefinitionsFactoryException ex )
102         {
103         request.setAttribute( "actionError", "General error '" + ex.getMessage() +"'.");
104         return (mapping.findForward("failure"));
105         }
106       }
107
108       // Overload a parameter
109
param = (String JavaDoc)context.getAttribute( "set-attribute" );
110     if( param != null )
111       {
112       context.putAttribute( param, context.getAttribute( "set-attribute-value" ));
113       } // end if
114

115       return (mapping.findForward("success"));
116
117     }
118
119
120 }
121
Popular Tags