KickJava   Java API By Example, From Geeks To Geeks.

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


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.MetaWeblogAPI;
40 import org.jahia.blogs.api.XMLRPCConstants;
41
42 import org.jahia.blogs.actions.AbstractAction;
43 import org.jahia.blogs.actions.GetPostAction;
44 import org.jahia.blogs.actions.NewPostAction;
45 import org.jahia.blogs.actions.EditPostAction;
46 import org.jahia.blogs.actions.DeletePostAction;
47 import org.jahia.blogs.actions.GetRecentPostsAction;
48 import org.jahia.blogs.actions.GetCategoriesAction;
49 import org.jahia.blogs.actions.NewMediaObjectAction;
50
51 import java.util.Hashtable JavaDoc;
52 import java.util.Vector JavaDoc;
53
54 import org.apache.xmlrpc.XmlRpcException;
55
56 import org.apache.log4j.Logger;
57
58 /**
59  * Implementation of the MetaWeblogAPI.
60  *
61  * @author Xavier Lawrence
62  */

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

71     public boolean editPost(final String JavaDoc postID, final String JavaDoc userName,
72             final String JavaDoc password, final Hashtable JavaDoc struct,
73             final boolean publish) throws XmlRpcException {
74         log.debug("metaWebLog.editPost: " +postID+ ", " +userName+ ", " +
75                 password+ ", " +struct+ ", "+publish);
76         
77         AbstractAction action = new EditPostAction(postID, userName,
78                 password, struct, publish);
79         
80         try {
81             return ((Boolean JavaDoc)action.execute()).booleanValue();
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         } finally {
91             action = null;
92         }
93     }
94     
95     /**
96      */

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

122     public Vector JavaDoc getRecentPosts(final String JavaDoc blogID, final String JavaDoc userName,
123             final String JavaDoc password, final int numposts) throws XmlRpcException {
124         log.debug("metaWebLog.getRecentPosts: " +blogID+ ", " +userName+ ", " +
125                 password+ ", " +numposts);
126         
127         AbstractAction action = new GetRecentPostsAction(blogID, userName,
128                 password, numposts);
129         
130         try {
131             return (Vector JavaDoc)action.execute();
132         } catch (Exception JavaDoc e) {
133             e.printStackTrace();
134             if (e.getMessage().indexOf("Login") != -1) {
135                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
136                         AUTHORIZATION_EXCEPTION_MSG);
137             } else {
138                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
139             }
140         } finally {
141             action = null;
142         }
143     }
144     
145     /**
146      */

147     public String JavaDoc newPost(final String JavaDoc blogID, final String JavaDoc userName,
148             final String JavaDoc password, final Hashtable JavaDoc struct,
149             final boolean publish) throws XmlRpcException {
150         log.debug("metaWebLog.newPost: " +blogID+ ", " +userName+ ", " +
151                 password+ ", " +struct+ ", "+publish);
152         
153         AbstractAction action = new NewPostAction(blogID, userName,
154                 password, struct, publish);
155         
156         try {
157             return (String JavaDoc)action.execute();
158         } catch (Exception JavaDoc e) {
159             e.printStackTrace();
160             if (e.getMessage().indexOf("Login") != -1) {
161                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
162                         AUTHORIZATION_EXCEPTION_MSG);
163             } else {
164                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
165             }
166         } finally {
167             action = null;
168         }
169     }
170     
171     /**
172      * Added to support some of the cell phone implementation of the MetaWeblog
173      * implementation client side (Sony Ericsson P900). Has the same behavior as
174      * its twin method.
175      */

176     public String JavaDoc newPost(final String JavaDoc blogID, final String JavaDoc userName,
177             final String JavaDoc password, final Hashtable JavaDoc struct,
178             final boolean publish, boolean tralala) throws XmlRpcException {
179         log.debug("metaWebLog.newPost: " +blogID+ ", " +userName+ ", " +
180                 password+ ", " +struct+ ", "+publish+ ", " +tralala);
181         
182         AbstractAction action = new NewPostAction(blogID, userName,
183                 password, struct, publish);
184         
185         try {
186             return (String 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      */

202     public boolean deletePost(String JavaDoc postID, String JavaDoc userName, String JavaDoc password,
203             boolean publish) throws XmlRpcException {
204         log.debug("metaWebLog.deletePost: " +postID+ ", " +userName+ ", " +
205                 password+ ", "+publish);
206         
207         AbstractAction action = new DeletePostAction(postID, userName,
208                 password, publish);
209         
210         try {
211             return ((Boolean JavaDoc)action.execute()).booleanValue();
212         } catch (Exception JavaDoc e) {
213             e.printStackTrace();
214             if (e.getMessage().indexOf("Login") != -1) {
215                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
216                         AUTHORIZATION_EXCEPTION_MSG);
217             } else {
218                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
219             }
220         } finally {
221             action = null;
222         }
223     }
224     
225     /**
226      */

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

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