roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r372765 - in /incubator/roller/trunk/src/org/roller/presentation/xmlrpc: BloggerAPIHandler.java MetaWeblogAPIHandler.java
Date Fri, 27 Jan 2006 06:06:08 GMT
Author: agilliland
Date: Thu Jan 26 22:06:06 2006
New Revision: 372765

URL: http://svn.apache.org/viewcvs?rev=372765&view=rev
Log:
code reformatting.


Modified:
    incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BloggerAPIHandler.java
    incubator/roller/trunk/src/org/roller/presentation/xmlrpc/MetaWeblogAPIHandler.java

Modified: incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BloggerAPIHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BloggerAPIHandler.java?rev=372765&r1=372764&r2=372765&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BloggerAPIHandler.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/xmlrpc/BloggerAPIHandler.java Thu Jan
26 22:06:06 2006
@@ -10,9 +10,7 @@
 import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.Vector;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -38,20 +36,17 @@
  *
  * @author David M Johnson
  */
-public class BloggerAPIHandler extends BaseAPIHandler
-{
+public class BloggerAPIHandler extends BaseAPIHandler {
+    
     static final long serialVersionUID = 2398898776655115019L;
     
-    private static Log mLogger =
-        LogFactory.getFactory().getInstance(RollerXMLRPCServlet.class);
-
-    public BloggerAPIHandler()
-    {
+    private static Log mLogger = LogFactory.getLog(BloggerAPIHandler.class);
+    
+    public BloggerAPIHandler() {
         super();
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Delete a Post
      *
@@ -64,28 +59,24 @@
      * @return
      */
     public boolean deletePost(String appkey, String postid, String userid,
-                              String password, boolean publish)
-                       throws Exception
-    {
+                            String password, boolean publish) throws Exception {
+        
         mLogger.info("deletePost() Called =====[ SUPPORTED ]=====");
         mLogger.info("     Appkey: " + appkey);
         mLogger.info("     PostId: " + postid);
         mLogger.info("     UserId: " + userid);
-
-        Roller roller = RollerFactory.getRoller(); 
+        
+        Roller roller = RollerFactory.getRoller();
         WeblogManager weblogMgr = roller.getWeblogManager();
         WeblogEntryData entry = weblogMgr.retrieveWeblogEntry(postid);
-
+        
         validate(entry.getWebsite().getHandle(), userid, password);
-
-        try
-        {
+        
+        try {
             entry.remove();
             roller.commit();
             flushPageCache(entry.getWebsite());
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in blogger.deletePost: "+e.getClass().getName();
             mLogger.error(msg,e);
             e.printStackTrace();
@@ -93,9 +84,8 @@
         }
         return true;
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Edits the main index template of a given blog. Roller only support
      * updating the main template, the default template of your weblog.
@@ -110,46 +100,41 @@
      * @return
      */
     public boolean setTemplate(String appkey, String blogid, String userid,
-                               String password, String templateData,
-                               String templateType) throws Exception
-    {
+                                String password, String templateData,
+                                String templateType) throws Exception {
+        
         mLogger.info("setTemplate() Called =====[ SUPPORTED ]=====");
         mLogger.info("     Appkey: " + appkey);
         mLogger.info("     BlogId: " + blogid);
         mLogger.info("     UserId: " + userid);
         mLogger.info("   Template: " + templateData);
         mLogger.info("       Type: " + templateType);
-
+        
         validate(blogid, userid, password);
-
-        if (! templateType.equals("main"))
-        {
+        
+        if (! templateType.equals("main")) {
             throw new XmlRpcException(
-                UNKNOWN_EXCEPTION, "Roller only supports main template");
+                    UNKNOWN_EXCEPTION, "Roller only supports main template");
         }
-
-        try
-        {
-            Roller roller = RollerFactory.getRoller(); 
+        
+        try {
+            Roller roller = RollerFactory.getRoller();
             UserManager userMgr = roller.getUserManager();
-
+            
             WeblogTemplate page = userMgr.retrievePage(templateType);
             page.setContents(templateData);
             userMgr.storePage(page);
             flushPageCache(page.getWebsite());
-
+            
             return true;
-        }
-        catch (RollerException e)
-        {
+        } catch (RollerException e) {
             String msg = "ERROR in BlooggerAPIHander.setTemplate";
             mLogger.error(msg,e);
             throw new XmlRpcException(UNKNOWN_EXCEPTION,msg);
         }
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Returns the main or archive index template of a given blog
      *
@@ -162,42 +147,35 @@
      * @return
      */
     public String getTemplate(String appkey, String blogid, String userid,
-                              String password, String templateType)
-                       throws Exception
-    {
+                                String password, String templateType)
+            throws Exception {
+        
         mLogger.info("getTemplate() Called =====[ SUPPORTED ]=====");
         mLogger.info("     Appkey: " + appkey);
         mLogger.info("     BlogId: " + blogid);
         mLogger.info("     UserId: " + userid);
         mLogger.info("       Type: " + templateType);
-
+        
         validate(blogid, userid,password);
-
-        try
-        {
-            Roller roller = RollerFactory.getRoller(); 
+        
+        try {
+            Roller roller = RollerFactory.getRoller();
             UserManager userMgr = roller.getUserManager();
             WeblogTemplate page = userMgr.retrievePage(templateType);
-
-            if ( null == page )
-            {
+            
+            if ( null == page ) {
                 throw new XmlRpcException(UNKNOWN_EXCEPTION,"Template not found");
-            }
-            else
-            {
+            } else {
                 return page.getContents();
             }
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in BlooggerAPIHander.getTemplate";
             mLogger.error(msg,e);
             throw new XmlRpcException(UNKNOWN_EXCEPTION,msg);
         }
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Authenticates a user and returns basic user info (name, email, userid, etc.)
      *
@@ -208,42 +186,38 @@
      * @return
      */
     public Object getUserInfo(String appkey, String userid, String password)
-                       throws Exception
-    {
+            throws Exception {
+        
         mLogger.info("getUserInfo() Called =====[ SUPPORTED ]=====");
         mLogger.info("     Appkey: " + appkey);
         mLogger.info("     UserId: " + userid);
-
+        
         validateUser(userid, password);
-
-        try
-        {
-            Roller roller = RollerFactory.getRoller(); 
+        
+        try {
+            Roller roller = RollerFactory.getRoller();
             UserManager userMgr = roller.getUserManager();
             UserData user = userMgr.getUser(userid);
-
+            
             // parses full name into two strings, firstname and lastname
             String firstname = "", lastname = "";
             StringTokenizer toker = new StringTokenizer(user.getFullName());
-
-            if (toker.hasMoreTokens())
-            {
+            
+            if (toker.hasMoreTokens()) {
                 firstname = toker.nextToken();
             }
-
-            while (toker.hasMoreTokens())
-            {
-                if ( !lastname.equals("") )
-                {
+            
+            while (toker.hasMoreTokens()) {
+                if ( !lastname.equals("") ) {
                     lastname += " ";
                 }
                 lastname += toker.nextToken();
             }
-
+            
             RollerRequest rreq = RollerRequest.getRollerRequest();
             HttpServletRequest req = rreq.getRequest();
             String contextUrl =
-                RollerContext.getRollerContext().getAbsoluteContextUrl(req);
+                    RollerContext.getRollerContext().getAbsoluteContextUrl(req);
             
             // populates user information to return as a result
             Hashtable result = new Hashtable();
@@ -253,19 +227,16 @@
             result.put("email", "");
             result.put("lastname", lastname);
             result.put("firstname", firstname);
-
+            
             return result;
-        }
-        catch (RollerException e)
-        {
+        } 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
      *
@@ -276,38 +247,33 @@
      * @return
      */
     public Object getUsersBlogs(String appkey, String userid, String password)
-                         throws Exception
-    {
+            throws Exception {
+        
         mLogger.info("getUsersBlogs() Called ===[ SUPPORTED ]=======");
         mLogger.info("     Appkey: " + appkey);
         mLogger.info("     UserId: " + userid);
         
         Vector result = new Vector();
-        if (validateUser(userid, password))
-        {
-            try
-            {
+        if (validateUser(userid, password)) {
+            try {
                 RollerRequest rreq = RollerRequest.getRollerRequest();
                 HttpServletRequest req = rreq.getRequest();
                 String contextUrl =
-                    RollerContext.getRollerContext().getAbsoluteContextUrl(req);
+                        RollerContext.getRollerContext().getAbsoluteContextUrl(req);
                 
                 UserManager umgr = RollerFactory.getRoller().getUserManager();
                 UserData user = umgr.getUser(userid);
                 List websites = umgr.getWebsites(user, Boolean.TRUE);
                 Iterator iter = websites.iterator();
-                while (iter.hasNext())
-                {
+                while (iter.hasNext()) {
                     WebsiteData website = (WebsiteData)iter.next();
                     Hashtable blog = new Hashtable(3);
                     blog.put("url", contextUrl+"/page/"+website.getHandle());
                     blog.put("blogid", website.getHandle());
-                    blog.put("blogName", website.getName());   
-                    result.add(blog);                    
+                    blog.put("blogName", website.getName());
+                    result.add(blog);
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 String msg = "ERROR in BlooggerAPIHander.getUsersBlogs";
                 mLogger.error(msg,e);
                 throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
@@ -315,9 +281,8 @@
         }
         return result;
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Edits a given post. Optionally, will publish the blog after making the edit
      *
@@ -332,42 +297,35 @@
      */
     public boolean editPost(String appkey, String postid, String userid,
                             String password, String content, boolean publish)
-                     throws Exception
-    {
+            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);
-
-        if (validateUser(userid, password))
-        {
-            try
-            {
+        
+        if (validateUser(userid, password)) {
+            try {
                 Timestamp current = new Timestamp(System.currentTimeMillis());
-    
-                Roller roller = RollerFactory.getRoller(); 
+                
+                Roller roller = RollerFactory.getRoller();
                 WeblogManager weblogMgr = roller.getWeblogManager();
                 WeblogEntryData entry = weblogMgr.retrieveWeblogEntry(postid);
                 entry.setText(content);
                 entry.setUpdateTime(current);
-                if (Boolean.valueOf(publish).booleanValue())
-                {
+                if (Boolean.valueOf(publish).booleanValue()) {
                     entry.setStatus(WeblogEntryData.PUBLISHED);
-                }
-                else
-                {
+                } else {
                     entry.setStatus(WeblogEntryData.DRAFT);
                 }
-    
+                
                 entry.save();
                 roller.commit();
                 flushPageCache(entry.getWebsite());
                 return true;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 String msg = "ERROR in BlooggerAPIHander.editPost";
                 mLogger.error(msg,e);
                 throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
@@ -375,9 +333,8 @@
         }
         return false;
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Makes a new post to a designated blog. Optionally, will publish the blog after making
the post
      *
@@ -391,36 +348,34 @@
      * @return
      */
     public String newPost(String appkey, String blogid, String userid,
-                          String password, String content, boolean publish)
-                   throws Exception
-    {
+                            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(blogid, userid,password);
-
+        
         // extract the title from the content
         String title = "";
-
-        if (content.indexOf("<title>") != -1)
-        {
+        
+        if (content.indexOf("<title>") != -1) {
             title =
-                content.substring(content.indexOf("<title>") + 7,
-                                  content.indexOf("</title>"));
+                    content.substring(content.indexOf("<title>") + 7,
+                    content.indexOf("</title>"));
             content = StringUtils.replace(content, "<title>"+title+"</title>",
"");
         }
-
-        try
-        {
+        
+        try {
             RollerRequest rreq = RollerRequest.getRollerRequest();
             Roller roller = RollerFactory.getRoller();
-
+            
             Timestamp current = new Timestamp(System.currentTimeMillis());
-
+            
             WeblogEntryData entry = new WeblogEntryData();
             entry.setTitle(title);
             entry.setText(content);
@@ -429,41 +384,35 @@
             entry.setCreator(roller.getUser());
             entry.setWebsite(website);
             entry.setCategory(website.getBloggerCategory());
-            if (Boolean.valueOf(publish).booleanValue())
-            {
+            if (Boolean.valueOf(publish).booleanValue()) {
                 entry.setStatus(WeblogEntryData.PUBLISHED);
-            }
-            else
-            {
+            } else {
                 entry.setStatus(WeblogEntryData.DRAFT);
             }
             entry.save();
             roller.commit();
             flushPageCache(entry.getWebsite());
 /*
-            String blogUrl = Utilities.escapeHTML( 
+            String blogUrl = Utilities.escapeHTML(
                 RollerContext.getRollerContext(req).getAbsoluteContextUrl(req)
                 + "/page/" + userid);
             RollerXmlRpcClient.sendWeblogsPing(
                 blogUrl,
                 entry.getWebsite().getName());
-*/
+ */
             return entry.getId();
-        }
-        catch (Exception e)
-        {
+        } 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 
+     * 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
@@ -473,58 +422,53 @@
      * @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
-    {
+    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(blogid, userid,password);
-
-        try
-        {
+        
+        try {
             Vector results = new Vector();
-
-            Roller roller = RollerFactory.getRoller(); 
+            
+            Roller roller = RollerFactory.getRoller();
             WeblogManager weblogMgr = roller.getWeblogManager();
-            if (website != null)
-            {
+            if (website != null) {
                 Map entries = weblogMgr.getWeblogEntryObjectMap(
-                                website,                // userName
-                                null,                   // startDate
-                                new Date(),             // endDate
-                                null,                   // catName
-                                null,      // status
-                                new Integer(numposts)); // maxEntries 
+                        website,                // userName
+                        null,                   // startDate
+                        new Date(),             // endDate
+                        null,                   // catName
+                        null,      // status
+                        new Integer(numposts)); // maxEntries
                 
                 Iterator iter = entries.values().iterator();
-                while (iter.hasNext())
-                {
+                while (iter.hasNext()) {
                     ArrayList list = (ArrayList) iter.next();
                     Iterator i = list.iterator();
-                    while (i.hasNext())
-                    {
-                        WeblogEntryData entry = (WeblogEntryData) i.next();    
-                        Hashtable result = new Hashtable();    
+                    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());                        
+                        result.put("content", entry.getText());
                         results.add(result);
                     }
                 }
             }
             return results;
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in BlooggerAPIHander.getRecentPosts";
             mLogger.error(msg,e);
             throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
         }
     }
+    
 }

Modified: incubator/roller/trunk/src/org/roller/presentation/xmlrpc/MetaWeblogAPIHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/xmlrpc/MetaWeblogAPIHandler.java?rev=372765&r1=372764&r2=372765&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/xmlrpc/MetaWeblogAPIHandler.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/xmlrpc/MetaWeblogAPIHandler.java Thu
Jan 26 22:06:06 2006
@@ -10,9 +10,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.util.RequestUtils;
@@ -39,20 +37,17 @@
  *
  * @author David M Johnson
  */
-public class MetaWeblogAPIHandler extends BloggerAPIHandler
-{
+public class MetaWeblogAPIHandler extends BloggerAPIHandler {
+    
     static final long serialVersionUID = -1364456614935668629L;
     
-    private static Log mLogger =
-        LogFactory.getFactory().getInstance(MetaWeblogAPIHandler.class);
-
-    public MetaWeblogAPIHandler()
-    {
+    private static Log mLogger = LogFactory.getLog(MetaWeblogAPIHandler.class);
+    
+    public MetaWeblogAPIHandler() {
         super();
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Authenticates a user and returns the categories available in the website
      *
@@ -63,37 +58,33 @@
      * @return
      */
     public Object getCategories(String blogid, String userid, String password)
-                         throws Exception
-    {
+            throws Exception {
+        
         mLogger.info("getCategories() Called =====[ SUPPORTED ]=====");
         mLogger.info("     BlogId: " + blogid);
         mLogger.info("     UserId: " + userid);
-
+        
         WebsiteData website = validate(blogid, userid,password);
         RollerRequest rreq = RollerRequest.getRollerRequest();
         Roller roller = RollerFactory.getRoller();
-        try
-        {
+        try {
             Hashtable result = new Hashtable();
             WeblogManager weblogMgr = roller.getWeblogManager();
             List cats = weblogMgr.getWeblogCategories(website, false);
             for (Iterator wbcItr = cats.iterator(); wbcItr.hasNext();) {
                 WeblogCategoryData category = (WeblogCategoryData) wbcItr.next();
-                result.put(category.getPath(), 
-                           createCategoryStruct(category, userid));
+                result.put(category.getPath(),
+                        createCategoryStruct(category, userid));
             }
             return result;
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in MetaWeblogAPIHandler.getCategories";
             mLogger.error(msg,e);
             throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
         }
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      * Edits a given post. Optionally, will publish the blog after making the edit
      *
@@ -106,93 +97,83 @@
      * @return
      */
     public boolean editPost(String postid, String userid, String password,
-                            Hashtable struct, int publish)
-                     throws Exception {
+                            Hashtable struct, int publish) throws Exception {
+        
         return editPost(postid, userid, password, struct, publish > 0);
     }
-
+    
+    
     public boolean editPost(String postid, String userid, String password,
-                            Hashtable struct, boolean publish)
-                     throws Exception
-    {
+            Hashtable struct, boolean publish) throws Exception {
+        
         mLogger.info("editPost() Called ========[ SUPPORTED ]=====");
         mLogger.info("     PostId: " + postid);
         mLogger.info("     UserId: " + userid);
         mLogger.info("    Publish: " + publish);
-
-        Roller roller = RollerFactory.getRoller(); 
+        
+        Roller roller = RollerFactory.getRoller();
         WeblogManager weblogMgr = roller.getWeblogManager();
         WeblogEntryData entry = weblogMgr.retrieveWeblogEntry(postid);
-
+        
         validate(entry.getWebsite().getHandle(), userid,password);
-
+        
         Hashtable postcontent = struct;
         String description = (String)postcontent.get("description");
         String title = (String)postcontent.get("title");
         if (title == null) title = "";
-
+        
         Date dateCreated = (Date)postcontent.get("dateCreated");
         if (dateCreated == null) dateCreated = (Date)postcontent.get("pubDate");
-
+        
         String cat = null;
-        if ( postcontent.get("categories") != null )
-        {
+        if ( postcontent.get("categories") != null ) {
             Vector cats = (Vector)postcontent.get("categories");
             cat = (String)cats.elementAt(0);
         }
         mLogger.info("      Title: " + title);
         mLogger.info("   Category: " + cat);
-
-        try
-        {
-
+        
+        try {
+            
             Timestamp current =
-                new Timestamp(System.currentTimeMillis());
-
+                    new Timestamp(System.currentTimeMillis());
+            
             if ( !title.equals("") ) entry.setTitle(title);
             entry.setText(description);
             entry.setUpdateTime(current);
-            if (Boolean.valueOf(publish).booleanValue())
-            {
+            if (Boolean.valueOf(publish).booleanValue()) {
                 entry.setStatus(WeblogEntryData.PUBLISHED);
-            }
-            else
-            {
+            } else {
                 entry.setStatus(WeblogEntryData.DRAFT);
             }
-            if (dateCreated != null) 
-            {
+            if (dateCreated != null) {
                 entry.setPubTime(new Timestamp(dateCreated.getTime()));
             }
-
-            if ( cat != null )
-            {
+            
+            if ( cat != null ) {
                 // Use first category specified by request
-                WeblogCategoryData cd = 
-                    weblogMgr.getWeblogCategoryByPath(entry.getWebsite(), cat);
+                WeblogCategoryData cd =
+                        weblogMgr.getWeblogCategoryByPath(entry.getWebsite(), cat);
                 entry.setCategory(cd);
             }
-
+            
             entry.save();
             roller.commit();
             flushPageCache(entry.getWebsite());
-
+            
             // 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 true;
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in MetaWeblogAPIHandler.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
      *
@@ -204,53 +185,50 @@
      * @throws org.apache.xmlrpc.XmlRpcException
      * @return
      */
-    public String newPost(
-        String blogid, String userid, String password, Hashtable struct, int publish)
-        throws Exception {
+    public String newPost(String blogid, String userid, String password, 
+                            Hashtable struct, int publish) throws Exception {
+        
         return newPost(blogid, userid, password, struct, publish > 0);
     }
     
-    public String newPost(
-        String blogid, String userid, String password, Hashtable struct, boolean publish)
-        throws Exception
-    {
+    
+    public String newPost(String blogid, String userid, String password, 
+                            Hashtable struct, boolean publish) throws Exception {
+        
         mLogger.info("newPost() Called ===========[ SUPPORTED ]=====");
         mLogger.info("     BlogId: " + blogid);
         mLogger.info("     UserId: " + userid);
         mLogger.info("    Publish: " + publish);
-
+        
         WebsiteData website = validate(blogid, userid, password);
-
+        
         Hashtable postcontent = struct;
         String description = (String)postcontent.get("description");
         String title = (String)postcontent.get("title");
         if (title == null) title = "";
-
+        
         Date dateCreated = (Date)postcontent.get("dateCreated");
         if (dateCreated == null) dateCreated = (Date)postcontent.get("pubDate");
         if (dateCreated == null) dateCreated = new Date();
-
+        
         String cat = null;
-        if ( postcontent.get("categories") != null )
-        {
+        if ( postcontent.get("categories") != null ) {
             Vector cats = (Vector)postcontent.get("categories");
-            if (cats.size() > 0) 
-            {
+            if (cats.size() > 0) {
                 // only use the first category passed in
                 cat = (String)cats.elementAt(0);
             }
         }
         mLogger.info("      Title: " + title);
         mLogger.info("   Category: " + cat);
-
-        try
-        {
-            Roller roller = RollerFactory.getRoller(); 
+        
+        try {
+            Roller roller = RollerFactory.getRoller();
             WeblogManager weblogMgr = roller.getWeblogManager();
             UserData user = roller.getUserManager().getUser(userid);
             Timestamp current =
-                new Timestamp(System.currentTimeMillis());
-
+                    new Timestamp(System.currentTimeMillis());
+            
             WeblogEntryData entry = new WeblogEntryData();
             entry.setTitle(title);
             entry.setText(description);
@@ -258,49 +236,40 @@
             entry.setUpdateTime(current);
             entry.setWebsite(website);
             entry.setCreator(user);
-            if (Boolean.valueOf(publish).booleanValue())
-            {
+            if (Boolean.valueOf(publish).booleanValue()) {
                 entry.setStatus(WeblogEntryData.PUBLISHED);
-            }
-            else
-            {
+            } else {
                 entry.setStatus(WeblogEntryData.DRAFT);
             }
-
-
-            if ( cat != null )
-            {
+            
+            
+            if ( cat != null ) {
                 // Use first category specified by request
-                WeblogCategoryData cd = 
-                    weblogMgr.getWeblogCategoryByPath(website, cat);
+                WeblogCategoryData cd =
+                        weblogMgr.getWeblogCategoryByPath(website, cat);
                 entry.setCategory(cd);
-            }
-            else
-            {
+            } else {
                 // Use Blogger API category from user's weblog config
                 entry.setCategory(website.getBloggerCategory());
             }
-
+            
             entry.save();
             roller.commit();
             flushPageCache(entry.getWebsite());
-
+            
             // 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)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in MetaWeblogAPIHandler.newPost";
             mLogger.error(msg,e);
             throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
         }
     }
-
-    //------------------------------------------------------------------------
-
+    
+    
     /**
      *
      * @param postid
@@ -310,67 +279,60 @@
      * @throws Exception
      */
     public Object getPost(String postid, String userid, String password)
-                   throws Exception
-    {
+            throws Exception {
+        
         mLogger.info("getPost() Called =========[ SUPPORTED ]=====");
         mLogger.info("     PostId: " + postid);
         mLogger.info("     UserId: " + userid);
-
-        Roller roller = RollerFactory.getRoller(); 
+        
+        Roller roller = RollerFactory.getRoller();
         WeblogManager weblogMgr = roller.getWeblogManager();
         WeblogEntryData entry = weblogMgr.retrieveWeblogEntry(postid);
         
         validate(entry.getWebsite().getHandle(), userid,password);
-
-        try
-        {
+        
+        try {
             return createPostStruct(entry, userid);
-        }
-        catch (Exception e)
-        {
+        } 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 
+     * 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
-    {
+    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(blogid, userid, password);
-        try
-        {
-            String name = (String) struct.get("name");    
+        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 = RollerFactory.getRoller(); 
+            
+            Roller roller = RollerFactory.getRoller();
             FileManager fmgr = roller.getFileManager();
             RollerMessages msgs = new RollerMessages();
             
             // If save is allowed by Roller system-wide policies
-            if (fmgr.canSave(website.getHandle(), name, bits.length, msgs)) 
-            {
+            if (fmgr.canSave(website.getHandle(), name, bits.length, msgs)) {
                 // Then save the file
                 fmgr.saveFile(
-                    website.getHandle(), name, bits.length, new ByteArrayInputStream(bits));
+                        website.getHandle(), name, bits.length, new ByteArrayInputStream(bits));
                 
                 RollerRequest rreq = RollerRequest.getRollerRequest();
                 HttpServletRequest request = rreq.getRequest();
@@ -385,17 +347,16 @@
                 returnStruct.put("url", fileLink);
                 return returnStruct;
             }
-            throw new XmlRpcException(UPLOAD_DENIED_EXCEPTION, 
-                "File upload denied because:" + msgs.toString());
-        }
-        catch (RollerException e)
-        {
+            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
      *
@@ -406,67 +367,60 @@
      * @throws XmlRpcException
      * @return
      */
-    public Object getRecentPosts(
-        String blogid, String userid, String password, int numposts)
-        throws Exception
-    {
+    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(blogid, userid,password);
-
-        try
-        {
+        
+        try {
             Vector results = new Vector();
-
-            Roller roller = RollerFactory.getRoller(); 
+            
+            Roller roller = RollerFactory.getRoller();
             WeblogManager weblogMgr = roller.getWeblogManager();
-            if (website != null)
-            {
+            if (website != null) {
                 Map entries = weblogMgr.getWeblogEntryObjectMap(
-                                website,                // userName
-                                null,                   // startDate
-                                new Date(),             // endDate
-                                null,                   // catName
-                                null,      // status
-                                new Integer(numposts)); // maxEntries 
+                        website,                // userName
+                        null,                   // startDate
+                        new Date(),             // endDate
+                        null,                   // catName
+                        null,      // status
+                        new Integer(numposts)); // maxEntries
                 
                 Iterator iter = entries.values().iterator();
-                while (iter.hasNext())
-                {
+                while (iter.hasNext()) {
                     ArrayList list = (ArrayList) iter.next();
                     Iterator entryIter = list.iterator();
-                    while (entryIter.hasNext())
-                    {
+                    while (entryIter.hasNext()) {
                         WeblogEntryData entry = (WeblogEntryData)entryIter.next();
                         results.addElement(createPostStruct(entry, userid));
                     }
                 }
             }
             return results;
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             String msg = "ERROR in BlooggerAPIHander.getRecentPosts";
             mLogger.error(msg,e);
             throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
         }
     }
     
-    private Hashtable createPostStruct(WeblogEntryData entry, String userid)
-    {       
+    
+    private Hashtable createPostStruct(WeblogEntryData entry, String userid) {
+        
         RollerRequest rreq = RollerRequest.getRollerRequest();
         HttpServletRequest request = rreq.getRequest();
         RollerContext rollerCtx = RollerContext.getRollerContext();
-        String permalink = 
-            rollerCtx.getAbsoluteContextUrl(request) + entry.getPermaLink();
+        String permalink =
+                rollerCtx.getAbsoluteContextUrl(request) + entry.getPermaLink();
         
-        Hashtable struct = new Hashtable();       
+        Hashtable struct = new Hashtable();
         struct.put("title", entry.getTitle());
-        if (entry.getLink() != null) 
-        {
+        if (entry.getLink() != null) {
             struct.put("link", Utilities.escapeHTML(entry.getLink()));
         }
         
@@ -475,33 +429,35 @@
         struct.put("dateCreated", entry.getPubTime());
         struct.put("guid", Utilities.escapeHTML(permalink));
         struct.put("permaLink", Utilities.escapeHTML(permalink));
-        struct.put("postid", entry.getId());                        
+        struct.put("postid", entry.getId());
         struct.put("userid", userid);
-
+        
         Vector catArray = new Vector();
-        catArray.addElement(entry.getCategory().getPath());      
+        catArray.addElement(entry.getCategory().getPath());
         struct.put("categories", catArray);
         
         return struct;
     }
     
-    private Hashtable createCategoryStruct(WeblogCategoryData category, String userid)
-    {
+    
+    private Hashtable createCategoryStruct(WeblogCategoryData category, String userid) {
+        
         RollerRequest rreq = RollerRequest.getRollerRequest();
         HttpServletRequest req = rreq.getRequest();
         String contextUrl = RollerContext.getRollerContext().getAbsoluteContextUrl(req);
-
+        
         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;
     }
+    
 }



Mime
View raw message