import org.apache.xmlrpc.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class BloggerTask extends Task {
private String _url;
private final static String APP_KEY = "8F5FC22730AEB98D96074ECEF66C2404ABCDF40137";
private final static String BLOGGER_URL = "http://plant.blogger.com/api/RPC2";
private String blogid;
private String username;
private String password;
private String content;
private String property_summary = new String();
public void execute() throws BuildException {
property_summary += "<b>Blogger build message</b>.<br><br>\n";
Hashtable userProperties = project.getUserProperties();
Enumeration keys = userProperties.keys();
property_summary += "User Environment Summary<br>\n";
property_summary += "-------------------<br><br>\n";
while(keys.hasMoreElements()) {
Object key = (Object) keys.nextElement();
property_summary += key + " = " + userProperties.get(key) + "<br>\n";
}
Hashtable properties = project.getProperties();
keys = properties.keys();
property_summary += "Environment Summary<br>\n";
property_summary += "-------------------<br><br>\n";
while(keys.hasMoreElements()) {
Object key = (Object) keys.nextElement();
property_summary += key + " = " + properties.get(key) + "<br>\n";
};
try {
XmlRpcClient xmlrpc = new XmlRpcClient(BLOGGER_URL);
Vector params = new Vector();
params.addElement(APP_KEY);
params.addElement(blogid);
params.addElement(username);
params.addElement(password);
params.addElement(content + property_summary);
params.addElement(new Boolean(false));
String result = (String) xmlrpc.execute("blogger.newPost",params);
} catch (Exception e) {
System.out.println("The message was: \n" + content + property_summary);
throw new BuildException("There was an XML-RPC error that occured: " + e);
}
}
public void setblogid(String blogid) {
this.blogid = blogid;
}
public void setusername(String username) {
this.username = username;
}
public void setpassword(String password) {
this.password = password;
}