View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2WebGui library.
13   *
14   *  The Initial Owner of the Original Code is Power Of Two S.R.L.
15   *  Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16   *  All Rights Reserved.
17   *
18   * Contributor(s):
19   */
20  
21  package com.pow2.webgui.tabbedselector;
22  
23  
24  import javax.servlet.http.*;
25  
26  
27  /***
28   *  Utility class for the TabbedSelector component.
29   *
30   * @author  Luca Fossato
31   * @created  03 July 2002
32   */
33  public class TabbedSelectorUtil
34  {
35    /***
36     *  Build the selectedTab parameter (the [key, value] couple)
37     *  for the tabbedSelector widget.
38     *  <br>
39     *  The selectedTab parameter value is take from the request object.
40     *
41     * @param  request            the request object
42     * @param  tabbedSelectorName the name of the tabbedSelector widget
43     * @return the selectedTab parameter
44     */
45    public static String getSelectedTabParam(HttpServletRequest request,
46                                             String tabbedSelectorName)
47    {
48      return getSelectedTabParam(tabbedSelectorName,
49                                  getSelectedTabParamValue(request, tabbedSelectorName));
50    }
51  
52  
53    /***
54     *  Build the selectedTab parameter (the [key, value] couple)
55     *  for the tabbedSelector widget.
56     *
57     * @param  tabbedSelectorName the name of the tabbedSelector widget
58     * @param  value              the value of the selectedTab parameter
59     * @return the selectedTab parameter
60     */
61    public static String getSelectedTabParam(String tabbedSelectorName,
62                                             String value)
63    {
64      String val = null;
65  
66      if ((val = getSelectedTabParamName(tabbedSelectorName)) != null)
67      {
68        val += "=";
69        val += value;
70      }
71  
72      return val;
73    }
74  
75  
76    /***
77     *  Get the the selectedTab parameter name for the tabbedSelector widget.
78     *
79     * @param  tabbedSelectorName the name of the tabbedSelector widget
80     * @return the selectedTab parameter name
81     */
82    public static String getSelectedTabParamName(String tabbedSelectorName)
83    {
84      if (tabbedSelectorName == null)
85        tabbedSelectorName = "";
86  
87      return new StringBuffer(Tab.FOLLOWUP_PARAMETER_PREFIX)
88                  .append(tabbedSelectorName)
89                  .append(Tab.FOLLOWUP_PARAMETER)
90                  .toString();
91    }
92  
93  
94    /***
95     *  Get the the selectedTab parameter value for the tabbedSelector widget.
96     *
97     * @param  request            the request object
98     * @param  tabbedSelectorName the name of the tabbedSelector widget
99     * @return the selectedTab parameter value
100    */
101   public static String getSelectedTabParamValue(HttpServletRequest request,
102                                                 String tabbedSelectorName)
103   {
104     String paramName  = getSelectedTabParamName(tabbedSelectorName);
105     String paramValue = null;
106 
107     if ((paramValue = (String)request.getAttribute(paramName)) == null)
108       paramValue = request.getParameter(paramName);
109 
110     return paramValue;
111   }
112 }