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: *
25: * @return the decoded attribute name
26: */
27:
28: public static java.lang.String decodeAttributeName(
29: java.lang.String name) {
30: if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
31: int index = name.indexOf('?');
32: if (index > -1) {
33: name = name.substring(index + 1);
34: }
35: }
36: return name;
37: }
38:
39: /**
40: * Returns the portlet attribute scope from an encoded portlet
41: * attribute.
42: * <br>Possible return values are:
43: * <ul>
44: * <li><code>PortletSession.APPLICATION_SCOPE</code></li>
45: * <li><code>PortletSession.PORTLET_SCOPE</code></li>
46: * </ul>
47: *
48: * @param name a string specifying the name of the
49: * encoded portlet attribute
50: *
51: * @return the decoded attribute scope
52: * @see PortletSession
53: */
54:
55: public static int decodeScope(java.lang.String name) {
56: int scope = PortletSession.APPLICATION_SCOPE; // APP
57: if (name.startsWith(PORTLET_SCOPE_NAMESPACE)) {
58: int index = name.indexOf('?');
59: if (index > -1) {
60: scope = PortletSession.PORTLET_SCOPE; // PORTLET
61: }
62: }
63: return scope;
64: }
65: }
|