KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > xmlrpc > BloggerHandler


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25
26 package org.snipsnap.xmlrpc;
27
28 import org.snipsnap.user.AuthenticationService;
29
30 import java.util.Hashtable JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 /**
34  * Handles XML-RPC calls for the Blogger API
35  * http://xmlrpc.free-conversant.com/docs/bloggerAPI
36  * http://plant.blogger.com/api/index.html
37  *
38  * @author Stephan J. Schmidt
39  * @version $Id: BloggerHandler.java 1612 2004-05-19 09:29:37Z stephan $
40  */

41
42 public class BloggerHandler extends XmlRpcSupport implements BloggerAPI {
43   public static final String JavaDoc API_PREFIX = "blogger";
44   MetaWeblogHandler metaHandler;
45
46   public BloggerHandler(AuthenticationService authenticationService) {
47      metaHandler = new MetaWeblogHandler(authenticationService);
48   }
49
50   public String JavaDoc getName() {
51     return API_PREFIX;
52   }
53
54   /**
55    * From the spec:
56    * blogger.newPost(): Makes a new post to a designated blog. Optionally, will publish the blog after making the post.
57    *
58    * appkey (string): Unique identifier/passcode of the application sending the post. (See access info.)
59    * blogid (string): Unique identifier of the blog the post will be added to.
60    * username (string): Login for a Blogger user who has permission to post to the blog.
61    * password (string): Password for said username.
62    * content (string): Contents of the post.
63    * publish (boolean): If true, the blog will be published immediately after the post is made.
64    *
65    * @param appkey Application key, currently not used by SnipSnap
66    * @param blogid Identifaction for the blog, currenty SnipSnap supports only one weblog
67    * @param username Login of a SnipSnap user whit permission to post to weblog
68    * @param password Password credential
69    * @param content Content of the post, currently no HTML
70    * @param publish SnipSnap currently does not support post drafts
71    *
72    * @return name Name of the post
73    */

74   public String JavaDoc newPost(String JavaDoc appkey,
75                         String JavaDoc blogid,
76                         String JavaDoc username,
77                         String JavaDoc password,
78                         String JavaDoc content,
79                         boolean publish) throws Exception JavaDoc {
80         return metaHandler.newPost(appkey,
81                 blogid,
82                 username,
83                 password,
84                 content,
85                 publish);
86   }
87
88     public boolean editPost(String JavaDoc appkey,
89                             String JavaDoc postId,
90                             String JavaDoc username,
91                             String JavaDoc password,
92                             String JavaDoc content,
93                             boolean publish) throws Exception JavaDoc {
94         return metaHandler.editPost(appkey,
95                 postId,
96                 username,
97                 password,
98                 content,
99                 publish);
100     }
101
102   public Vector JavaDoc getUsersBlogs(String JavaDoc appkey,
103                               String JavaDoc username,
104                               String JavaDoc password) throws Exception JavaDoc {
105        return metaHandler.getUsersBlogs(appkey,
106               username,
107               password);
108  }
109
110   public Vector JavaDoc getRecentPosts(String JavaDoc appkey,
111                                String JavaDoc blogid,
112                                String JavaDoc username,
113                                String JavaDoc password,
114                                int numberOfPosts) throws Exception JavaDoc {
115       return metaHandler.getRecentPosts(appkey,
116               blogid,
117               username,
118               password,
119               numberOfPosts);
120 /*
121     User user = authenticate(username, password);
122     Snip snip = SnipSpaceFactory.getInstance().getBlog().getSnip();
123
124     List children =
125         SnipSpaceFactory.getInstance().getChildrenDateOrder(snip, numberOfPosts);
126
127     Vector posts = new Vector(children.size());
128     for (Iterator i = children.iterator(); i.hasNext();) {
129       Snip each = (Snip) i.next();
130       Hashtable data = new Hashtable();
131       data.put("userid", each.getOUser() == null ? "" : each.getOUser());
132       data.put("dateCreated", each.getCTime());
133       data.put("content", each.getContent());
134       data.put("postid", each.getName());
135       posts.add(data);
136     }
137     return posts;
138  */

139   }
140
141
142   public Hashtable JavaDoc getPost(String JavaDoc appkey,
143                            String JavaDoc postId,
144                            String JavaDoc username,
145                            String JavaDoc password) throws Exception JavaDoc {
146
147      return metaHandler.getPost(appkey,
148               postId,
149               username,
150               password);
151     /*
152     User user = authenticate(username, password);
153     Snip snip = SnipSpaceFactory.getInstance().load(postId);
154     Hashtable post = new Hashtable();
155     post.put("content", snip.getXMLContent());
156     post.put("userid", snip.getOUser());
157     post.put("postid", snip.getName());
158     post.put("dateCreated", snip.getCTime());
159     return post;
160     */

161   }
162
163     /**
164      *
165      * @param appkey
166      * @param postId
167      * @param username
168      * @param password
169      * @param publish
170      * @return
171      * @throws Exception
172      */

173
174     public boolean deletePost(String JavaDoc appkey,
175                               String JavaDoc postId,
176                               String JavaDoc username,
177                               String JavaDoc password,
178                               boolean publish) throws Exception JavaDoc {
179         return metaHandler.deletePost(appkey,
180                 postId,
181                 username,
182                 password,
183                 publish);
184     }
185
186 }
187
Popular Tags