Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by Roberto Simoni ( 13 years ago )
package smsgateway.exampleclient;

import java.net.*;

public class SendMsgURIBuilder {

 private String baseUrl;
 private String to;
 private String text;
 
 private SendMsgURIBuilder() {
 }
 
 public static SendMsgURIBuilder aSendMsgURI() {
  return new SendMsgURIBuilder();
 }
 
 public SendMsgURIBuilder withBaseUrl(String baseurl) {
  this.baseUrl = baseurl;
  return this;
 }

 public SendMsgURIBuilder withTo(String to) {
  this.to = to;
  return this;
 }

 public SendMsgURIBuilder withText(String text) {
  this.text = text;
  return this;
 }

 public URI toURI() {
  if (baseUrl == null) throw new IllegalStateException("'baseUrl' parameter is mandatory");
  if (to == null) throw new IllegalStateException("'to' parameter is mandatory");
  if (text == null) throw new IllegalStateException("'text' parameter is mandatory");
  
  StringBuilder builder = new StringBuilder(baseUrl);
  if (! baseUrl.endsWith("/"))
   builder.append("/");
  
  // NOTA: e' evidente da alcune verfiche che l'encoding CP1252 e' il piu' vicino
  //       a quello utilizzato poi da clickatell
  try {
   String urlAsText = builder.append("send_msg.htm?to=")
    .append(to)
    .append("&text;=")
    .append(URLEncoder.encode(text, "CP1252"))
    .toString();
   return new URI(urlAsText);
  } catch (Throwable t) {
   throw new RuntimeException("unexpected error", t);
  }
 }
 
}

 

Revise this Paste

Your Name: Code Language: