KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > portletAPIImp > helpers > SharedSessionUtil


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  *
5  * Created on 1 d�c. 2003
6  */

7 package org.exoplatform.services.portletcontainer.impl.portletAPIImp.helpers;
8
9
10 /**
11  * To simulate independant PortletSession objects for every portlet application,
12  * we partitionnate a single Http Session object wit the following convention :
13  * portletApplicationId.data?attributeName
14  * portletApplicationId.metaData?attributeName
15  *
16  * @author Mestrallet Benjamin
17  * benjmestrallet@users.sourceforge.net
18  */

19 public class SharedSessionUtil {
20
21   private static final char SEPARATOR = '$';
22
23   public static String JavaDoc encodePortletSessionAttribute(String JavaDoc portletApplicationId,
24                                                      String JavaDoc attributeName) {
25     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
26     sB.append(portletApplicationId);
27     sB.append(".data");
28     sB.append(SEPARATOR);
29     sB.append(attributeName);
30     return sB.toString();
31   }
32
33   public static String JavaDoc encodePortletSessionMetaDataAttribute(String JavaDoc portletApplicationId,
34                                                              String JavaDoc attributeName) {
35     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
36     sB.append(portletApplicationId);
37     sB.append(".metaData");
38     sB.append(SEPARATOR);
39     sB.append(attributeName);
40     return sB.toString();
41   }
42
43   public static String JavaDoc decodePortletSessionMetaDataAttribute(String JavaDoc portletApplicationId,
44                                                              String JavaDoc attributeName) {
45     if (attributeName.startsWith(portletApplicationId + ".metaData" + SEPARATOR)) {
46       int index = attributeName.indexOf(SEPARATOR);
47       if (index > -1) {
48         attributeName = attributeName.substring(index + 1);
49       }
50     }
51     return attributeName;
52   }
53
54   public static boolean isMetaDataAttribute(String JavaDoc portletApplicationId,
55                                             String JavaDoc attributeName) {
56     if (attributeName.startsWith(portletApplicationId + ".metaData" + SEPARATOR))
57       return true;
58     else
59       return false;
60   }
61
62   public static String JavaDoc decodePortletSessionAttribute(String JavaDoc portletApplicationId,
63                                                      String JavaDoc attributeName) {
64     if (attributeName.startsWith(portletApplicationId + ".data" + SEPARATOR)) {
65       int index = attributeName.indexOf(SEPARATOR);
66       if (index > -1) {
67         attributeName = attributeName.substring(index + 1);
68       }
69     }
70     return attributeName;
71   }
72
73   public static boolean isAttribute(String JavaDoc portletApplicationId, String JavaDoc s) {
74     if (s.startsWith(portletApplicationId + ".data" + SEPARATOR))
75       return true;
76     else
77       return false;
78   }
79   
80
81 }
82
Popular Tags