01: /**
02: * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
03: * All rights reserved.
04: * Use is subject to license terms.
05: */package javax.portlet;
06:
07: /**
08: * The <CODE>PortletSessionUtil</CODE> class helps identify and decode
09: * attributes in the <CODE>PORTLET_SCOPE</CODE> scope of the PortletSession
10: * when accessed through the HttpSession an from within calls to methods
11: * of the HttpSessionBindingListener interface.
12: */
13: public class PortletSessionUtil {
14:
15: private static final String PORTLET_SCOPE_NAMESPACE = "javax.portlet.p.";
16:
17: /**
18: * Returns the attribute name of an attribute in the
19: * <code>PORTLET_SCOPE</code>. If the attribute is in the
20: * <code>APPLICATION_SCOPE</code> it returns the attribute name unchanged.
21: *
22: * @param name a string specifying the name of the
23: * encoded portlet attribute
24: * @return the decoded attribute name
25: */
26:
27: public static java.lang.String decodeAttributeName(
28: java.lang.String name) {
29: if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
30: int index = name.indexOf('?');
31: if (index > -1) {
32: name = name.substring(index + 1);
33: }
34: }
35: return name;
36: }
37:
38: /**
39: * Returns the portlet attribute scope from an encoded portlet
40: * attribute.
41: * <br>Possible return values are:
42: * <ul>
43: * <li><code>PortletSession.APPLICATION_SCOPE</code></li>
44: * <li><code>PortletSession.PORTLET_SCOPE</code></li>
45: * </ul>
46: *
47: * @param name a string specifying the name of the
48: * encoded portlet attribute
49: * @return the decoded attribute scope
50: * @see PortletSession
51: */
52:
53: public static int decodeScope(java.lang.String name) {
54: int scope = PortletSession.APPLICATION_SCOPE; // APP
55: if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
56: int index = name.indexOf('?');
57: if (index > -1) {
58: scope = PortletSession.PORTLET_SCOPE; // PORTLET
59: }
60: }
61: return scope;
62: }
63: }
|