📄 metaweblogapihandler.java
字号:
if ( cat != null ) { // Use first category specified by request WeblogCategoryData cd = weblogMgr.getWeblogCategoryByPath(website, cat); entry.setCategory(cd); } else { // Use Blogger API category from user's weblog config entry.setCategory(website.getBloggerCategory()); } entry.save(); roller.commit(); flushPageCache(userid); // TODO: Roller timestamps need better than 1 second accuracy // Until then, we can't allow more than one post per second Thread.sleep(1000); return entry.getId(); } catch (Exception e) { String msg = "ERROR in MetaWeblogAPIHandler.newPost"; mLogger.error(msg,e); throw new XmlRpcException(UNKNOWN_EXCEPTION, msg); } } //------------------------------------------------------------------------ /** * * @param postid * @param userid * @param password * @return * @throws Exception */ public Object getPost(String postid, String userid, String password) throws Exception { mLogger.info("getPost() Called =========[ SUPPORTED ]====="); mLogger.info(" PostId: " + postid); mLogger.info(" UserId: " + userid); validate(userid,password); try { Roller roller = RollerRequest.getRollerRequest().getRoller(); WeblogManager weblogMgr = roller.getWeblogManager(); WeblogEntryData entry = weblogMgr.retrieveWeblogEntry(postid); return createPostStruct(entry); } catch (Exception e) { String msg = "ERROR in MetaWeblogAPIHandler.getPost"; mLogger.error(msg,e); throw new XmlRpcException(UNKNOWN_EXCEPTION, msg); } } //------------------------------------------------------------------------ /** * Allows user to post a binary object, a file, to Roller. If the file is * allowed by the RollerConfig file-upload settings, then the file will be * placed in the user's upload diretory. */ public Object newMediaObject( String blogid, String userid, String password, Hashtable struct) throws Exception { mLogger.debug("newMediaObject() Called =[ SUPPORTED ]====="); mLogger.debug(" BlogId: " + blogid); mLogger.debug(" UserId: " + userid); mLogger.debug(" Password: *********"); WebsiteData website = validate(userid, password); try { String name = (String) struct.get("name"); name = name.replaceAll("/","_"); String type = (String) struct.get("type"); mLogger.debug("newMediaObject name: " + name); mLogger.debug("newMediaObject type: " + type); byte[] bits = (byte[]) struct.get("bits"); Roller roller = RollerRequest.getRollerRequest().getRoller(); FileManager fmgr = roller.getFileManager(); RollerMessages msgs = new RollerMessages(); // If save is allowed by Roller system-wide policies if (fmgr.canSave(website, name, bits.length, msgs)) { // Then save the file fmgr.saveFile( website, name, bits.length, new ByteArrayInputStream(bits)); RollerRequest rreq = RollerRequest.getRollerRequest(); HttpServletRequest request = rreq.getRequest(); // TODO: build URL to uploaded file should be done in FileManager String uploadPath = RollerContext.getUploadPath( request.getSession(true).getServletContext()); uploadPath += "/" + website.getUser().getUserName() + "/" + name; String fileLink = RequestUtils.printableURL( RequestUtils.absoluteURL(request, uploadPath)); Hashtable returnStruct = new Hashtable(1); returnStruct.put("url", fileLink); return returnStruct; } throw new XmlRpcException(UPLOAD_DENIED_EXCEPTION, "File upload denied because:" + msgs.toString()); } catch (RollerException e) { String msg = "ERROR in BlooggerAPIHander.newMediaObject"; mLogger.error(msg,e); throw new XmlRpcException(UNKNOWN_EXCEPTION, msg); } } /** * Get a list of recent posts for a category * * @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 */ public Object getRecentPosts( String blogid, String userid, String password, int numposts) throws Exception { mLogger.info("getRecentPosts() Called ===========[ SUPPORTED ]====="); 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 entryIter = list.iterator(); while (entryIter.hasNext()) { WeblogEntryData entry = (WeblogEntryData)entryIter.next(); results.addElement(createPostStruct(entry)); } } } return results; } catch (Exception e) { String msg = "ERROR in BlooggerAPIHander.getRecentPosts"; mLogger.error(msg,e); throw new XmlRpcException(UNKNOWN_EXCEPTION, msg); } } private Hashtable createPostStruct(WeblogEntryData entry) { RollerRequest rreq = RollerRequest.getRollerRequest(); HttpServletRequest request = rreq.getRequest(); RollerContext rollerCtx = RollerContext.getRollerContext(request); String permalink = rollerCtx.getAbsoluteContextUrl(request) + entry.getPermaLink(); Hashtable struct = new Hashtable(); struct.put("title", entry.getTitle()); if (entry.getLink() != null) { struct.put("link", Utilities.escapeHTML(entry.getLink())); } struct.put("description", entry.getText()); struct.put("pubDate", entry.getPubTime()); struct.put("dateCreated", entry.getPubTime()); struct.put("guid", Utilities.escapeHTML(permalink)); struct.put("permaLink", Utilities.escapeHTML(permalink)); struct.put("postid", entry.getId()); struct.put("userid", entry.getWebsite().getUser().getId()); Vector catArray = new Vector(); catArray.addElement(entry.getCategory().getPath()); struct.put("categories", catArray); return struct; } private Hashtable createCategoryStruct(WeblogCategoryData category) { RollerRequest rreq = RollerRequest.getRollerRequest(); HttpServletRequest req = rreq.getRequest(); String contextUrl = RollerContext.getRollerContext(req).getAbsoluteContextUrl(req); String userid = category.getWebsite().getUser().getId(); Hashtable struct = new Hashtable(); struct.put("description", category.getPath()); String catUrl = contextUrl+"/page/"+userid+"?catname="+category.getPath(); catUrl = Utilities.stringReplace(catUrl," ","%20"); struct.put("htmlUrl", catUrl); String rssUrl = contextUrl+"/rss/"+userid+"?catname="+category.getPath(); rssUrl = Utilities.stringReplace(catUrl," ","%20"); struct.put("rssUrl",rssUrl); return struct; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -