KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > sms > util > SmsPortletUtil


1 /**
2  * Copyright 2001-2004 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.portlets.communication.sms.util;
6
7 import javax.faces.context.FacesContext;
8 import javax.portlet.PortletPreferences;
9 import javax.portlet.PortletRequest;
10 import javax.portlet.PortletSession;
11 import org.exoplatform.services.communication.sms.SmsService;
12 import org.exoplatform.services.communication.sms.provider.Provider;
13
14
15
16 /**
17  * @author Ove Ranheim (oranheim@yahoo.no)
18  * @since Jun 22, 2004 4:14:49 PM
19  */

20 public class SmsPortletUtil {
21     public static final String JavaDoc PREF_USERNAME = "gatewayUsername";
22     public static final String JavaDoc PREF_PASSWORD = "gatewayPassword";
23     public static String JavaDoc SMS_PROVIDER = "SMS_PROVIDER";
24
25     public static Provider getProvider(SmsService service) {
26         FacesContext context = FacesContext.getCurrentInstance();
27         PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
28         PortletSession session = request.getPortletSession();
29         Provider provider = (Provider) session.getAttribute(SMS_PROVIDER);
30         if (provider == null) {
31             PortletPreferences prefs = request.getPreferences();
32             String JavaDoc uid = prefs.getValue(PREF_USERNAME, "");
33             String JavaDoc pwd = prefs.getValue(PREF_PASSWORD, "");
34             provider = service.createProdatProvider(uid, pwd);
35             session.setAttribute(SMS_PROVIDER, provider);
36         }
37         return provider;
38     }
39
40     
41 }
42
Popular Tags