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

📄 bloggerapihandler.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            return result;        }        catch (RollerException e)        {            String msg = "ERROR in BlooggerAPIHander.getInfo";            mLogger.error(msg,e);            throw new XmlRpcException(UNKNOWN_EXCEPTION,msg);        }    }    //------------------------------------------------------------------------    /**     * Returns information on all the blogs a given user is a member of     *     * @param appkey Unique identifier/passcode of the application sending the post     * @param userid Login for a Blogger user who has permission to post to the blog     * @param password Password for said username     * @throws XmlRpcException     * @return     */    public Object getUsersBlogs(String appkey, String userid, String password)                         throws Exception    {        mLogger.info("getUsersBlogs() Called ===[ SUPPORTED ]=======");        mLogger.info("     Appkey: " + appkey);        mLogger.info("     UserId: " + userid);        WebsiteData website = validate(userid,password);        try        {            RollerRequest rreq = RollerRequest.getRollerRequest();            HttpServletRequest req = rreq.getRequest();            String contextUrl =                RollerContext.getRollerContext(req).getAbsoluteContextUrl(req);            Hashtable blog = new Hashtable(3);            blog.put("url", contextUrl+"/page/"+userid);            blog.put("blogid", userid);            blog.put("blogName", website.getName());            Vector result = new Vector();            result.add(blog);            return result;        }        catch (Exception e)        {            String msg = "ERROR in BlooggerAPIHander.getUsersBlogs";            mLogger.error(msg,e);            throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);        }    }    //------------------------------------------------------------------------    /**     * Edits a given post. Optionally, will publish the blog after making the edit     *     * @param appkey Unique identifier/passcode of the application sending the post     * @param postid Unique identifier of the post to be changed     * @param userid Login for a Blogger user who has permission to post to the blog     * @param password Password for said username     * @param content Contents of the post     * @param publish If true, the blog will be published immediately after the post is made     * @throws XmlRpcException     * @return     */    public boolean editPost(String appkey, String postid, String userid,                            String password, String content, boolean publish)                     throws Exception    {        mLogger.info("editPost() Called ========[ SUPPORTED ]=====");        mLogger.info("     Appkey: " + appkey);        mLogger.info("     PostId: " + postid);        mLogger.info("     UserId: " + userid);        mLogger.info("    Publish: " + publish);        mLogger.info("     Content:\n " + content);        validate(userid,password);        try        {            Timestamp current = new Timestamp(System.currentTimeMillis());            Roller roller = RollerRequest.getRollerRequest().getRoller();            WeblogManager weblogMgr = roller.getWeblogManager();            WeblogEntryData entry = weblogMgr.retrieveWeblogEntry(postid);            entry.setText(content);            entry.setUpdateTime(current);            entry.setPublishEntry(Boolean.valueOf(publish));            entry.save();            roller.commit();            flushPageCache(userid);            return true;        }        catch (Exception e)        {            String msg = "ERROR in BlooggerAPIHander.editPost";            mLogger.error(msg,e);            throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);        }    }    //------------------------------------------------------------------------    /**     * Makes a new post to a designated blog. Optionally, will publish the blog after making the post     *     * @param appkey Unique identifier/passcode of the application sending the post     * @param blogid Unique identifier of the blog the post will be added to     * @param userid Login for a Blogger user who has permission to post to the blog     * @param password Password for said username     * @param content Contents of the post     * @param publish If true, the blog will be published immediately after the post is made     * @throws XmlRpcException     * @return     */    public String newPost(String appkey, String blogid, String userid,                          String password, String content, boolean publish)                   throws Exception    {        mLogger.info("newPost() Called ===========[ SUPPORTED ]=====");        mLogger.info("     Appkey: " + appkey);        mLogger.info("     BlogId: " + blogid);        mLogger.info("     UserId: " + userid);        mLogger.info("    Publish: " + publish);        mLogger.info("    Content:\n " + content);        WebsiteData website = validate(userid,password);        // extract the title from the content        String title = "";        if (content.indexOf("<title>") != -1)        {            title =                content.substring(content.indexOf("<title>") + 7,                                  content.indexOf("</title>"));            content = StringUtils.replace(content, "<title>"+title+"</title>", "");        }        try        {            RollerRequest rreq = RollerRequest.getRollerRequest();            Roller roller = rreq.getRoller();            Timestamp current = new Timestamp(System.currentTimeMillis());            WeblogEntryData entry = new WeblogEntryData();            entry.setTitle(title);            entry.setText(content);            entry.setPubTime(current);            entry.setUpdateTime(current);            entry.setWebsite(website);            entry.setPublishEntry(Boolean.valueOf(publish));            entry.setCategory(website.getBloggerCategory());            entry.save();            roller.commit();            flushPageCache(userid);/*            String blogUrl = Utilities.escapeHTML(                 RollerContext.getRollerContext(req).getAbsoluteContextUrl(req)                + "/page/" + userid);            RollerXmlRpcClient.sendWeblogsPing(                blogUrl,                entry.getWebsite().getName());*/            return entry.getId();        }        catch (Exception e)        {            String msg = "ERROR in BlooggerAPIHander.newPost";            mLogger.error(msg,e);            throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);        }    }    //------------------------------------------------------------------------    /**     * This method was added to the Blogger 1.0 API via an Email from Evan     * Williams to the Yahoo Group bloggerDev, see the email message for details -      * http://groups.yahoo.com/group/bloggerDev/message/225      *     * @param appkey Unique identifier/passcode of the application sending the post     * @param blogid Unique identifier of the blog the post will be added to     * @param userid Login for a Blogger user who has permission to post to the blog     * @param password Password for said username     * @param numposts Number of Posts to Retrieve     * @throws XmlRpcException     * @return Vector of Hashtables, each containing dateCreated, userid, postid, content     */    public Object getRecentPosts(        String appkey, String blogid, String userid, String password, int numposts)        throws Exception    {        mLogger.info("getRecentPosts() Called ===========[ SUPPORTED ]=====");        mLogger.info("     Appkey: " + appkey);        mLogger.info("     BlogId: " + blogid);        mLogger.info("     UserId: " + userid);        mLogger.info("     Number: " + numposts);        WebsiteData website = validate(userid,password);        try        {            Vector results = new Vector();            Roller roller = RollerRequest.getRollerRequest().getRoller();            WeblogManager weblogMgr = roller.getWeblogManager();            if (website != null)            {                Map entries = weblogMgr.getWeblogEntryObjectMap(                                website,                // userName                                null,                   // startDate                                new Date(),             // endDate                                null,                   // catName                                WeblogManager.ALL,      // status                                new Integer(numposts)); // maxEntries                                 Iterator iter = entries.values().iterator();                while (iter.hasNext())                {                    ArrayList list = (ArrayList) iter.next();                    Iterator i = list.iterator();                    while (i.hasNext())                    {                        WeblogEntryData entry = (WeblogEntryData) i.next();                            Hashtable result = new Hashtable();                            result.put("dateCreated", entry.getPubTime());                        result.put("userid", userid);                        result.put("postid", entry.getId());                        result.put("content", entry.getText());                                                results.add(result);                    }                }            }            return results;        }        catch (Exception e)        {            String msg = "ERROR in BlooggerAPIHander.getRecentPosts";            mLogger.error(msg,e);            throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);        }    }}

⌨️ 快捷键说明

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