KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > communication > sms > provider > prodat > ProdatRequestImpl


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.services.communication.sms.provider.prodat;
6
7 import java.util.Iterator JavaDoc;
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 /**
19  * @author Ove Ranheim (oranheim@yahoo.no)
20  * @since Jun 17, 2004 9:39:05 PM
21  */

22 public class ProdatRequestImpl implements SmsRequest {
23
24     private Provider _provider;
25     private Messages _messages;
26     private String JavaDoc _payload;
27     
28     public ProdatRequestImpl(Provider provider) {
29         _provider = provider;
30     }
31
32     /**
33      * @return Returns the messages.
34      */

35     public Messages getMessages() {
36         return _messages;
37     }
38
39     /**
40      * @param messages The messages to set.
41      */

42     public void setMessages(Messages messages) {
43         _messages = messages;
44     }
45
46     /**
47      * @return Returns the payload.
48      */

49     public String JavaDoc getPayload() {
50         return _payload;
51     }
52
53     /**
54      * @param payload The payload to set.
55      */

56     public void setPayload(String JavaDoc payload) {
57         _payload = payload;
58     }
59
60     /*
61      * @see org.exoplatform.services.communication.sms.provider.SenderImpl#prepare(Messages messages)
62      * @see org.exoplatform.services.communication.sms.provider.SmsRequest#prepare()
63      */

64     public void prepare() throws RequestException, ConvertException {
65         Operator operator = _provider.getOperator();
66         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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("<SD></SD>\n"); // Session Data Code
74
buffer.append("<MSGLST>\n");
75         for(Iterator JavaDoc i = _messages.iterator(); i.hasNext(); ) {
76             Message message = (Message) i.next();
77             String JavaDoc text = message.getContent().toString();
78             Resolver resolver = _provider.getResolver();
79             Formatter formatter = resolver.getFormatter(message.getFormat());
80             text = (String JavaDoc) formatter.convert(text);
81             Integer JavaDoc op = (Integer JavaDoc)resolver.getOperationCode(message.getFormat());
82             for(Iterator JavaDoc j = message.getRecipients().iterator(); j.hasNext(); ) {
83                 Recipient recipient = (Recipient) j.next();
84                 String JavaDoc from = message.getFrom();
85                 // Only consider numbers with + and 00 prefix and non alpha numbers as real number
86
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