View Javadoc

1   /*
2    * Copyright 2003,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * This source code implements specifications defined by the Java
18   * Community Process. In order to remain compliant with the specification
19   * DO NOT add / change / or delete method signatures!
20   */
21  package javax.portlet;
22  
23  /***
24   * The <CODE>PortletSessionUtil</CODE>  class helps identify and decode
25   * attributes in the <CODE>PORTLET_SCOPE</CODE> scope of the PortletSession
26   * when accessed through the HttpSession an from within calls to methods
27   * of the HttpSessionBindingListener interface.
28   */
29  public class PortletSessionUtil
30  {
31  
32  
33    private static final String PORTLET_SCOPE_NAMESPACE = "javax.portlet.p.";
34    
35    /***
36     * Returns the attribute name of an attribute in the 
37     * <code>PORTLET_SCOPE</code>. If the attribute is in the
38     * <code>APPLICATION_SCOPE</code> it returns the attribute name unchanged.
39     *
40     * @param name		a string specifying the name of the
41     *                            encoded portlet attribute
42     *
43     * @return			the decoded attribute name
44     */
45  
46    public static java.lang.String decodeAttributeName(java.lang.String name)
47    {
48      if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
49        int index = name.indexOf('?');
50        if (index>-1) {
51  	name = name.substring(index+1);
52        }
53      }
54      return name;
55    }
56  
57  
58    /***
59     * Returns the portlet attribute scope from an encoded portlet
60     * attribute.
61     * <br>Possible return values are:
62     * <ul>
63     * <li><code>PortletSession.APPLICATION_SCOPE</code></li>
64     * <li><code>PortletSession.PORTLET_SCOPE</code></li>
65     * </ul>
66     *
67     * @param name		a string specifying the name of the
68     *                            encoded portlet attribute
69     *
70     * @return			the decoded attribute scope
71     * @see PortletSession
72     */
73  
74    public static int decodeScope(java.lang.String name)
75    {
76      int scope = PortletSession.APPLICATION_SCOPE; // APP
77      if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
78        int index = name.indexOf('?');
79        if (index>-1) {
80  	scope = PortletSession.PORTLET_SCOPE; // PORTLET
81        }
82      }
83      return scope;
84    }
85  }
86  
87