diff options
Diffstat (limited to 'client/trunk/src/com/fourisland/instadisc/XmlRpc.java')
| -rw-r--r-- | client/trunk/src/com/fourisland/instadisc/XmlRpc.java | 84 |
1 files changed, 84 insertions, 0 deletions
| diff --git a/client/trunk/src/com/fourisland/instadisc/XmlRpc.java b/client/trunk/src/com/fourisland/instadisc/XmlRpc.java new file mode 100644 index 0000000..8c22155 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/XmlRpc.java | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | package com.fourisland.instadisc; | ||
| 6 | |||
| 7 | import com.fourisland.instadisc.Database.Wrapper; | ||
| 8 | import com.fourisland.instadisc.Item.Verification; | ||
| 9 | import java.net.MalformedURLException; | ||
| 10 | import java.net.URL; | ||
| 11 | import java.util.logging.Level; | ||
| 12 | import java.util.logging.Logger; | ||
| 13 | import org.apache.xmlrpc.XmlRpcException; | ||
| 14 | import org.apache.xmlrpc.client.XmlRpcClient; | ||
| 15 | import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * | ||
| 19 | * @author hatkirby | ||
| 20 | */ | ||
| 21 | public class XmlRpc { | ||
| 22 | |||
| 23 | private String function; | ||
| 24 | private Object[] params; | ||
| 25 | private int step = 3; | ||
| 26 | private String url = ""; | ||
| 27 | |||
| 28 | public XmlRpc(String function) { | ||
| 29 | this.function = function; | ||
| 30 | if (url.equals("")) | ||
| 31 | { | ||
| 32 | url = Wrapper.getConfig("centralServerURL"); | ||
| 33 | } | ||
| 34 | |||
| 35 | Verification ver = new Verification(); | ||
| 36 | params = new Object[3]; | ||
| 37 | params[0] = ver.getUsername(); | ||
| 38 | params[1] = ver.getHash(); | ||
| 39 | params[2] = ver.getID(); | ||
| 40 | } | ||
| 41 | |||
| 42 | public XmlRpc(String function, String url, String username, String password) | ||
| 43 | { | ||
| 44 | this.function = function; | ||
| 45 | this.url = url; | ||
| 46 | |||
| 47 | Verification ver = new Verification(username, password); | ||
| 48 | params = new Object[3]; | ||
| 49 | params[0] = ver.getUsername(); | ||
| 50 | params[1] = ver.getHash(); | ||
| 51 | params[2] = ver.getID(); | ||
| 52 | } | ||
| 53 | |||
| 54 | public void addParam(Object param) | ||
| 55 | { | ||
| 56 | Object oldParams[] = params; | ||
| 57 | Object temp[] = new Object[step+1]; | ||
| 58 | int i=0; | ||
| 59 | for (i=0;i<step;i++) | ||
| 60 | { | ||
| 61 | temp[i] = oldParams[i]; | ||
| 62 | } | ||
| 63 | temp[step] = param; | ||
| 64 | step++; | ||
| 65 | params = temp; | ||
| 66 | } | ||
| 67 | |||
| 68 | public Object execute() { | ||
| 69 | Object result = null; | ||
| 70 | try { | ||
| 71 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); | ||
| 72 | config.setServerURL(new URL(url)); | ||
| 73 | XmlRpcClient client = new XmlRpcClient(); | ||
| 74 | client.setConfig(config); | ||
| 75 | |||
| 76 | result = client.execute("InstaDisc." + function, params); | ||
| 77 | } catch (XmlRpcException ex) { | ||
| 78 | Logger.getLogger(InstaDiscApp.class.getName()).log(Level.SEVERE, null, ex); | ||
| 79 | } catch (MalformedURLException ex) { | ||
| 80 | Logger.getLogger(InstaDiscApp.class.getName()).log(Level.SEVERE, null, ex); | ||
| 81 | } | ||
| 82 | return result; | ||
| 83 | } | ||
| 84 | } | ||
