File Source: BloggerAPIHandler.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  
    19  package org.apache.roller.weblogger.webservices.xmlrpc;
    20  
    21  import java.sql.Timestamp;
    22  import java.util.ArrayList;
    23  import java.util.Date;
    24  import java.util.Hashtable;
    25  import java.util.Iterator;
    26  import java.util.List;
    27  import java.util.Map;
    28  import java.util.StringTokenizer;
    29  import java.util.Vector;
    30  
    31  import javax.servlet.http.HttpServletRequest;
    32  
    33  import org.apache.commons.lang.StringUtils;
    34  import org.apache.commons.logging.Log;
    35  import org.apache.commons.logging.LogFactory;
    36  import org.apache.roller.weblogger.WebloggerException;
    37  import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
    38  import org.apache.roller.weblogger.business.Weblogger;
    39  import org.apache.roller.weblogger.business.WebloggerFactory;
    40  import org.apache.roller.weblogger.business.UserManager;
    41  import org.apache.roller.weblogger.business.WeblogManager;
    42  import org.apache.roller.weblogger.pojos.User;
    43  import org.apache.roller.weblogger.pojos.WeblogEntry;
    44  import org.apache.roller.weblogger.pojos.WeblogTemplate;
    45  import org.apache.roller.weblogger.pojos.Weblog;
    46  import org.apache.roller.weblogger.util.Utilities;
    47  import org.apache.xmlrpc.XmlRpcException;
    48  
    49  /**
    50   * Weblogger XML-RPC Handler for the Blogger v1 API.
    51   * 
    52   * Blogger API spec can be found at http://plant.blogger.com/api/index.html
    53   * See also http://xmlrpc.free-conversant.com/docs/bloggerAPI
    54   * 
    55   * @author David M Johnson
    56   */
    57  public class BloggerAPIHandler extends BaseAPIHandler {
    58      
    59      static final long serialVersionUID = 2398898776655115019L;
    60      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.webservices.xmlrpc.BloggerAPIHandler__static_init
              * 
              *  Postconditions:
              *    init'ed(mLogger)
              */
    61      private static Log mLogger = LogFactory.getLog(BloggerAPIHandler.class);
    62      
    63      public BloggerAPIHandler() {
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.webservices.xmlrpc.BloggerAPIHandler()
                  */
    64          super();
    65      }
    66      
    67      
    68      /**
    69       * Delete a Post
    70       *
    71       * @param appkey Unique identifier/passcode of the application sending the post
    72       * @param postid Unique identifier of the post to be changed
    73       * @param userid Login for a Blogger user who has permission to post to the blog
    74       * @param password Password for said username
    75       * @param publish Ignored
    76       * @throws XmlRpcException
    77       * @return
    78       */
    79      public boolean deletePost(String appkey, String postid, String userid,
    80              String password, boolean publish) throws Exception {
    81          
                 /* 
    P/P           *  Method: bool deletePost(String, String, String, String, bool)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  *    (soft) password != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@88 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@87 != null
                  *    org.apache.roller.weblogger.pojos.WeblogEntry:getWebsite(...)@94 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.business.WeblogManager:getWeblogEntry(...)@89: Inverse{null}, Addr_Set{null}
                  */
    82          mLogger.debug("deletePost() Called =====[ SUPPORTED ]=====");
    83          mLogger.debug("     Appkey: " + appkey);
    84          mLogger.debug("     PostId: " + postid);
    85          mLogger.debug("     UserId: " + userid);
    86          
    87          Weblogger roller = WebloggerFactory.getWeblogger();
    88          WeblogManager weblogMgr = roller.getWeblogManager();
    89          WeblogEntry entry = weblogMgr.getWeblogEntry(postid);
    90          
    91          // Return false if entry not found
    92          if (entry == null) return false;
    93          
    94          validate(entry.getWebsite().getHandle(), userid, password);
    95          
    96          try {
    97              // delete the entry
    98              weblogMgr.removeWeblogEntry(entry);
    99              roller.flush();
   100              
   101              // notify cache
   102              flushPageCache(entry.getWebsite());
   103          } catch (Exception e) {
   104              String msg = "ERROR in blogger.deletePost: "+e.getClass().getName();
   105              mLogger.error(msg,e);
   106              throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
   107          }
   108          
   109          return true;
   110      }
   111      
   112      
   113      /**
   114       * Edits the main index template of a given blog. Weblogger only support
   115       * updating the main template, the default template of your weblog.
   116       * 
   117       * @param appkey Unique identifier/passcode of the application sending the post
   118       * @param blogid Unique identifier of the blog the post will be added to
   119       * @param userid Login for a Blogger user who has permission to post to the blog
   120       * @param password Password for said username
   121       * @param template The text for the new template (usually mostly HTML).
   122       * @param templateType Determines which of the blog's templates is to be set.
   123       * @return 
   124       * @throws XmlRpcException
   125       */
   126      public boolean setTemplate(String appkey, String blogid, String userid,
   127              String password, String templateData,
   128              String templateType) throws Exception {
   129          
                 /* 
    P/P           *  Method: bool setTemplate(String, String, String, String, String, String)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    templateType != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  *    (soft) password != null
                  * 
                  *  Presumptions:
                  *    java.lang.String:equals(...)@139 == 1
                  *    org.apache.roller.weblogger.business.UserManager:getPage(...)@148 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@146 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@145 != null
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
   130          mLogger.debug("setTemplate() Called =====[ SUPPORTED ]=====");
   131          mLogger.debug("     Appkey: " + appkey);
   132          mLogger.debug("     BlogId: " + blogid);
   133          mLogger.debug("     UserId: " + userid);
   134          mLogger.debug("   Template: " + templateData);
   135          mLogger.debug("       Type: " + templateType);
   136          
   137          validate(blogid, userid, password);
   138          
   139          if (! templateType.equals("main")) {
   140              throw new XmlRpcException(
   141                      UNKNOWN_EXCEPTION, "Roller only supports main template");
   142          }
   143          
   144          try {
   145              Weblogger roller = WebloggerFactory.getWeblogger();
   146              UserManager userMgr = roller.getUserManager();
   147              
   148              WeblogTemplate page = userMgr.getPage(templateType);
   149              page.setContents(templateData);
   150              userMgr.savePage(page);
   151              flushPageCache(page.getWebsite());
   152              
   153              return true;
   154          } catch (WebloggerException e) {
   155              String msg = "ERROR in BlooggerAPIHander.setTemplate";
   156              mLogger.error(msg,e);
   157              throw new XmlRpcException(UNKNOWN_EXCEPTION,msg);
   158          }
   159      }
   160      
   161      
   162      /**
   163       * Returns the main or archive index template of a given blog
   164       *
   165       * @param appkey Unique identifier/passcode of the application sending the post
   166       * @param blogid Unique identifier of the blog the post will be added to
   167       * @param userid Login for a Blogger user who has permission to post to the blog
   168       * @param password Password for said username
   169       * @param templateType Determines which of the blog's templates will be returned. Currently, either "main" or "archiveIndex"
   170       * @throws XmlRpcException
   171       * @return
   172       */
   173      public String getTemplate(String appkey, String blogid, String userid,
   174              String password, String templateType)
   175              throws Exception {
   176          
                 /* 
    P/P           *  Method: String getTemplate(String, String, String, String, String)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  *    (soft) password != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.UserManager:getPage(...)@188 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@187 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@186 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   177          mLogger.debug("getTemplate() Called =====[ SUPPORTED ]=====");
   178          mLogger.debug("     Appkey: " + appkey);
   179          mLogger.debug("     BlogId: " + blogid);
   180          mLogger.debug("     UserId: " + userid);
   181          mLogger.debug("       Type: " + templateType);
   182          
   183          validate(blogid, userid,password);
   184          
   185          try {
   186              Weblogger roller = WebloggerFactory.getWeblogger();
   187              UserManager userMgr = roller.getUserManager();
   188              WeblogTemplate page = userMgr.getPage(templateType);
   189              
   190              if ( null == page ) {
   191                  throw new XmlRpcException(UNKNOWN_EXCEPTION,"Template not found");
   192              } else {
   193                  return page.getContents();
   194              }
   195          } catch (Exception e) {
   196              String msg = "ERROR in BlooggerAPIHander.getTemplate";
   197              mLogger.error(msg,e);
   198              throw new XmlRpcException(UNKNOWN_EXCEPTION,msg);
   199          }
   200      }
   201      
   202      
   203      /**
   204       * Authenticates a user and returns basic user info (name, email, userid, etc.)
   205       *
   206       * @param appkey Unique identifier/passcode of the application sending the post
   207       * @param userid Login for a Blogger user who has permission to post to the blog
   208       * @param password Password for said username
   209       * @throws XmlRpcException
   210       * @return
   211       */
   212      public Object getUserInfo(String appkey, String userid, String password)
   213      throws Exception {
   214          
                 /* 
    P/P           *  Method: Object getUserInfo(String, String, String)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.UserManager:getUserByUserName(...)@224 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@223 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@222 != null
                  * 
                  *  Postconditions:
                  *    return_value == &new Hashtable(getUserInfo#6)
                  *    new Hashtable(getUserInfo#6) num objects == 1
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@235: {1}, {0}
                  *    java.util.StringTokenizer:hasMoreTokens(...)@230: {0}, {1}
                  *    java.util.StringTokenizer:hasMoreTokens(...)@234: {0}, {1}
                  */
   215          mLogger.debug("getUserInfo() Called =====[ SUPPORTED ]=====");
   216          mLogger.debug("     Appkey: " + appkey);
   217          mLogger.debug("     UserId: " + userid);
   218          
   219          validateUser(userid, password);
   220          
   221          try {
   222              Weblogger roller = WebloggerFactory.getWeblogger();
   223              UserManager userMgr = roller.getUserManager();
   224              User user = userMgr.getUserByUserName(userid);
   225              
   226              // parses full name into two strings, firstname and lastname
   227              String firstname = "", lastname = "";
   228              StringTokenizer toker = new StringTokenizer(user.getFullName());
   229              
   230              if (toker.hasMoreTokens()) {
   231                  firstname = toker.nextToken();
   232              }
   233              
   234              while (toker.hasMoreTokens()) {
   235                  if ( !lastname.equals("") ) {
   236                      lastname += " ";
   237                  }
   238                  lastname += toker.nextToken();
   239              }
   240  
   241              // TODO: Should screen name be renamed nickname and used here?
   242              // populates user information to return as a result
   243              Hashtable result = new Hashtable();
   244              result.put("nickname", user.getUserName());
   245              result.put("userid", user.getUserName());
   246              result.put("email", "");
   247              result.put("lastname", lastname);
   248              result.put("firstname", firstname);
   249              
   250              return result;
   251          } catch (WebloggerException e) {
   252              String msg = "ERROR in BlooggerAPIHander.getInfo";
   253              mLogger.error(msg,e);
   254              throw new XmlRpcException(UNKNOWN_EXCEPTION,msg);
   255          }
   256      }
   257      
   258      
   259      /**
   260       * Returns information on all the blogs a given user is a member of
   261       *
   262       * @param appkey Unique identifier/passcode of the application sending the post
   263       * @param userid Login for a Blogger user who has permission to post to the blog
   264       * @param password Password for said username
   265       * @throws XmlRpcException
   266       * @return
   267       */
   268      public Object getUsersBlogs(String appkey, String userid, String password)
   269      throws Exception {
   270          
                 /* 
    P/P           *  Method: Object getUsersBlogs(String, String, String)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  * 
                  *  Presumptions:
                  *    java.lang.Boolean.TRUE != null
                  *    java.util.Iterator:next(...)@287 != null
                  *    org.apache.roller.weblogger.business.UserManager:getWebsites(...)@284 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@280 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@280 != null
                  * 
                  *  Postconditions:
                  *    return_value == &new Vector(getUsersBlogs#3)
                  *    new Vector(getUsersBlogs#3) num objects == 1
                  * 
                  *  Test Vectors:
                  *    java.lang.Boolean:equals(...)@290: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@286: {1}, {0}
                  */
   271          mLogger.debug("getUsersBlogs() Called ===[ SUPPORTED ]=======");
   272          mLogger.debug("     Appkey: " + appkey);
   273          mLogger.debug("     UserId: " + userid);
   274          
   275          Vector result = new Vector();
+  276          if (validateUser(userid, password)) {
   277              try {
+  278                  String contextUrl = WebloggerRuntimeConfig.getAbsoluteContextURL();
   279                  
   280                  UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
   281                  User user = umgr.getUserByUserName(userid);
   282                  
   283                  // get list of user's enabled websites
   284                  List websites = umgr.getWebsites(user, Boolean.TRUE, null, null, null, 0, -1);
   285                  Iterator iter = websites.iterator();
   286                  while (iter.hasNext()) {
   287                      Weblog website = (Weblog)iter.next();
   288                      
   289                      // only include weblog's that have client API support enabled
   290                      if (Boolean.TRUE.equals(website.getEnableBloggerApi())) {
   291                          Hashtable blog = new Hashtable(3);
   292                          blog.put("url", website.getURL());
   293                          blog.put("blogid", website.getHandle());
   294                          blog.put("blogName", website.getName());
   295                          result.add(blog);
   296                      }
   297                  }
   298              } catch (Exception e) {
   299                  String msg = "ERROR in BlooggerAPIHander.getUsersBlogs";
   300                  mLogger.error(msg,e);
   301                  throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
   302              }
   303          }
   304          return result;
   305      }
   306      
   307      
   308      /**
   309       * Edits a given post. Optionally, will publish the blog after making the edit
   310       *
   311       * @param appkey Unique identifier/passcode of the application sending the post
   312       * @param postid Unique identifier of the post to be changed
   313       * @param userid Login for a Blogger user who has permission to post to the blog
   314       * @param password Password for said username
   315       * @param content Contents of the post
   316       * @param publish If true, the blog will be published immediately after the post is made
   317       * @throws XmlRpcException
   318       * @return
   319       */
   320      public boolean editPost(String appkey, String postid, String userid,
   321              String password, String content, boolean publish)
   322              throws Exception {
   323          
                 /* 
    P/P           *  Method: bool editPost(String, String, String, String, String, bool)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  * 
                  *  Presumptions:
                  *    java.lang.Boolean:valueOf(...)@340 != null
                  *    org.apache.roller.weblogger.business.WeblogManager:getWeblogEntry(...)@337 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@336 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@335 != null
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  * 
                  *  Test Vectors:
                  *    java.lang.Boolean:booleanValue(...)@340: {0}, {1}
                  */
   324          mLogger.debug("editPost() Called ========[ SUPPORTED ]=====");
   325          mLogger.debug("     Appkey: " + appkey);
   326          mLogger.debug("     PostId: " + postid);
   327          mLogger.debug("     UserId: " + userid);
   328          mLogger.debug("    Publish: " + publish);
   329          mLogger.debug("     Content:\n " + content);
   330          
+  331          if (validateUser(userid, password)) {
   332              try {
   333                  Timestamp current = new Timestamp(System.currentTimeMillis());
   334                  
   335                  Weblogger roller = WebloggerFactory.getWeblogger();
   336                  WeblogManager weblogMgr = roller.getWeblogManager();
   337                  WeblogEntry entry = weblogMgr.getWeblogEntry(postid);
   338                  entry.setText(content);
   339                  entry.setUpdateTime(current);
   340                  if (Boolean.valueOf(publish).booleanValue()) {
   341                      entry.setStatus(WeblogEntry.PUBLISHED);
   342                  } else {
   343                      entry.setStatus(WeblogEntry.DRAFT);
   344                  }
   345                  
   346                  // save the entry
   347                  weblogMgr.saveWeblogEntry(entry);
   348                  roller.flush();
   349                  
   350                  // notify cache
   351                  flushPageCache(entry.getWebsite());
   352                  
   353                  return true;
   354              } catch (Exception e) {
   355                  String msg = "ERROR in BlooggerAPIHander.editPost";
   356                  mLogger.error(msg,e);
   357                  throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
   358              }
   359          }
+  360          return false;
   361      }
   362      
   363      
   364      /**
   365       * Makes a new post to a designated blog. Optionally, will publish the blog after making the post
   366       *
   367       * @param appkey Unique identifier/passcode of the application sending the post
   368       * @param blogid Unique identifier of the blog the post will be added to
   369       * @param userid Login for a Blogger user who has permission to post to the blog
   370       * @param password Password for said username
   371       * @param content Contents of the post
   372       * @param publish If true, the blog will be published immediately after the post is made
   373       * @throws XmlRpcException
   374       * @return
   375       */
   376      public String newPost(String appkey, String blogid, String userid,
   377              String password, String content, boolean publish)
   378              throws Exception {
   379          
                 /* 
    P/P           *  Method: String newPost(String, String, String, String, String, bool)
                  * 
                  *  Preconditions:
                  *    content != null
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  *    (soft) password != null
                  * 
                  *  Presumptions:
                  *    java.lang.Boolean:valueOf(...)@419 != null
                  *    java.lang.String:indexOf(...)@393 <= 232-8
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@414 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@404 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@403 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    java.lang.Boolean:booleanValue(...)@419: {0}, {1}
                  *    java.lang.String:indexOf(...)@392: {-1}, {-231..-2, 0..232-1}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@398: {0}, {1}
                  */
   380          mLogger.debug("newPost() Called ===========[ SUPPORTED ]=====");
   381          mLogger.debug("     Appkey: " + appkey);
   382          mLogger.debug("     BlogId: " + blogid);
   383          mLogger.debug("     UserId: " + userid);
   384          mLogger.debug("    Publish: " + publish);
   385          mLogger.debug("    Content:\n " + content);
   386          
   387          Weblog website = validate(blogid, userid, password);
   388          
   389          // extract the title from the content
   390          String title = "";
   391          
   392          if (content.indexOf("<title>") != -1) {
   393              title =
   394                      content.substring(content.indexOf("<title>") + 7,
   395                      content.indexOf("</title>"));
   396              content = StringUtils.replace(content, "<title>"+title+"</title>", "");
   397          }
   398          if (StringUtils.isEmpty(title)) {
   399              title = Utilities.truncateNicely(content, 15, 15, "...");
   400          }
   401          
   402          try {
   403              Weblogger roller = WebloggerFactory.getWeblogger();
   404              WeblogManager weblogMgr = roller.getWeblogManager();
   405              
   406              Timestamp current = new Timestamp(System.currentTimeMillis());
   407              
   408              WeblogEntry entry = new WeblogEntry();
   409              entry.setTitle(title);
   410              entry.setText(content);
   411              entry.setLocale(website.getLocale());
   412              entry.setPubTime(current);
   413              entry.setUpdateTime(current);
   414              User user = roller.getUserManager().getUserByUserName(userid);
   415              entry.setCreator(user);
   416              entry.setWebsite(website);
   417              entry.setCategory(website.getBloggerCategory());
   418              entry.setCommentDays(new Integer(website.getDefaultCommentDays()));
   419              if (Boolean.valueOf(publish).booleanValue()) {
   420                  entry.setStatus(WeblogEntry.PUBLISHED);
   421              } else {
   422                  entry.setStatus(WeblogEntry.DRAFT);
   423              }
   424              
   425              // save the entry
   426              weblogMgr.saveWeblogEntry(entry);
   427              roller.flush();
   428              
   429              // notify cache
   430              flushPageCache(entry.getWebsite());
   431              
   432              return entry.getId();
   433          } catch (Exception e) {
   434              String msg = "ERROR in BlooggerAPIHander.newPost";
   435              mLogger.error(msg,e);
   436              throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
   437          }
   438      }
   439      
   440      
   441      /**
   442       * This method was added to the Blogger 1.0 API via an Email from Evan
   443       * Williams to the Yahoo Group bloggerDev, see the email message for details -
   444       * http://groups.yahoo.com/group/bloggerDev/message/225
   445       *
   446       * @param appkey Unique identifier/passcode of the application sending the post
   447       * @param blogid Unique identifier of the blog the post will be added to
   448       * @param userid Login for a Blogger user who has permission to post to the blog
   449       * @param password Password for said username
   450       * @param numposts Number of Posts to Retrieve
   451       * @throws XmlRpcException
   452       * @return Vector of Hashtables, each containing dateCreated, userid, postid, content
   453       */
   454      public Object getRecentPosts(String appkey, String blogid, String userid,
   455              String password, int numposts)
   456              throws Exception {
   457          
                 /* 
    P/P           *  Method: Object getRecentPosts(String, String, String, String, int)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    (soft) org/apache/roller/weblogger/webservices/xmlrpc/BaseAPIHandler.mLogger != null
                  *    (soft) password != null
                  * 
                  *  Presumptions:
                  *    java.util.ArrayList:iterator(...)@483 != null
                  *    java.util.Iterator:next(...)@482 != null
                  *    java.util.Iterator:next(...)@485 != null
                  *    java.util.Map:values(...)@480 != null
                  *    org.apache.roller.weblogger.business.WeblogManager:getWeblogEntryObjectMap(...)@472 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    return_value == &new Vector(getRecentPosts#5)
                  *    new Vector(getRecentPosts#5) num objects == 1
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@481: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@484: {0}, {1}
                  *    org.apache.roller.weblogger.pojos.WeblogEntry:getPubTime(...)@487: Addr_Set{null}, Inverse{null}
                  */
   458          mLogger.debug("getRecentPosts() Called ===========[ SUPPORTED ]=====");
   459          mLogger.debug("     Appkey: " + appkey);
   460          mLogger.debug("     BlogId: " + blogid);
   461          mLogger.debug("     UserId: " + userid);
   462          mLogger.debug("     Number: " + numposts);
   463          
   464          Weblog website = validate(blogid, userid,password);
   465          
   466          try {
   467              Vector results = new Vector();
   468              
   469              Weblogger roller = WebloggerFactory.getWeblogger();
   470              WeblogManager weblogMgr = roller.getWeblogManager();
+  471              if (website != null) {
   472                  Map entries = weblogMgr.getWeblogEntryObjectMap(
   473                          website,                // website
   474                          null,                   // startDate
   475                          new Date(),             // endDate
   476                          null,                   // catName
   477                          null,                   // tags
   478                          null, null, 0, -1);
   479                  
   480                  Iterator iter = entries.values().iterator();
   481                  while (iter.hasNext()) {
   482                      ArrayList list = (ArrayList) iter.next();
   483                      Iterator i = list.iterator();
   484                      while (i.hasNext()) {
   485                          WeblogEntry entry = (WeblogEntry) i.next();
   486                          Hashtable result = new Hashtable();
   487                          if (entry.getPubTime() != null) {
   488                              result.put("dateCreated", entry.getPubTime());
   489                          }
   490                          result.put("userid", userid);
   491                          result.put("postid", entry.getId());
   492                          result.put("content", entry.getText());
   493                          results.add(result);
   494                      }
   495                  }
   496              }
   497              return results;
   498          } catch (Exception e) {
   499              String msg = "ERROR in BlooggerAPIHander.getRecentPosts";
   500              mLogger.error(msg,e);
   501              throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
   502          }
   503      }
   504      
   505  }








SofCheck Inspector Build Version : 2.18479
BloggerAPIHandler.java 2009-Jan-02 14:25:28
BloggerAPIHandler.class 2009-Sep-04 03:12:46