⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bloggerapihandler.java

📁 pebble-blog 博客源码博客源码博客源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @param content   the new content of the new blog entry   * @param publish   a flag to indicate whether the entry should be published   *                  (this is ignored as all new entries are published)   * @return  a boolean true value to signal success   * @throws XmlRpcException    if something goes wrong, including an authentication error   */  public boolean editPost(String appkey, String postid, String username, String password, String content, boolean publish) throws XmlRpcException {    log.debug("BloggerAPI.editPost(" +        appkey + ", " +        postid + ", " +        username + ", " +        "********, " +        content + ", " +        publish + ")");    try {      Blog blog = getBlogWithPostId(postid);      postid = getPostId(postid);      authenticate(blog, username, password);      BlogService service = new BlogService();      BlogEntry entry = service.getBlogEntry(blog, postid);      if (entry != null) {        populateEntry(entry, content, username);        entry.setPublished(publish);        service.putBlogEntry(entry);      } else {        throw new XmlRpcException(0, "Blog entry with ID of " + postid + " was not found.");      }      return true;    } catch (BlogServiceException be) {      throw new XmlRpcException(0, be.getMessage());    }  }  /**   * Deletes an existing blog entry.   *   * @param appkey    the client application key (ignored)   * @param postid    the ID of the blog entry to be edited   * @param username  the username used for logging in via XML-RPC   * @param password  the password used for logging in via XML-RPC   * @param publish   a flag to indicate whether the entry should be published   *                  (this is ignored)   * @return  a boolean true value to signal success   * @throws XmlRpcException    if something goes wrong, including an authentication error   */  public boolean deletePost(String appkey, String postid, String username, String password, boolean publish) throws XmlRpcException {    log.debug("BloggerAPI.deletePost(" +        appkey + ", " +        postid + ", " +        username + ", " +        "********, " +        publish + ")");    try {      Blog blog = getBlogWithPostId(postid);      postid = getPostId(postid);      authenticate(blog, username, password);      BlogService service = new BlogService();      BlogEntry blogEntry = service.getBlogEntry(blog, postid);      if (blogEntry != null) {        service.removeBlogEntry(blogEntry);        return true;      } else {        throw new XmlRpcException(0, "Blog entry with ID of " + postid + " was not found.");      }    } catch (BlogServiceException be) {      throw new XmlRpcException(0, be.getMessage());    }  }  /**   * Helper method to adapt a blog entry into an XML-RPC compatible struct.   * Since the Blogger API doesn't support titles, the title is wrapped in   * &lt;title&gt;&lt;/title&gt; tags.   *   * @param entry   the BlogEntry to adapt   * @return  a Hashtable representing the major properties of the entry   */  private Hashtable adaptBlogEntry(BlogEntry entry) {    Hashtable post = new Hashtable();    String categories = "";    Iterator it = entry.getCategories().iterator();    while (it.hasNext()) {      Category category = (Category)it.next();      categories += category.getId();      if (it.hasNext()) {        categories += ",";      }    }    post.put(DATE_CREATED, entry.getDate());    post.put(USER_ID, entry.getAuthor());    post.put(POST_ID, formatPostId(entry.getBlog().getId(), entry.getId()));    post.put(CONTENT, TITLE_START_DELIMITER + entry.getTitle() + TITLE_END_DELIMITER        + CATEGORY_START_DELIMITER + categories + CATEGORY_END_DELIMITER + entry.getBody());    return post;  }  /**   * Populates a given BlogEntry.   *   * @param entry     the BlogEntry to populate   * @param content   the content (including title)   * @param username  the author   */  private void populateEntry(BlogEntry entry, String content, String username) {    String title = "";    String category = "";    if (content.indexOf(TITLE_START_DELIMITER) > -1 && content.indexOf(TITLE_END_DELIMITER) > -1) {      content = content.substring(TITLE_START_DELIMITER.length());      int index = content.indexOf(TITLE_END_DELIMITER);      title = content.substring(0, index);      content = content.substring(index);      content = content.substring(TITLE_END_DELIMITER.length());    }    if (content.indexOf(CATEGORY_START_DELIMITER) > -1 && content.indexOf(CATEGORY_END_DELIMITER) > -1) {      content = content.substring(CATEGORY_START_DELIMITER.length());      int index = content.indexOf(CATEGORY_END_DELIMITER);      category = content.substring(0, index);      content = content.substring(index);      content = content.substring(CATEGORY_END_DELIMITER.length());    }    entry.setTitle(title);    entry.setBody(content);    entry.setAuthor(username);    if (category != null && !category.trim().equals("")) {      String[] categories = category.split(",");      for (int i = 0; i < categories.length; i++) {        Category c = entry.getBlog().getCategory(categories[i].trim());         if (c != null) {           entry.addCategory(c);         }      }    }  }  /**   * Gets the specified template type for a blog - not supported by Pebble.   *   * @param appkey    the client application key (ignored)   * @param blogid    the ID of the blog   * @param username  the username used for logging in via XML-RPC   * @param password  the password used for logging in via XML-RPC   * @param templateType  the type of template to retrieve   * @return  the text of the specified template   * @throws XmlRpcException   */  public String getTemplate(String appkey, String blogid, String username, String password, String templateType) throws XmlRpcException {    log.debug("BloggerAPI.getTemplate(" +        appkey + ", " +        blogid + ", " +        username + ", " +        "********, " +        templateType + ")");    throw new XmlRpcException(0, "getTemplate is not supported by Pebble.");  }  /**   * Sets the specified template type for a blog - not supported by Pebble.   *   * @param appkey    the client application key (ignored)   * @param blogid    the ID of the blog   * @param username  the username used for logging in via XML-RPC   * @param password  the password used for logging in via XML-RPC   * @param template  the new text of the template   * @param templateType  the type of template to retrieve   * @return  true if setting the template was successful, false otherwise   * @throws XmlRpcException   */  public boolean setTemplate(String appkey, String blogid, String username, String password, String template, String templateType) throws XmlRpcException {    log.debug("BloggerAPI.setTemplate(" +        appkey + ", " +        blogid + ", " +        username + ", " +        "********, " +        template + ", " +        templateType + ")");    throw new XmlRpcException(0, "setTemplate is not supported by Pebble.");  }  /**   * Adds a category to a blog entry - this isn't a standard Blogger API method.   *   * @param appkey    the client application key (ignored)   * @param postid    the ID of the blog entry to be edited   * @param username  the username used for logging in via XML-RPC   * @param password  the password used for logging in via XML-RPC   * @param category  the category ID   * @return  a boolean true value to signal success   * @throws XmlRpcException    if something goes wrong, including an authentication error   */  public boolean addCategory(String appkey, String postid, String username, String password, String category) throws XmlRpcException {    log.debug("BloggerAPI.addCategory(" +        appkey + ", " +        postid + ", " +        username + ", " +        "********, " +        category + ")");    try {      Blog blog = getBlogWithPostId(postid);      postid = getPostId(postid);      authenticate(blog, username, password);      BlogService service = new BlogService();      BlogEntry entry = service.getBlogEntry(blog, postid);      if (entry != null) {        Category c = entry.getBlog().getCategory(category);        if (c != null) {          entry.addCategory(c);          service.putBlogEntry(entry);          return true;        }      } else {        throw new XmlRpcException(0, "Blog entry with ID of " + postid + " was not found.");      }      return false;    } catch (BlogServiceException be) {      throw new XmlRpcException(0, be.getMessage());    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -