1 5 package org.exoplatform.services.communication.sms.provider.prodat; 6 7 import java.util.Iterator ; 8 import org.exoplatform.services.communication.sms.common.ConvertException; 9 import org.exoplatform.services.communication.sms.common.RequestException; 10 import org.exoplatform.services.communication.sms.encoder.Formatter; 11 import org.exoplatform.services.communication.sms.encoder.Resolver; 12 import org.exoplatform.services.communication.sms.model.*; 13 import org.exoplatform.services.communication.sms.provider.*; 14 import org.exoplatform.services.communication.sms.util.SmsUtil; 15 16 17 18 22 public class ProdatRequestImpl implements SmsRequest { 23 24 private Provider _provider; 25 private Messages _messages; 26 private String _payload; 27 28 public ProdatRequestImpl(Provider provider) { 29 _provider = provider; 30 } 31 32 35 public Messages getMessages() { 36 return _messages; 37 } 38 39 42 public void setMessages(Messages messages) { 43 _messages = messages; 44 } 45 46 49 public String getPayload() { 50 return _payload; 51 } 52 53 56 public void setPayload(String payload) { 57 _payload = payload; 58 } 59 60 64 public void prepare() throws RequestException, ConvertException { 65 Operator operator = _provider.getOperator(); 66 StringBuffer buffer = new StringBuffer (); 67 buffer.append("<?xml version=\"1.0\" encoding=\""+_messages.getEncoding()+"\"?>\n"); 68 buffer.append("<!DOCTYPE SESSION SYSTEM \"pswincom_submit.dtd\">\n"); 69 buffer.append("<SESSION>\n"); 70 buffer.append("<CLIENT>" + operator.getUsername() + "</CLIENT>\n"); 71 buffer.append("<PW>" + operator.getPassword() + "</PW>\n"); 72 buffer.append("<AP>eXo</AP>\n"); 73 buffer.append("<MSGLST>\n"); 75 for(Iterator i = _messages.iterator(); i.hasNext(); ) { 76 Message message = (Message) i.next(); 77 String text = message.getContent().toString(); 78 Resolver resolver = _provider.getResolver(); 79 Formatter formatter = resolver.getFormatter(message.getFormat()); 80 text = (String ) formatter.convert(text); 81 Integer op = (Integer )resolver.getOperationCode(message.getFormat()); 82 for(Iterator j = message.getRecipients().iterator(); j.hasNext(); ) { 83 Recipient recipient = (Recipient) j.next(); 84 String from = message.getFrom(); 85 if (!SmsUtil.isAlpha(from) || SmsUtil.hasMobileNumberPrefix(from)) 87 from = SmsUtil.prepareCellularNumber(from); 88 buffer.append("<MSG>\n"); 89 buffer.append("<ID>" + recipient.getId() + "</ID>\n"); 90 buffer.append("<TEXT>" + text + "</TEXT>\n"); 91 buffer.append("<RCV>" + SmsUtil.prepareCellularNumber(recipient.getTo()) + "</RCV>\n"); 92 buffer.append("<SND>" + from + "</SND>\n"); 93 buffer.append("<OP>" + op.toString() + "</OP>\n"); 94 buffer.append("</MSG>\n"); 95 recipient.setStatus(MessageStatus.PENDING); 96 } 97 } 98 buffer.append("</MSGLST>\n"); 99 buffer.append("</SESSION>\n"); 100 _payload = buffer.toString(); 101 } 102 103 } 104 | Popular Tags |