KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > tiles > skin > LayoutSettingsAction


1 /*
2  * $Id: LayoutSettingsAction.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.skin;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.apache.struts.tiles.ComponentContext;
27 import org.apache.struts.tiles.actions.TilesAction;
28
29 /**
30  * Action used to set user skin.
31  */

32 public class LayoutSettingsAction extends TilesAction
33 {
34       /** debug flag */
35     public static boolean debug = true;
36
37     /**
38      * Process the specified HTTP request, and create the corresponding HTTP
39      * response (or forward to another web component that will create it).
40      * Return an <code>ActionForward</code> instance describing where and how
41      * control should be forwarded, or <code>null</code> if the response has
42      * already been completed.
43      * This method should be implemented by subclasses.
44      *
45      * @param context The current Tile context, containing Tile attributes.
46      * @param mapping The ActionMapping used to select this instance.
47      * @param form The optional ActionForm bean for this request (if any).
48      * @param request The HTTP request we are processing.
49      * @param response The HTTP response we are creating.
50      *
51      * @exception Exception if the application business logic throws
52      * an exception
53      * @since Struts 1.1
54      */

55     public ActionForward execute(
56         ComponentContext context,
57         ActionMapping mapping,
58         ActionForm form,
59         HttpServletRequest JavaDoc request,
60         HttpServletResponse JavaDoc response)
61         throws Exception JavaDoc
62    {
63     if(debug)
64       System.out.println("Enter action LayoutSettingAction");
65
66     LayoutSettingsForm actionForm = (LayoutSettingsForm)form;
67
68         // Load user menu settings and available list of choices
69
String JavaDoc selected = LayoutSwitchAction.getUserSetting( context, request );
70     if(selected==null)
71       selected = "default";
72     System.out.println("user setting retrieved");
73     DefinitionCatalog catalog = LayoutSwitchAction.getCatalog( context, request, getServlet().getServletContext() );
74     System.out.println("catalog retrieved");
75
76       // Check if form is submitted
77
// If true, read, check and store new values submitted by user.
78
if( actionForm.isSubmitted() )
79       { // read arrays
80
if(debug)
81         System.out.println("form submitted");
82       selected = catalog.getKey(actionForm.getSelected());
83       if(debug)
84         System.out.println( "key : " + selected );
85       LayoutSwitchAction.setUserSetting(context, request, selected );
86       if(debug)
87         System.out.println( "settings : " + selected );
88       actionForm.reset();
89       } // end if
90

91       // Prepare data for view tile
92
context.putAttribute( "selected", selected );
93     context.putAttribute( "catalog", catalog );
94
95     if(debug)
96       System.out.println("Exit action LayoutSettingAction");
97     return null;
98    }
99 }
100
Popular Tags