1
2
3
4
5
6
7 package com.wickle.Jdiary;
8
9 import java.awt.event.MouseEvent;
10 import java.io.IOException;
11 import java.net.MalformedURLException;
12 import java.util.Vector;
13 import org.apache.xmlrpc.XmlRpcClient;
14 import org.apache.xmlrpc.XmlRpcException;
15
16 /***
17 * @author vic
18 *
19 * TODO To change the template for this generated type comment go to
20 * Window - Preferences - Java - Code Style - Code Templates
21 */
22 public class TestXMLRPC {
23
24 public static XmlRpcClient xmlrpc;
25
26 static Preferencias prefs = new Preferencias();
27
28 public String Title;
29 public String Description;
30 public String postID;
31
32 public static String username;
33 public static String password;
34 public static String host;
35 public static String appId="74fffffffaffffff9bffffffafffffff80fffffff417ffffffdeffffffb7293a22fffffff1ffffffdd195a6affffff8805ffffffc31e412518";
36 public static String blogId="1";
37
38 Thread t;
39 Jdiary jdia;
40
41 public TestXMLRPC(Jdiary j){
42 jdia=j;
43
44 }
45 public TestXMLRPC(String a, String b){
46 this.Title=a;
47 this.Description=b;
48
49 }
50 public static String parseContent(String title, String body){
51 StringBuffer contenido= new StringBuffer();
52 System.out.println(contenido);
53
54 contenido.append("<title>".toString()).append(title.toString()).append("</title>".toString()).append(body.toString());
55 System.out.println(contenido);
56 return contenido.toString();
57 }
58
59 public String post(String content, String body){
60 String postID=null;
61 String contenido= parseContent(content,body);
62 username=prefs.getUSERNAME();
63 password=prefs.getPASSWORD();
64 host=prefs.getHOST();
65 try {
66 xmlrpc = new XmlRpcClient(host);
67 } catch (MalformedURLException e1) {
68
69 e1.printStackTrace();
70 }
71
72 Vector params = new Vector();
73 params.add(appId);
74 params.add(blogId);
75 params.add(username);
76 params.add(password);
77
78 params.add(contenido);
79 params.add(Boolean.TRUE);
80
81
82
83 String s = null;
84 System.out.println("test3");
85
86 try {
87 postID = (String) xmlrpc.execute("blogger.newPost",params);
88 } catch (XmlRpcException e) {
89 System.out.println("ERROR 1:"+e.getMessage());
90 } catch (IOException e) {
91 System.out.println("ERROR 2:"+e.getMessage());
92 }
93
94 System.out.println("devuelve:"+postID);
95 System.out.println("Valor:"+prefs.getHOST());
96 this.setPostID(postID);
97 return postID;
98
99 }
100
101
102
103 public void run() {
104
105 System.out.println("holaaaaaaa");
106 while ((postID=post(Title,Description)) == null ){
107
108 System.out.println("data is null...waiting ");
109
110
111
112
113 }
114
115
116 System.out.println("datos recibidos ... ");
117
118 }
119
120
121
122 /***
123 * @return Returns the a.
124 */
125 public String getTitle() {
126 return Title;
127 }
128
129 /***
130 * @return Returns the description.
131 */
132 public String getDescription() {
133 return Description;
134 }
135 /***
136 * @param description The description to set.
137 */
138 public void setDescription(String description) {
139 Description = description;
140 }
141 /***
142 * @param title The title to set.
143 */
144 public void setTitle(String title) {
145 Title = title;
146 }
147 /***
148 * @return Returns the postID.
149 */
150 public String getPostID() {
151 return postID;
152 }
153 /***
154 * @param postID The postID to set.
155 */
156 public void setPostID(String postID) {
157 this.postID = postID;
158 }
159 }