The Artima Developer Community
Sponsored Link

Java Buzz Forum
The Weblog APIs in a single JSP

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Russell Beattie

Posts: 727
Nickname: rbeattie
Registered: Aug, 2003

Russell Beattie is a Mobile Internet Developer
The Weblog APIs in a single JSP Posted: May 31, 2004 5:05 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Russell Beattie.
Original Post: The Weblog APIs in a single JSP
Feed Title: Russell Beattie Notebook
Feed URL: http://www.russellbeattie.com/notebook/rss.jsp?q=java,code,mobile
Feed Description: My online notebook with thoughts, comments, links and more.
Latest Java Buzz Posts
Latest Java Buzz Posts by Russell Beattie
Latest Posts From Russell Beattie Notebook

Advertisement
I should be in bed, but I'm still awake messing around with weblog tech. I've been meaning to get around to implementing the Blogger, MetaWeblog, and MoveableType XML-RPC APIs for a while now (think: 2 years) but I just never bothered. Well, that's not true, I'd take a look at it, wonder what the hell a struct was in Java and move on. But now that I'm trying to meet all the criteria on this Blog Feature List both personally and professionally, I figured I'd better sit down for a moment and work it out.

XML-RPC, as most people have pointed out before, isn't particularly hard to get working. The problem is that what is affectionately called the Weblog APIs by some are actually several different groups of methods spread between their respective websites. Though MoveableType does have a nice summary, you still have to go track down and grok the original sources. Then, if you want to get this stuff running in Java, you have to contend with the horrendous samples that most Java programmers out there have created. I grabbed Blojsom, Roller and Pebble's implementations and was completely astounded by their complexity. Simon's is the clearest - and was a great starting point for me, but still. Why do Java programmers have to make this stuff so damn hard?!?!

So here's a single JSP page with an empty framework which supports of all three Weblog APIs.

A snippet:



<%!

	public void log(String message){
		System.out.println(message);
	}

	public boolean authenticate(String username, String password){
		
		//TODO: add authentication
		
		return true;	
	}


//************* Blogger 1.0 API ******************//

	public Hashtable getUserInfo(String appkey, String username, String password)
		throws XmlRpcException
	{
		
		log("XMLRPC: getUserInfo");
		
		boolean authenticated = authenticate(username, password);
		
	    if (authenticated) {

			String userid = "";
			String nickname = "";
			String url = "";
			String email = "";
			String lastname = "";
			String firstname = "";
			
			Hashtable map = new Hashtable();
			
			map.put("userid", userid);
			map.put("nickname", nickname);
			map.put("userid", userid);
			map.put("url", url);
			map.put("email", email);
			map.put("lastname", lastname);
			map.put("firstname", firstname);
			
			return map;
		
	    } else {
	      throw new XmlRpcException(0, "Username and password did not pass authentication.");
	    }

	}


	public Vector getUsersBlogs(String appkey, String username, String password)
		throws XmlRpcException
	{
		log("XMLRPC: getUsersBlogs");

		boolean authenticated = authenticate(username, password);

		if(authenticated){
			
			String url = "http://www.russellbeattie.com/notebook/";
			String blogid = "1";
			String blogName = "Russell Beattie Notebook";
		
			Vector list = new Vector();
			
	        Hashtable map = new Hashtable();
	        map.put("url", url);
	        map.put("blogid", blogid);
	        map.put("blogName", blogName);
	        
	        list.add(map);
	
			return list;
		
		} else {
	      throw new XmlRpcException(0, "Username and password did not pass authentication.");
	    }
		
	}


	public String newPost(String appkey, String blogid, String username, String password, String content, boolean publish)
		throws XmlRpcException
	{
		log("XMLRPC: newPost - blogger");
		
		String postid = "";
		
		return postid;
	}


	public boolean editPost(String appkey, String postid, String username, String password, String content, boolean publish)
		throws XmlRpcException
	{
		log("XMLRPC: editPost - blogger");
		
		boolean posted = true;
		
		return posted;
	}


	public String getTemplate(String appkey, String blogid, String username, String password, String templateType)
		throws XmlRpcException
	{
		log("XMLRPC: getTemplate");
	 	throw new XmlRpcException(0, "getTemplate is not supported.");
	}


	public boolean setTemplate(String appkey, String blogid, String username, String password, String template, String templateType)
		throws XmlRpcException
	{
		log("XMLRPC: setTemplate");
		throw new XmlRpcException(0, "setTemplate is not supported.");
	}

// ...
}

That's just the original Blogger 1.0 API. The rest of doc has the other method signatures. To use this file, go get Apache's XML-RPC Jar, throw it into your WEB-INF/lib, upload the .jsp file to your server as the endpoint and you'll have a basis to start working with editors like w.bloggar, Zempt and blogBuddy. Easy.

All the JSP does right now is just allow you to connect with those clients and log the methods being called. It's sort of like a JSP based base-class for you to fill in with your own method implementations. But that should be a good enough starting point for most projects. I wish I had this myself. For my personal weblog, I have to now go through and add the SQL queries to validate the user, query posts and update tables, but that's just busy work really. I think it would be really cool if someone just took this JSP as a starting point and instead of filling in the details with SQL stuff, wrote out actual .html files instead, creating a one page XML-RPC based weblog engine. Wouldn't that rock? I wish I had extra minutes to do it myself.

I find it very strange that there isn't a Java example out there like this already. Is there and I missed it?

The one thing that I don't really understand is what exactly the Blogger API has implemented. If you go to the offical Blogger 1.0 API page, it only lists six methods. But w.bloggar expects at least another few methods like getRecentPosts() (but not the metaWeblog version, a different one) that are also mysteriously documented on the MoveableType API page. It's strange. Then there's the Blogger 2.0 API which has been abandoned, but is floating out there, which doesn't match the signatures either. The metaWeblog API is a pretty straight forward addition to the Blogger stuff (if sketchily documented) as is MoveableType's. But in general it's just chaos out there. At the bare minimum someone should create a JavaDoc-like page explaining all these methods. No wonder the Atom guys wanted to organize all this.

Anyways, next up will actually be the AtomAPI after I get the XML-RPC methods implemented (I'll update the linked sample page as I go along)... I will definitely need to sleep before I tackle Atom, and may need healthy amounts of alcohol too.

-Russ

Read: The Weblog APIs in a single JSP

Topic: [May 21, 2004 14:30 PDT] 2 Links Previous Topic   Next Topic Topic: MT3: are you not entertained?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use