1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
77 if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
78 int index = name.indexOf('?');
79 if (index>-1) {
80 scope = PortletSession.PORTLET_SCOPE;
81 }
82 }
83 return scope;
84 }
85 }
86
87