KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > portlet > PortletSessionUtil


1 /**
2   * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
3   * All rights reserved.
4   * Use is subject to license terms.
5   */

6
7 package javax.portlet;
8
9 /**
10  * The <CODE>PortletSessionUtil</CODE> class helps identify and decode
11  * attributes in the <CODE>PORTLET_SCOPE</CODE> scope of the PortletSession
12  * when accessed through the HttpSession an from within calls to methods
13  * of the HttpSessionBindingListener interface.
14  */

15 public class PortletSessionUtil
16 {
17
18   private static final String JavaDoc PORTLET_SCOPE_NAMESPACE = "javax.portlet.p.";
19   
20   /**
21    * Returns the attribute name of an attribute in the
22    * <code>PORTLET_SCOPE</code>. If the attribute is in the
23    * <code>APPLICATION_SCOPE</code> it returns the attribute name unchanged.
24    *
25    * @param name a string specifying the name of the
26    * encoded portlet attribute
27    *
28    * @return the decoded attribute name
29    */

30
31   public static java.lang.String JavaDoc decodeAttributeName(java.lang.String JavaDoc name)
32   {
33     if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
34       int index = name.indexOf('?');
35       if (index>-1) {
36     name = name.substring(index+1);
37       }
38     }
39     return name;
40   }
41
42
43   /**
44    * Returns the portlet attribute scope from an encoded portlet
45    * attribute.
46    * <br>Possible return values are:
47    * <ul>
48    * <li><code>PortletSession.APPLICATION_SCOPE</code></li>
49    * <li><code>PortletSession.PORTLET_SCOPE</code></li>
50    * </ul>
51    *
52    * @param name a string specifying the name of the
53    * encoded portlet attribute
54    *
55    * @return the decoded attribute scope
56    * @see PortletSession
57    */

58
59   public static int decodeScope(java.lang.String JavaDoc name)
60   {
61     int scope = PortletSession.APPLICATION_SCOPE; // APP
62
if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
63       int index = name.indexOf('?');
64       if (index>-1) {
65     scope = PortletSession.PORTLET_SCOPE; // PORTLET
66
}
67     }
68     return scope;
69   }
70 }
71
72
73
Popular Tags