# HG changeset patch # User e085711 # Date 1318355533 -32400 # Node ID 1fdee3cb0908b45ec5d5ce13ef8c6458e1faa6e1 # Parent 29ec6fbcb079d29b4eee0a554c2f7dc304ba4e2d remove myVncProxy.XmlRpc.java diff -r 29ec6fbcb079 -r 1fdee3cb0908 src/myVncProxy/XmlRpc.java --- a/src/myVncProxy/XmlRpc.java Wed Oct 12 02:50:07 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -package myVncProxy; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; - -public class XmlRpc { - static final String META_WEBLOG_NEW_POST = "metaWeblog.newPost"; - static final String META_WEBLOG_EDIT_POST = "metaWeblog.editPost"; - static final String META_WEBLOG_GET_POST = "metaWeblog.getPost"; - - XmlRpcClient client; - XmlRpcClientConfigImpl config; - - String loginId, pw, postUrl; - String blogId; - String title = ""; - String description = ""; - ArrayList categories = new ArrayList(); - - XmlRpc(String blogId, String loginId, String pw, String url) throws MalformedURLException { - this.blogId = blogId; - this.loginId = loginId; - this.pw = pw; - postUrl = checkUrl(url); - client = createClient(postUrl); - } - String checkUrl(String url) { - String str; - if(url.endsWith("xmlrpc.php")){ - return url; - } else if(url.endsWith("/")) { - str = url + "xmlrpc.php"; - } else { - str = url + "/xmlrpc.php"; - } - return str; - } - XmlRpcClient createClient(String url) throws MalformedURLException { - config = new XmlRpcClientConfigImpl(); - config.setServerURL(new URL(url.trim())); - - XmlRpcClient c = new XmlRpcClient(); - c.setConfig(config); - - return c; - } - - String newPost() { - String result = post(META_WEBLOG_NEW_POST); - blogId = result; - return result; - } - String editPost() { - return post(META_WEBLOG_EDIT_POST); - } - - String post(String API) { - - String result = ""; - - Map contentParam = buildContent(); - List params = buildParam(contentParam); - - Object o = null; - try { - o = client.execute(API, params); - result = o.toString(); - } catch (XmlRpcException e) { - e.printStackTrace(); - } - return result; - } - - - protected void setTitle(String str) { - this.title = str; - } - protected void setDescription(String str) { - this.description = str; - } - protected void addDescription(String str) { - this.description += str; - } - protected void setCategories(String[] str) { - for(int i = 0; i < str.length; i ++) - categories.add(str[i]); - } - protected void addCategories(String str) { - categories.add(str); - } - - protected Map buildContent() { - Map content = new HashMap(); - - description = description.replaceAll("\n", "
"); - content.put("title", title); - content.put("categories", categories.toArray()); - content.put("description", description); - content.put("dateCreated", ""); - content.put("wp_slug", ""); - - return content; - } - - protected List buildParam(Map contentParam) { - List params = new ArrayList(); - - params.add(""); // appkey - params.add(blogId); - params.add(loginId); - params.add(pw); - params.add(contentParam);// content - params.add("1");// publish - - return params; - } - - String getUrl() { - List params = new ArrayList(); - - params.add(blogId); - params.add(loginId); - params.add(pw); - - Object result = null; - String str = "false"; - try { - result = weblog(params, META_WEBLOG_GET_POST); - Map map = (HashMap) result; - str = (String) map.get("link"); - } catch (XmlRpcException e) { - e.printStackTrace(); - } - return str; - } - - Object weblog(List params, String API) throws XmlRpcException { - Object o = null; - o = client.execute(API, params); - return o; - } - - public static void main(String[] args){ - if (args.length < 2) { - System.out.println("usage: program username password "); - System.exit(0); - } - String username = args[0]; - String password = args[1]; - - String blogId = "77"; -// String url = "http://single.cr.ie.u-ryukyu.ac.jp/wordpress/xmlrpc.php"; -// String url = "http://single.cr.ie.u-ryukyu.ac.jp/wordpress/"; - String url = "http://single.cr.ie.u-ryukyu.ac.jp/wordpress"; - - XmlRpc rpc; - try { - rpc = new XmlRpc(blogId, username, password, url ); - rpc.setTitle("xml-rpcを用いての投稿 @ java"); - rpc.setDescription("java からの投稿\nテスト\n"); - rpc.addDescription("addDescription()\n"); - rpc.addCategories("XML-RPC"); - - String res = rpc.newPost(); -// String res = rpc.editPost(); - String res2 = rpc.getUrl(); - System.out.println(res); - System.out.println(res2); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - } - -}