1 19 20 package com.lutris.airsent.business.sms; 21 22 import com.lutris.util.Config; 23 import com.lutris.util.KeywordValueTable; 24 import com.lutris.airsent.business.AirSentBusinessException; 25 import com.lutris.airsent.spec.sms.SMSManager; 26 27 34 public class SMSManagerImpl implements SMSManager { 35 36 37 protected final static String SMS_ACTIVE = "Active"; 38 protected final static String SMS_KEY = "SMS"; 39 protected final static String SMS_HOSTNAME = "Hostname"; 40 protected final static String SMS_PORT = "Port"; 41 protected final static String SMS_SYSID = "Sysid"; 42 protected final static String SMS_SYSTYPE = "Systype"; 43 protected final static String SMS_SYSPASSWORD = "Password"; 44 45 protected String smsServer = null; 46 protected String smsPort = null; 47 protected String smsSysid = null; 48 protected String smsSystype = null; 49 protected String smsSyspassword = null; 50 protected boolean active = false; 51 52 58 public SMSManagerImpl() {} 59 60 68 public SMSManagerImpl(Config config) throws AirSentBusinessException { 69 try { 70 KeywordValueTable section = config.getSection(SMS_KEY); 72 smsServer = section.getString(SMS_HOSTNAME); 73 smsPort = section.getString(SMS_PORT); 74 smsSysid = section.getString(SMS_SYSID); 75 smsSystype = section.getString(SMS_SYSTYPE); 76 smsSyspassword = section.getString(SMS_SYSPASSWORD); 77 active = Boolean.valueOf(section.getString(SMS_ACTIVE)).booleanValue(); 78 } catch (Exception ex) { 79 throw new AirSentBusinessException("Error sending mail:", ex); 80 } 81 } 82 83 84 98 public void send(String id, String body) throws AirSentBusinessException { 99 try { 100 if(active) { 101 SMS sms = new SMS(smsServer, smsPort, smsSysid, 102 smsSystype, smsSyspassword); 103 sms.sendMessage(id, body); 104 } else { 105 System.out.println("SMS is not active. Edit airSent.conf to activate."); 106 } 107 } catch (Exception ex) { 108 throw new AirSentBusinessException("Error sending SMS:", ex); 109 } 110 } 111 112 } 113 114 | Popular Tags |