1 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 20 public class SmsPortletUtil { 21 public static final String PREF_USERNAME = "gatewayUsername"; 22 public static final String PREF_PASSWORD = "gatewayPassword"; 23 public static String 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 uid = prefs.getValue(PREF_USERNAME, ""); 33 String 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 |