Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • IBM Connections wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 1.0
  • 1.0.x
  • 2.0
  • 2.0.1
  • 2.0.1.1
  • 2.0_media
  • 2.5
  • 2.5_deployment
  • 2.5_media
  • 2.5_performance
  • 3
  • 3.0
  • 3.0.1
  • 3.0.1_media
  • 3.0_media
  • 3_deployment
  • 8.1.1
  • 8.2
  • activities
  • administrators
  • api
  • best_practices
  • blogs
  • bookmarks
  • business_card
  • cluster
  • communities
  • community
  • community_manager
  • connections
  • connections_3
  • connections_301
  • customization
  • customize
  • customizing
  • demos
  • deploying
  • deployment
  • deployments
  • developers
  • dogear
  • Domino
  • Edge server
  • education
  • error messages
  • files
  • forums
  • getting_started
  • Help
  • home
  • home_page
  • homepage
  • how-to
  • HTTP server
  • ibm
  • index
  • installation
  • integration
  • iOS
  • ipad
  • iWidget
  • J2EE
  • javadoc
  • lc3.0
  • learning
  • lotus-connections
  • mml
  • mobile
  • Notes
  • performance
  • person_card
  • Portal
  • portlet
  • portlet_factory
  • profiles
  • proxy server
  • quickr
  • Redbooks
  • rest
  • reverse proxy server
  • Sametime
  • scenarios
  • search
  • security
  • self-paced
  • SSO
  • tags
  • test_infrastructure
  • troubleshooting
  • tuning
  • video
  • VideoFest
  • videos
  • WAI
  • WAS
  • web_seminar
  • WebAppIntegrator
  • WebSphere
  • widgets
  • wikis
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > IBM Redbooks: Customizing IBM Connections 3.0.1 > 9.5 Working with Blog postings and comments
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

9.5 Working with Blog postings and comments 

expanded Abstract
collapsed Abstract
No abstract provided.
ShowTable of Contents
HideTable of Contents
  • 1 Posting a blog entry
  • 2 Posting a comment
Previous | Next

Blogs have long since used Atom and RSS feeds for both the consuming and publishing of information. So the Atom feeds used for the Blogs API are a natural fit. Since there are a variety of tools and applications that exist to consume blog feeds, this article focuses on the publishing of blog entries and comments. 

Posting a blog entry


To post a new blog entry, first retrieve the service document for the blog. The service document contains the URL necessary for posting new entries. The input for the API is a blog entry document.
 
The following sample code can be used to post a new blog entry:
 
 // Create an Abdera client and add credentials to it. 

Abdera abdera = new Abdera();
        
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager();
 
client.addCredentials("https://server", null, null, new UsernamePasswordCredentials("user","password"));
     
// After authentication, we use Abdera to get the service document and parse the document to get required collection. 
 
ClientResponse resp = client.get("https://server/blogs/services/atom?lang=en_us"); 
Document<Service> ServiceDocument = resp.getDocument(); 
ServiceDocument.writeTo(System.out);
Service service = ServiceDocument.getRoot(); 
 
// Provide title of workspace and title of the Blogs collection at this stage to retrieve the collection.
// In this example, Sample Blog is the name of the blog. Weblog Entries is the collection of entries to be returned.
 
Collection collection = service.getCollection("Sample Blog", "Weblog Entries"); 
 
// Obtain collections uri where entry needs to be posted.
 
String CollectionURI = collection.getResolvedHref().toASCIIString();              
 
// Create a new atom entry document as below which needs to be posted to the blog. 
 
Entry entry = abdera.newEntry(); 
entry.newId();         
entry.addAuthor("John Doe"); 
entry.setUpdated(new Date()); 
entry.setTitle("Test entry from Java"); 
entry.setContentAsHtml("This is the content of the entry.");  
entry.addCategory("tag1"); 
entry.addCategory("tag2"); 
 
//Post the created entry document to the collections uri obtained from service document. 
 
RequestOptions opt = client.getDefaultRequestOptions(); 
resp = client.post(CollectionURI, entry, opt );    
 

Posting a comment


To post a comment to a blog entry, we first retrieve the service document for the blog. Then we use the Comment Entries collection to find the URL for posting comments. Each comment must be attached to an entry or another comment so we also must find the ID of the blog entry to post the comment against.
 
 // Create an Abdera client and add credentials to it. 

Abdera abdera = new Abdera();
Parser parser = abdera.getParser();
 
AbderaClient client = new AbderaClient(abdera);
 
AbderaClient.registerTrustManager();
 
client.addCredentials("https://server", null, null, new UsernamePasswordCredentials("user","password"));
 
// After authentication we use Abdera to get the service document and parse the document to get required collection. 
 
ClientResponse resp = client.get("https://server/blogs/api"); 
Document<Service> ServiceDocument = resp.getDocument(); 
ServiceDocument.writeTo(System.out);
Service service = ServiceDocument.getRoot(); 
 
// Provide title of workspace and title of the Blogs collection at this stage to retrieve the collection.
 
// In this example, Sample Blog is the name of the blog. Weblog Entries is the collection of entries to be returned.
 
Collection collection = service.getCollection("Sample Blog", "Weblog Entries");
String CollectionURI = collection.getResolvedHref().toASCIIString();
 
// Use the Comment Entries collection to find the URL to post comments
 
Collection collectionComments = service.getCollection("Sample Blog", "Comment Entries"); 
 
String CommentURI = collectionComments.getHref().toASCIIString();
 
Document<Element> doc;                                                 
URL url = new URL(CollectionURI); 
 
resp = client.get(url.toString());
doc = parser.parse(resp.getInputStream()); 
Feed feed = (Feed) doc.getRoot(); 
 
Entry entry2 = null;
 
// Loop through the entries to find the id of the entry to post the comment 
 
for (Entry entry : feed.getEntries()) { 
    System.out.println("\t" + entry.getTitle());        // This prints the title of each comment entry 
    System.out.println("\t" + entry.getContent());      // This prints the actual content of the comment . 
    System.out.println("\t" + entry.getId());             // This prints the comment entry id . 
    System.out.println("\t" + entry.getLink("edit"));
    entry2 = entry;
} 
     
// Creating the atom entry that needs to be posted .
 
Entry entry1 = abdera.newEntry();   
entry1.setTitle("Sample Comment"); 
entry1.setContent("html"); 
entry1.setContentAsHtml("This is another sample comment HTML content");
 
// ThreadHelper Class used to add the  tag to the entry1
// and entry 2 is the Blog entry to which this comment is a response . The  of entry2 is added   to the  tag on entry1   
 
ThreadHelper.addInReplyTo(entry1, entry2); 
System.out.println(entry1); 
 
//Construction in entry1 completed now post to the Blogs API. 
RequestOptions opt = client.getDefaultRequestOptions(); 
resp = client.post(CommentURI , entry1, opt);
 
System.out.println("posted?" + resp.getStatus() + "/" + resp.getStatusText());   


Parent topic: 9.0 Using the API

expanded Article information
collapsed Article information
Category:
IBM Redbooks: Customizing IBM Connections 3.0.1
Tags:
Redbooks

This Version: Version 2 November 22, 2011 12:04:07 PM by Amanda J Bauman  IBMer

expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (2)
collapsed Versions (2)
Version Comparison     
Version Date Changed by               Summary of changes
This version (2) Nov 22, 2011 12:04:07 PM Amanda J Bauman  
1 Nov 21, 2011 1:09:18 PM Amanda J Bauman  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use