KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > blogs > BloggerAPIImpl


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution Sàrl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * ----- END LICENSE BLOCK -----
36  */

37
38 package org.jahia.blogs;
39 import org.jahia.blogs.api.BloggerAPI;
40 import org.jahia.blogs.api.XMLRPCConstants;
41
42 import org.jahia.blogs.actions.AbstractAction;
43 import org.jahia.blogs.actions.GetUserBlogsAction;
44 import org.jahia.blogs.actions.NewPostAction;
45 import org.jahia.blogs.actions.EditPostAction;
46 import org.jahia.blogs.actions.GetPostAction;
47 import org.jahia.blogs.actions.DeletePostAction;
48 import org.jahia.blogs.actions.GetRecentPostsAction;
49 import org.jahia.blogs.actions.GetUserInfoAction;
50
51 import java.util.Vector JavaDoc;
52 import java.util.Hashtable JavaDoc;
53
54 import org.apache.xmlrpc.XmlRpcException;
55
56 import org.apache.log4j.Logger;
57
58 /**
59  * Implementation of the BloggerAPI.
60  *
61  * @author Xavier Lawrence
62  */

63 public class BloggerAPIImpl implements BloggerAPI, XMLRPCConstants {
64     
65     // log4j logger
66
static Logger log = Logger.getLogger(BloggerAPIImpl.class);
67     
68     /**
69      */

70     public String JavaDoc newPost(final String JavaDoc appKey, final String JavaDoc blogID,
71             final String JavaDoc userName, final String JavaDoc password, final String JavaDoc content,
72             final boolean publish) throws XmlRpcException {
73         log.debug("blogger.newPost: "+appKey+ ", " +blogID+ ", " +userName+
74                 ", " +password+ ", " +content+ ", " +publish);
75         
76         AbstractAction action = new NewPostAction(appKey, blogID, userName,
77                 password, content, publish);
78         
79         try {
80             return (String JavaDoc)action.execute();
81             
82         } catch (Exception JavaDoc e) {
83             e.printStackTrace();
84             if (e.getMessage().indexOf("Login") != -1) {
85                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
86                         AUTHORIZATION_EXCEPTION_MSG);
87             } else {
88                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
89             }
90             
91         } finally {
92             action = null;
93         }
94     }
95     
96     /**
97      */

98     public boolean editPost(final String JavaDoc appKey, final String JavaDoc postID,
99             final String JavaDoc userName, final String JavaDoc password, final String JavaDoc content,
100             final boolean publish) throws XmlRpcException {
101         log.debug("blogger.editPost: "+appKey+ ", " +postID+ ", " +userName+
102                 ", " +password+ ", " +content+ ", " +publish);
103         
104         AbstractAction action = new EditPostAction(appKey, postID, userName,
105                 password, content, publish);
106         
107         try {
108             return ((Boolean JavaDoc)action.execute()).booleanValue();
109             
110         } catch (Exception JavaDoc e) {
111             e.printStackTrace();
112             if (e.getMessage().indexOf("Login") != -1) {
113                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
114                         AUTHORIZATION_EXCEPTION_MSG);
115             } else {
116                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
117             }
118         } finally {
119             action = null;
120         }
121     }
122     
123     /**
124      */

125     public Hashtable JavaDoc getPost(final String JavaDoc appKey, final String JavaDoc postID,
126             final String JavaDoc userName, final String JavaDoc password) throws XmlRpcException {
127         log.debug("blogger.getPost: "+appKey+ ", " +postID+ ", " +userName+
128                 ", " +password);
129         
130         AbstractAction action = new GetPostAction(appKey, postID, userName,
131                 password);
132         
133         try {
134             return (Hashtable JavaDoc)action.execute();
135         } catch (Exception JavaDoc e) {
136             e.printStackTrace();
137             if (e.getMessage().indexOf("Login") != -1) {
138                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
139                         AUTHORIZATION_EXCEPTION_MSG);
140             } else {
141                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
142             }
143         } finally {
144             action = null;
145         }
146     }
147     
148     /**
149      */

150     public boolean deletePost(final String JavaDoc appKey, final String JavaDoc postID,
151             final String JavaDoc userName, final String JavaDoc password,
152             final boolean publish) throws XmlRpcException {
153         log.debug("blogger.deletePost: "+appKey+ ", " +postID+ ", " +userName+
154                 ", " +password+ ", " +publish);
155         
156         AbstractAction action = new DeletePostAction(appKey, postID, userName,
157                 password, publish);
158         
159         try {
160             return ((Boolean JavaDoc)action.execute()).booleanValue();
161         } catch (Exception JavaDoc e) {
162             if (e.getMessage().indexOf("Login") != -1) {
163                 e.printStackTrace();
164                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
165                         AUTHORIZATION_EXCEPTION_MSG);
166             } else {
167                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
168             }
169         } finally {
170             action = null;
171         }
172     }
173     
174     /**
175      */

176     public Vector JavaDoc getRecentPosts(final String JavaDoc appKey, final String JavaDoc blogID,
177             final String JavaDoc userName, final String JavaDoc password,
178             final int numberOfPosts) throws XmlRpcException {
179         log.debug("blogger.getRecentPosts: "+appKey+ ", " +blogID+ ", " +userName+
180                 ", " +password+ ", " +numberOfPosts);
181         
182         AbstractAction action = new GetRecentPostsAction(appKey, blogID, userName,
183                 password, numberOfPosts);
184         
185         try {
186             return (Vector JavaDoc)action.execute();
187         } catch (Exception JavaDoc e) {
188             e.printStackTrace();
189             if (e.getMessage().indexOf("Login") != -1) {
190                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
191                         AUTHORIZATION_EXCEPTION_MSG);
192             } else {
193                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
194             }
195         } finally {
196             action = null;
197         }
198     }
199     
200     /**
201      * Not implemented. The user should change the template directly from
202      * Jahia
203      */

204     public boolean setTemplate(final String JavaDoc appKey, final String JavaDoc blogID,
205             final String JavaDoc userName, final String JavaDoc password,
206             final String JavaDoc templateData, final String JavaDoc templateType) throws XmlRpcException {
207         log.debug("blogger.setTemplate: "+appKey+ ", " +blogID+ ", " +userName+
208                 ", " +password+ ", " +templateData+ ", " +templateType);
209         
210         throw new XmlRpcException(UNSUPPORTED_EXCEPTION,
211                 UNSUPPORTED_EXCEPTION_MSG);
212     }
213     
214     /**
215      * Not implemented. The user should change the template directly from
216      * Jahia
217      */

218     public String JavaDoc getTemplate(final String JavaDoc appKey, final String JavaDoc blogID,
219             final String JavaDoc userName, final String JavaDoc password,
220             final String JavaDoc templateType) throws XmlRpcException {
221         log.debug("blogger.getTemplate: "+appKey+ ", " +blogID+ ", " +userName+
222                 ", " +password+ ", " +templateType);
223         
224         throw new XmlRpcException(UNSUPPORTED_EXCEPTION,
225                 UNSUPPORTED_EXCEPTION_MSG);
226     }
227     
228     /**
229      */

230     public Hashtable JavaDoc getUserInfo(final String JavaDoc appKey, final String JavaDoc userName,
231             final String JavaDoc password) throws XmlRpcException {
232         log.debug("blogger.getUserInfo: "+appKey+ ", " +userName+ ", " +password);
233         
234         AbstractAction action = new GetUserInfoAction(appKey, userName,
235                 password);
236         
237         try {
238             return (Hashtable JavaDoc)action.execute();
239         } catch (Exception JavaDoc e) {
240             e.printStackTrace();
241             if (e.getMessage().indexOf("Login") != -1) {
242                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
243                         AUTHORIZATION_EXCEPTION_MSG);
244             } else {
245                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
246             }
247         } finally {
248             action = null;
249         }
250     }
251     
252     /**
253      */

254     public Vector JavaDoc getUsersBlogs(final String JavaDoc appKey, final String JavaDoc userName,
255             final String JavaDoc password) throws XmlRpcException {
256         log.debug("blogger.getUsersBlogs: "+appKey+ ", " +userName+ ", " +password);
257         
258         AbstractAction action = new GetUserBlogsAction(appKey, userName,
259                 password);
260         
261         try {
262             return (Vector JavaDoc)action.execute();
263         } catch (Exception JavaDoc e) {
264             e.printStackTrace();
265             if (e.getMessage().indexOf("Login") != -1) {
266                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
267                         AUTHORIZATION_EXCEPTION_MSG);
268             } else {
269                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
270             }
271         } finally {
272             action = null;
273         }
274     }
275 }
276
Popular Tags