Client library for interacting with blog servers

The BlogClient package defines generic interface that can be used to create, retrieve, update and delete blog entries and blog resources from a blog server that supports either the MetaWeblog API or the Atom protocol.

The diagram below shows the interfaces in the blog client package.

Diagram of BlogClient classes

Now let's take a look at an example that shows how to post a blog entry via Atom protocol and the Blog Client library.

    
import com.sun.syndication.propono.blogclient.*;

// class and method declaration omitted 

String endpointURL = // URL of your blog server
String username =    // your username on the blog server
String password =    // your password 
String title =       // title of the new blog entry
String content =     // content of the new blog entry

BlogConnection con =                                      #1
   BlogConnectionFactory.getBlogConnection(
      "atom", endpointURL, username, password);
Blog blog = (Blog)con.getBlogs().get(0);                  #2

BlogEntry entry = blog.newEntry();                        #3
entry.setTitle(title);                                    #4
entry.setContent(new BlogEntry.Content(content));         #5
entry.save();                                             #6

Let's review that code. First we get a connection from the factory by specifying Atom protocol, our blog server's endpoint URL and login credentials (#1). From the connection, we get the first blog that's available (#2). Next we create a new entry in the blog's primary collection (#3), set its title (#4), set it's content (#5) and post it to the blog server by calling its save() method (#5).