changeset 160:29ec6fbcb079

remove test.XmlRpc.java test.XMLRpcTest.java
author e085711
date Wed, 12 Oct 2011 02:50:07 +0900
parents 99747d2cb4cd
children 1fdee3cb0908
files src/test/XMLRPCTest.java src/test/XmlRpc.java
diffstat 2 files changed, 0 insertions(+), 360 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/XMLRPCTest.java	Wed Oct 12 02:47:47 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-package test;
-
-import java.io.IOException;
-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 XMLRPCTest {
-	protected static final String META_WEBLOG_NEW_POST = "metaWeblog.newPost";
-	protected static final String META_WEBLOG_EDIT_POST = "metaWeblog.editPost";
-	
-	public String getBlogid(String username,String password, String url) throws Exception {
-
-		XmlRpcClient client = createClient(url);
-
-		List<Object> params = new ArrayList<Object>();
-		params.add("77"); 
-		params.add(username);
-		params.add(password);
-
-//		Object result = client.execute("blogger.getUsersBlogs", params);
-		Object result = client.execute("metaWeblog.getPost", params);
-		
-		if (result instanceof Boolean) {
-			throw new Exception("can't get UsersBlogs");
-		}
-		
-//		Object obj = ((Object[])result)[0];
-//		Map map = (HashMap) obj;		
-//		String blogid = (String) map.get("blogid");
-//		return blogid;
-
-		Map map = (HashMap) result;
-		String s = String.valueOf(map.get("description"));
-		return s;
-	}
-
-	public int post(String title, String description, String blogId,
-			String loginId, String pw, String url) throws IOException {
-		int ret = -1;
-
-		// 記事を作る
-		// 必要に応じてカスタムフィールドやslugの引数も追加。
-		Map<String, Object> contentParam = buildContent(title, description);
-		// パラメータとして記事を渡す。
-		List<Object> params = buildParam(blogId, loginId, pw, contentParam);
-
-		// クライアント作る
-		XmlRpcClient client = createClient(url);
-		Object o = null;
-		try {
-			// 送信
-			o = client.execute(META_WEBLOG_NEW_POST, params);
-			ret = Integer.parseInt(o.toString());
-		} catch (XmlRpcException e) {
-			e.printStackTrace();
-		}
-		return ret; // 成功なら1
-	}
-
-	public String edit(String title, String description, String blogId,
-			String loginId, String pw, String url) throws IOException {
-		String result = "";
-
-		Map<String, Object> contentParam = buildContent(title, description);
-		List<Object> params = buildParam(blogId, loginId, pw, contentParam);
-
-		XmlRpcClient client = createClient(url);
-		Object o = null;
-		try {
-			o = client.execute(META_WEBLOG_EDIT_POST, params);
-			result = o.toString();
-		} catch (XmlRpcException e) {
-			e.printStackTrace();
-		}
-		return result; // 成功ならtrue
-	}
-
-	
-	/**
-	 * XmlRpcClientをインスタンス化する
-	 * 
-	 * @param postUrl
-	 * @return
-	 * @throws MalformedURLException
-	 */
-	protected XmlRpcClient createClient(String postUrl)
-			throws MalformedURLException {
-		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
-
-		config.setServerURL(new URL(postUrl.trim()));
-
-		XmlRpcClient client = new XmlRpcClient();
-
-		client.setConfig(config);
-
-		return client;
-	}
-
-	/**
-	 * コンテンツ用のパラメーターを組み立てる
-	 * 
-	 * @param wordsalad
-	 * @return
-	 */
-	protected Map<String, Object> buildContent(String title, String description) {
-		Map<String, Object> content = new HashMap<String, Object>();
-		// XMLRPC用に改行コードを書き換える
-		description = description.replaceAll("\n", "<br/>");
-
-		content.put("title", title);
-
-		String[] categories = new String[1];
-		categories[0] = "XML-RPC";
-		content.put("categories", categories);
-
-		content.put("description", description);
-
-		content.put("dateCreated", "");
-
-		content.put("wp_slug", "");
-
-		
-		// カスタムフィールドの設定
-		/*
-		 * Map<String, Object>[] customFields = new Map[1];
-		 * 
-		 * Map<String, Object> jimusho = new HashMap<String, Object>();
-		 * 
-		 * jimusho.put("key", "company");
-		 * 
-		 * jimusho.put("value", "じむしょ");
-		 * 
-		 * customFields[0] = jimusho;
-		 * 
-		 * content.put("custom_fields", customFields);
-		 */
-		return content;
-	}
-
-	protected List<Object> buildParam(String blogId, String loginId, String pw,
-			Map<String, Object> contentParam) {
-		List<Object> params = new ArrayList<Object>();
-
-		params.add(""); // appkey
-		params.add(blogId);
-		params.add(loginId);
-		params.add(pw);
-		params.add(contentParam);// content
-		params.add("1");// publish
-
-		return params;
-	}
-
-	public static void main(String[] args) throws Exception {
-		String title = "xml-rpcを用いての投稿テスト @ newPost";
-		String description = "metaWeblog.editPost<br>xml-rpc @ java";
-		String blogId = "77";
-		String loginId = "aotokage52";
-		String pw = "jasonkidd";
-		String url = "http://single.cr.ie.u-ryukyu.ac.jp/wordpress/xmlrpc.php";
-
-		XMLRPCTest logic = new XMLRPCTest();
-
-//		int res = logic.post(title, description, blogId, loginId, pw, url);
-		String res = logic.edit(title, description, blogId, loginId, pw, url);
-//		String result = logic.getBlogid(loginId, pw,url);
-		System.out.println("result = "+ res);
-		
-	}
-}
--- a/src/test/XmlRpc.java	Wed Oct 12 02:47:47 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +0,0 @@
-package test;
-
-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<String> categories = new ArrayList<String>();
-	
-	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() {
-		return post(META_WEBLOG_NEW_POST);
-	}
-	String editPost() {
-		return post(META_WEBLOG_EDIT_POST);
-	}
-	
-	String post(String API) {
-
-		String result = "";
-
-		Map<String, Object> contentParam = buildContent();
-		List<Object> 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<String, Object> buildContent() {
-		Map<String, Object> content = new HashMap<String, Object>();
-
-		description = description.replaceAll("\n", "<br/>");
-		content.put("title", title);
-		content.put("categories", categories.toArray());
-		content.put("description", description);
-		content.put("dateCreated", "");
-		content.put("wp_slug", "");
-		
-		return content;
-	}
-	
-	protected List<Object> buildParam(Map<String, Object> contentParam) {
-		List<Object> params = new ArrayList<Object>();
-
-		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<Object> params = new ArrayList<Object>();
-
-		params.add(blogId);
-		params.add(loginId);
-		params.add(pw);
-		
-		Object result = null;
-		String str = "false";
-		try {
-			result = weblog(params, META_WEBLOG_GET_POST);
-			Map<String, Object> map = (HashMap) result;
-			str = (String) map.get("link");
-		} catch (XmlRpcException e) {
-			e.printStackTrace();
-		}
-		return str;
-	}
-	
-	Object weblog(List<Object> 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.getUrl();
-//			String res = rpc.editPost();
-			System.out.println(res);
-		} catch (MalformedURLException e) {
-			e.printStackTrace();
-		}
-
-	}
-	
-}