Advertisement
Guest User

Skype URI Java

a guest
Aug 28th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.15 KB | None | 0 0
  1. package dragorn421;
  2.  
  3. import java.awt.Desktop;
  4. import java.io.IOException;
  5. import java.net.URI;
  6. import java.net.URISyntaxException;
  7. import java.nio.charset.Charset;
  8.  
  9. public class SkypeAPI
  10. {
  11.  
  12.     final static public String SKYPE_PROTOCOL = "skype:";
  13.     final static private Charset UTF_8_CHARSET = Charset.forName("UTF-8");
  14.  
  15.     private SkypeAPI() {}
  16.  
  17.     static public boolean runSkypeOrFocusIt()
  18.     {
  19.         return SkypeAPI.runURI(SkypeAPI.SKYPE_PROTOCOL + "?");
  20.     }
  21.  
  22.     static public boolean call(final String contact, final String... additionalContacts)
  23.     {
  24.         return SkypeAPI.call(false, contact, additionalContacts);
  25.     }
  26.  
  27.     static public boolean call(final boolean video, final String contact, final String... additionalContacts)
  28.     {
  29.         return SkypeAPI.callTopic(video, null, contact, additionalContacts);
  30.     }
  31.  
  32.     static public boolean callTopic(final String topicName, final String contact, final String... additionalContacts)
  33.     {
  34.         return SkypeAPI.callTopic(false, topicName, contact, additionalContacts);
  35.     }
  36.  
  37.     static public boolean callTopic(final boolean video, final String topicName, final String contact, final String... additionalContacts)
  38.     {
  39.         String contacts = contact;
  40.         for(final String c : additionalContacts)
  41.             contacts += (";" + c);
  42.         return SkypeAPI.runURI(SkypeAPI.SKYPE_PROTOCOL + contacts + "?call" + ((topicName==null)?(""):("&topic=" + SkypeAPI.escapeString(topicName))) + ((video)?("&video=true"):("")));
  43.     }
  44.  
  45.     static public boolean createGroup(final String contact, final String... additionalContacts)
  46.     {
  47.         return SkypeAPI.createGroupTopic(null, contact, additionalContacts);
  48.     }
  49.  
  50.     static public boolean createGroupTopic(final String topicName, final String contact, final String... additionalContacts)
  51.     {
  52.         String contacts = contact;
  53.         for(final String c : additionalContacts)
  54.             contacts += (";" + c);
  55.         return SkypeAPI.runURI(SkypeAPI.SKYPE_PROTOCOL + contacts + "?chat" +
  56.             ((topicName==null)?(""):("&topic=" + SkypeAPI.escapeString(topicName))));
  57.     }
  58.  
  59.     static public boolean runURI(final String uriS)
  60.     {
  61.         Swagg421.p(uriS);
  62.         URI uri;
  63.         try {
  64.             uri = new URI(uriS);
  65.         } catch (URISyntaxException e) {
  66.             e.printStackTrace();
  67.             return false;
  68.         }
  69.         try {
  70.             Desktop.getDesktop().browse(uri);
  71.         } catch (IOException e) {
  72.             e.printStackTrace();
  73.             return false;
  74.         }
  75.         return true;
  76.     }
  77.  
  78.     public static String escapeString(String s)
  79.     {
  80.         String hexa, es = "";
  81.         for(final byte b : s.getBytes(SkypeAPI.UTF_8_CHARSET))
  82.         {
  83.             if(Character.isLetterOrDigit(b))
  84.             {
  85.                 es += new String(new byte[]{b}, SkypeAPI.UTF_8_CHARSET);
  86.                 continue;
  87.             }
  88.             hexa = Integer.toString(b, 16);
  89.             if(hexa.length() == 1)
  90.                 hexa = ("0" + hexa);
  91.             es += ("%" + hexa);
  92.         }
  93.         return es;
  94.     }
  95.  
  96.     public static String unescapeString(String s)
  97.     {
  98.         final byte bytes[] = s.getBytes();
  99.         String es = "";
  100.         for(int i=0;i<bytes.length;i++)
  101.         {
  102.             if(bytes[i] == '%')
  103.             {
  104.                 es += new String(new byte[]{(byte) Integer.parseInt(new String(new byte[]{bytes[i+1], bytes[i+2]}, SkypeAPI.UTF_8_CHARSET), 16)}, SkypeAPI.UTF_8_CHARSET);
  105.                 i += 2;
  106.             }
  107.             else
  108.                 es += new String(new byte[]{bytes[i]}, SkypeAPI.UTF_8_CHARSET);
  109.         }
  110.         return es;
  111.     }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement