Package com.volongoto.quickbp

Source Code of com.volongoto.quickbp.BloggerServiceHandler

package com.volongoto.quickbp;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import com.google.gdata.client.GoogleService;
import com.google.gdata.client.GoogleService.InvalidCredentialsException;
import com.google.gdata.client.blogger.BloggerService;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.util.ServiceException;

public final class BloggerServiceHandler {
 
  BloggerServiceHandler() {
    feedUrl = null;
    serviceHandler = new GoogleServiceHandler();
    service = new BloggerService("NinjaBlogger");
    // Initialize feedUrl
    try {
      feedUrl = new URL(METAFEED_URL);
    } catch (MalformedURLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
  }
 
  public boolean authenticate(String username, String password) throws InvalidCredentialsException {
    return serviceHandler.authenticate(service, username, password);
  }
 
  public boolean handleCaptcha(
      String username,
      String password,
      GoogleService.CaptchaRequiredException cre
      ) throws InvalidCredentialsException {
    return serviceHandler.handleCaptcha(service, username, password, cre);
  }
  /**
   * @param service GoogleService object to be operated on
   * @param feedUrl Meta feed URL to be user to get the list of
   * blogs/albums/etc. depending on the service
   * @return Feed object containing the list of blogs/albums/etc.
   */
  public Feed getMetaFeed() {
    Feed metaFeed = null;
    try {
      metaFeed = service.getFeed(feedUrl, Feed.class);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ServiceException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return metaFeed;
  }
 
  public URL getFeedUrl() {
    return feedUrl;
  }
 
  public Entry createPost(
      String blogID,
      String title,
      String content) {
    // Create the entry to insert
    Entry myEntry = new Entry();
    myEntry.setTitle(new PlainTextConstruct(title));
    myEntry.setContent(new PlainTextConstruct(content));
   
    // Ask the service to insert the new entry
    URL postUrl = null;
    try {
      postUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/posts/default");
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      return service.insert(postUrl, myEntry);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ServiceException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return myEntry;
  }
 
  private static final String METAFEED_URL = "http://www.blogger.com/feeds/default/blogs";
  private URL feedUrl;
  private GoogleServiceHandler serviceHandler;
  private BloggerService service;
}
TOP

Related Classes of com.volongoto.quickbp.BloggerServiceHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.