changeset 149:f68f63c298d0

merge
author Yu Taninari <e085734@ie.u-ryukyu.ac.jp>
date Fri, 09 Sep 2011 23:22:58 +0900
parents 0d9a824dd12f (current diff) a2b5149bbbe6 (diff)
children ea60596e05ef
files hades.cr.ie.u-ryukyu.ac.jp.html nw0811.st.ie.u-ryukyu.ac.jp.html src/myVncProxy/AcceptClient.java src/myVncProxy/MyRfbProto.java
diffstat 13 files changed, 658 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Fri Sep 09 23:12:37 2011 +0900
+++ b/.classpath	Fri Sep 09 23:22:58 2011 +0900
@@ -3,5 +3,11 @@
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+	<classpathentry kind="lib" path="/Users/aotokage/testProgram/java/xml_rpc/apache-xmlrpc-3.1.3/lib/xmlrpc-client-3.1.3.jar"/>
+	<classpathentry kind="lib" path="/Users/aotokage/testProgram/java/xml_rpc/apache-xmlrpc-3.1.3/lib/xmlrpc-common-3.1.3.jar"/>
+	<classpathentry kind="lib" path="/Users/aotokage/testProgram/java/xml_rpc/apache-xmlrpc-3.1.3/lib/xmlrpc-server-3.1.3.jar"/>
+	<classpathentry kind="lib" path="/Users/aotokage/testProgram/java/xml_rpc/commons-codec-1.3.jar"/>
+	<classpathentry kind="lib" path="/Users/aotokage/testProgram/java/xml_rpc/apache-xmlrpc-3.1.3/lib/ws-commons-util-1.0.2.jar"/>
+	<classpathentry kind="lib" path="/Users/aotokage/testProgram/java/xml_rpc/apache-xmlrpc-3.1.3/lib/commons-logging-1.1.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Fri Sep 09 23:22:58 2011 +0900
@@ -0,0 +1,7 @@
+syntax: glob
+*.jar
+GPATH
+GRTAGS
+GSYMS
+GTAGS
+template.txt
\ No newline at end of file
--- a/hades.cr.ie.u-ryukyu.ac.jp.html	Fri Sep 09 23:12:37 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-<HTML><TITLE>hbpVNC desktop</TITLE>
-<APPLET CODE="VncViewer.class" ARCHIVE="VncViewer.jar"
- WIDTH="1280" HEIGHT="1024">
-<PARAM NAME="PORT" VALUE="5550">
-<PARAM NAME="HOST" VALUE="133.13.56.3">
-</APPLET>
-<BR>
-<A href="http://ie.u-ryukyu.ac.jp/">University of the Ryukyu </A>
-</HTML>
-
--- a/nw0811.st.ie.u-ryukyu.ac.jp.html	Fri Sep 09 23:12:37 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-<HTML><TITLE>hbpVNC desktop</TITLE>
-<APPLET CODE="VncViewer.class" ARCHIVE="VncViewer.jar"
- WIDTH="1280" HEIGHT="800">
-<PARAM NAME="PORT" VALUE="5550">
-<PARAM NAME="HOST" VALUE="133.13.56.3">
-</APPLET>
-<BR>
-<A href="http://ie.u-ryukyu.ac.jp/">University of the Ryukyu </A>
-</HTML>
-
--- a/src/myVncProxy/AcceptClient.java	Fri Sep 09 23:12:37 2011 +0900
+++ b/src/myVncProxy/AcceptClient.java	Fri Sep 09 23:22:58 2011 +0900
@@ -5,7 +5,7 @@
 import java.net.*;
 import java.util.*;
 
-public class AcceptClient extends Thread {
+public class AcceptClient {
 	int counter = 0, parentnum = 0/* 落ちたときの親の番号をカウントするためのもの */;
 	LinkedList<String> ls = new LinkedList<String>();
 	boolean runflag = false;
@@ -106,9 +106,11 @@
 							if (checkRepetition.equals(ls.getLast())) {
 								checkRepetition = "stop";
 							} else {
+
 								//checkRepetition = "go";
 								if(ls.size()-1+passCheck == Integer.parseInt(checkRepetition)) {
 									checkRepetition = "skip";
+
 								}
 								passCheck = 0;
 							}
--- a/src/myVncProxy/MyRfbProto.java	Fri Sep 09 23:12:37 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Fri Sep 09 23:22:58 2011 +0900
@@ -26,7 +26,6 @@
 import myVncProxy.MulticastQueue.Client;
 
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
@@ -55,7 +54,7 @@
 	private boolean clicomp = false;
 
 	private ServerSocket servSock;
-	private int acceptPort;
+	protected int acceptPort;
 	private byte initData[];
 	private LinkedList<Socket> cliListTmp;
 	private LinkedList<Socket> cliList;
@@ -119,6 +118,7 @@
 
 	// 5999を開けるが、開いてないなら+1のポートを開ける。
 	void selectPort(int p) {
+		if(servSock != null ) return ;
 		int port = p;
 		while (true) {
 			try {
@@ -230,7 +230,7 @@
 
 		if (serverMajor < 3) {
 			throw new IOException(
-					"RFB server does not support protocol version 3");
+			"RFB server does not support protocol version 3");
 		}
 
 		if (serverMinor == 998) {
--- a/src/myVncProxy/ProxyVncCanvas.java	Fri Sep 09 23:12:37 2011 +0900
+++ b/src/myVncProxy/ProxyVncCanvas.java	Fri Sep 09 23:22:58 2011 +0900
@@ -392,7 +392,7 @@
 					rfb.is.reset();
 					break;
 				}
-				
+
 				if (statNumUpdates == viewer.debugStatsExcludeUpdates
 						&& !statsRestarted) {
 					resetStats();
@@ -404,6 +404,7 @@
 
 				rfb.readFramebufferUpdate();
 				statNumUpdates++;
+//				System.out.println("NRects = "+ rfb.updateNRects);
 
 				boolean cursorPosReceived = false;
 
@@ -413,7 +414,9 @@
 					statNumTotalRects++;
 					int rx = rfb.updateRectX, ry = rfb.updateRectY;
 					int rw = rfb.updateRectW, rh = rfb.updateRectH;
-
+//					System.out.println("rx = "+ rx + "  ry = "+ry+"\nrw = "+rw+"  rh = "+rh);
+//					System.out.println("encoding = "+ rfb.updateRectEncoding);
+					
 					if (rfb.updateRectEncoding == rfb.EncodingLastRect)
 						break;
 
--- a/src/myVncProxy/RfbProto.java	Fri Sep 09 23:12:37 2011 +0900
+++ b/src/myVncProxy/RfbProto.java	Fri Sep 09 23:22:58 2011 +0900
@@ -1366,7 +1366,7 @@
 	}
 
 	// FIXME: DataInputStream::skipBytes() is not guaranteed to skip
-	// exactly n bytes. Probably we don't want to use this method.
+	// exactly n bytes. Probably we don't want to use this method.f
 	final int skipBytes(int n) throws IOException {
 		int r = is.skipBytes(n);
 		numBytesRead += r;
--- a/src/myVncProxy/VncProxyService.java	Fri Sep 09 23:12:37 2011 +0900
+++ b/src/myVncProxy/VncProxyService.java	Fri Sep 09 23:22:58 2011 +0900
@@ -53,7 +53,7 @@
 	// Variables read from parameter values.
 	String socketFactory;
 	String host;
-	int port;
+	int port = 5900;
 	String passwordParam;
 	boolean showControls;
 	boolean offerRelogin;
@@ -65,19 +65,51 @@
 	int debugStatsMeasureUpdates;
 
 	int echoPort = 9999;
-	
+
+	String url;
 
+	XmlRpc client;
+	String wpUsername, wpPassword, blogId;
+	String title = "TreeVNC";
 	
 	void checkArgs(String[] argv){
-		if(argv.length > 3){
-			username = argv[3]; 
-		}else if(argv.length < 2){
-			System.out.println("Please enter argv");
-			System.out.println("hostname(IPaddress) port password");
-			System.exit(0);
-		}else{
-			username = argv[0];
+		int len = argv.length;
+
+		for(int i = 0; i < len ; i ++) {
+			String str = argv[i];
+			if (str.equals("-h") || str.equals("--host")){
+				host = argv[++i];
+			} else if (str.equals("-pn") || str.equals("--port")){
+				port = Integer.parseInt(argv[++i]);
+			} else if (str.equals("-pw") || str.equals("--password")){
+				passwordParam = argv[++i];
+			} else if (str.equals("-w") || str.equals("--wpurl")){
+				url = argv[++i];
+			} else if (str.equals("-wu") || str.equals("--wpusername")){
+				wpUsername = argv[++i];
+			} else if (str.equals("-wp") || str.equals("--wppassword")){
+				wpPassword = argv[++i];
+			} else if (str.equals("-wb") || str.equals("--wpblogId")){
+				blogId = argv[++i];
+			} else if (str.equals("--help")) {
+				printHelp();
+				System.exit(0);
+			} else if (len == 3) {
+				host = argv[0];
+				port = Integer.parseInt(argv[1]);
+				passwordParam = argv[2];
+			} else if (len < 3){
+				printHelp();
+				System.exit(0);
+			}
 		}
+		
+	} 
+	
+	void printHelp() {
+		System.out.println("usage: java -jar VncProxyService [-h hostname] " +
+				"[-pn portnumber] [-pw password] [-w WordPressURL] [-wu WPUsername] " +
+				"[-wp WPPassword] [-wb blogId]");
 	}
 	
 	//
@@ -87,7 +119,7 @@
 	public void init() {
 
 		readParameters();
-
+		
 		options = new OptionsNoFrame(this);
 		recordingSync = new Object();
 
@@ -99,6 +131,7 @@
 
 		try{
 			connectAndAuthenticate();
+			doProtocolInitialisation();
 		}catch (NoRouteToHostException e) {
 			fatalError("Network error: no route to server: " + host, e);
 		} catch (UnknownHostException e) {
@@ -107,10 +140,40 @@
 			fatalError("Network error: could not connect to server: " + host
 					+ ":" + port, e);
 		}catch(Exception e){}
-
+		
+		rfb.selectPort(5999);
 		rfbThread = new Thread(this);
 		accThread = new Thread(new AcceptThread(rfb, 5999)); 
 
+		if(url != null) {
+			try {
+				client = new XmlRpc(blogId, wpUsername, wpPassword, url );
+				InetAddress addr = InetAddress.getLocalHost();
+				String add = new String(addr.getHostAddress());
+				client.addDescription(rfb.desktopName);
+				setStatusXmlRpc(client, title, add, rfb.acceptPort);
+				client.editPost();
+				System.out.println("URL:\n" + client.getUrl() + "\n");
+			} catch (MalformedURLException e) {
+				System.out.println("Faild create instance of class XmlRpc");
+				e.printStackTrace();
+			} catch (UnknownHostException e) {
+				e.printStackTrace();
+			}
+		}		
+		
+		
+	}
+	
+	void setStatusXmlRpc(XmlRpc client, String title, String hostname, int port) {
+		client.setTitle(title);
+		String description = makeDescription(hostname, Integer.toString(port));
+		client.addDescription(description);
+	}
+	
+	String makeDescription(String hostname, String port) {
+		String description = "<h1>" + hostname + " " + port + "<h1>\n";
+		return description;
 	}
 	
 	public void start_threads(){
@@ -126,7 +189,7 @@
 
 		try {
 //			connectAndAuthenticate();
-			doProtocolInitialisation();
+//			doProtocolInitialisation();
 /*
 			htmlFile = new CreateHtmlFile(rfb, host, username);
 			htmlFile.createHtml();
@@ -201,7 +264,7 @@
 	//
 
 	void connectAndAuthenticate() throws Exception {
-	    acc = new AcceptClient(mainArgs[0]);
+	    acc = new AcceptClient(host);
 	    geth = new CreateThread(acc , echoPort);
 	    Thread thread = new Thread(geth);
 	    thread.start();
@@ -211,8 +274,6 @@
 
 		showConnectionStatus("Connecting to " + host + ", port " + port + "...");
 
-		// rfb = new RfbProto(host, port, this);
-//		rfb = new MyRfbProto(host, port);
 		rfb = new MyRfbProto(host, port, geth);
 
 		showConnectionStatus("Connected to server");
@@ -327,6 +388,7 @@
 		int preferredEncoding = options.preferredEncoding;
 		if (preferredEncoding == -1) {
 			long kbitsPerSecond = rfb.kbitsPerSecond();
+/*
 			if (nEncodingsSaved < 1) {
 				// Choose Tight or ZRLE encoding for the very first update.
 				System.out.println("Using Tight/ZRLE encodings");
@@ -349,6 +411,7 @@
 					return;
 				preferredEncoding = encodingsSaved[0];
 			}
+*/			
 		} else {
 			// Auto encoder selection is not enabled.
 			if (autoSelectOnly)
@@ -364,19 +427,22 @@
 		if (options.useCopyRect) {
 			encodings[nEncodings++] = RfbProto.EncodingCopyRect;
 		}
+/*
 		if (preferredEncoding != RfbProto.EncodingTight) {
 			encodings[nEncodings++] = RfbProto.EncodingTight;
 		}
-
+*/
 		if (preferredEncoding != RfbProto.EncodingZRLE) {
 			encodings[nEncodings++] = RfbProto.EncodingZRLE;
 		}
+/*
 		if (preferredEncoding != RfbProto.EncodingHextile) {
 			encodings[nEncodings++] = RfbProto.EncodingHextile;
 		}
 		if (preferredEncoding != RfbProto.EncodingZlib) {
 			encodings[nEncodings++] = RfbProto.EncodingZlib;
 		}
+*/
 		if (preferredEncoding != RfbProto.EncodingCoRRE) {
 			encodings[nEncodings++] = RfbProto.EncodingCoRRE;
 		}
@@ -538,14 +604,6 @@
 
 	void readParameters() {
 
-		host = mainArgs[0];
-		if(mainArgs.length < 2){
-			port = 5900;
-		}else{
-			port = Integer.parseInt(mainArgs[1]);
-		}
-		
-
 		// Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
 //		readPasswordParameters();
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/myVncProxy/XmlRpc.java	Fri Sep 09 23:22:58 2011 +0900
@@ -0,0 +1,183 @@
+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<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() {
+		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<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.newPost();			
+//			String res = rpc.editPost();
+			String res2 = rpc.getUrl();
+			System.out.println(res);
+			System.out.println(res2);
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		}
+
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/XMLRPCTest.java	Fri Sep 09 23:22:58 2011 +0900
@@ -0,0 +1,178 @@
+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);
+		
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/XmlRpc.java	Fri Sep 09 23:22:58 2011 +0900
@@ -0,0 +1,182 @@
+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();
+		}
+
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/template.txt	Fri Sep 09 23:22:58 2011 +0900
@@ -0,0 +1,7 @@
+-h hostname
+-pn 5900
+-pw password
+-w WordPressURL
+-wu WPUsername
+-wp WPPassword
+-wb blogId
\ No newline at end of file