KickJava   Java API By Example, From Geeks To Geeks.

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


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
40 import org.jahia.blogs.api.MovableTypeAPI;
41 import org.jahia.blogs.api.XMLRPCConstants;
42
43 import org.jahia.blogs.actions.AbstractAction;
44 import org.jahia.blogs.actions.GetRecentPostTitlesAction;
45 import org.jahia.blogs.actions.GetCategoriesAction;
46 import org.jahia.blogs.actions.GetPostCategoriesAction;
47 import org.jahia.blogs.actions.SetPostCategoriesAction;
48 import org.jahia.blogs.actions.GetTrackBackPingsAction;
49
50 import java.util.Vector JavaDoc;
51
52 import org.apache.xmlrpc.XmlRpcException;
53
54 import org.apache.log4j.Logger;
55
56 /**
57  * Implementation of the MovableTypeAPI.
58  *
59  * @author Xavier Lawrence
60  */

61 public class MovableTypeAPIImpl extends MetaWeblogAPIImpl
62         implements MovableTypeAPI, XMLRPCConstants {
63     
64     // log4j logger
65
static Logger log = Logger.getLogger(MovableTypeAPIImpl.class);
66     
67     /**
68      * Returns a bandwidth-friendly list of the most recent posts in the system.
69      */

70     public Vector JavaDoc getRecentPostTitles(
71             final String JavaDoc blogID,
72             final String JavaDoc userName,
73             final String JavaDoc passWord,
74             final int numberOfPosts)
75             throws XmlRpcException {
76         
77         log.debug("mt.getRecentPostTitles: " +blogID+ ", " +userName+
78                 ", " +passWord+ ", " +numberOfPosts);
79         
80         AbstractAction action = new GetRecentPostTitlesAction(blogID, userName,
81                 passWord, numberOfPosts);
82         
83         try {
84             return (Vector JavaDoc)action.execute();
85         } catch (Exception JavaDoc e) {
86             e.printStackTrace();
87             if (e.getMessage().indexOf("Login") != -1) {
88                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
89                         AUTHORIZATION_EXCEPTION_MSG);
90             } else {
91                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
92             }
93         } finally {
94             action = null;
95         }
96     }
97     
98     /**
99      * Returns a list of all categories defined in the weblog.
100      */

101     public Vector JavaDoc getCategoryList(
102             final String JavaDoc blogID,
103             final String JavaDoc userName,
104             final String JavaDoc passWord)
105             throws XmlRpcException {
106         
107         log.debug("mt.getCategoryList: " +blogID+ ", " +userName+
108                 ", " +passWord);
109         
110         AbstractAction action = new GetCategoriesAction(blogID, userName,
111                 passWord, false);
112         
113         try {
114             return (Vector JavaDoc)action.execute();
115         } catch (Exception JavaDoc e) {
116             e.printStackTrace();
117             if (e.getMessage().indexOf("Login") != -1) {
118                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
119                         AUTHORIZATION_EXCEPTION_MSG);
120             } else {
121                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
122             }
123         } finally {
124             action = null;
125         }
126     }
127     
128     /**
129      * Returns a list of all categories to which the post is assigned.
130      */

131     public Vector JavaDoc getPostCategories(
132             final String JavaDoc postID,
133             final String JavaDoc userName,
134             final String JavaDoc passWord)
135             throws XmlRpcException {
136         
137         log.debug("mt.getPostCategories: " +postID+ ", " +userName+
138                 ", " +passWord);
139         
140         AbstractAction action = new GetPostCategoriesAction(postID, userName,
141                 passWord);
142         
143         try {
144             return (Vector JavaDoc)action.execute();
145         } catch (Exception JavaDoc e) {
146             e.printStackTrace();
147             if (e.getMessage().indexOf("Login") != -1) {
148                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
149                         AUTHORIZATION_EXCEPTION_MSG);
150             } else {
151                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
152             }
153         } finally {
154             action = null;
155         }
156     }
157     
158     /**
159      * Sets the categories for a post.
160      */

161     public boolean setPostCategories(
162             final String JavaDoc postID,
163             final String JavaDoc userName,
164             final String JavaDoc passWord,
165             final Vector JavaDoc categories)
166             throws XmlRpcException {
167         
168         log.debug("mt.setPostCategories: " +postID+ ", " +userName+
169                 ", " +passWord+ ", " +categories);
170         
171         AbstractAction action = new SetPostCategoriesAction(postID, userName,
172                 passWord, categories);
173         
174         try {
175             return ((Boolean JavaDoc)action.execute()).booleanValue();
176         } catch (Exception JavaDoc e) {
177             e.printStackTrace();
178             if (e.getMessage().indexOf("Login") != -1) {
179                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
180                         AUTHORIZATION_EXCEPTION_MSG);
181             } else {
182                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
183             }
184         } finally {
185             action = null;
186         }
187     }
188     
189     /**
190      * Retrieve information about the XML-RPC methods supported by the server.
191      */

192     public Vector JavaDoc supportedMethods() throws XmlRpcException {
193         log.debug("mt.supportedMethods()");
194         Vector JavaDoc result = new Vector JavaDoc(21);
195         
196         result.add("blogger.newPost");
197         result.add("blogger.editPost");
198         result.add("blogger.getPost");
199         result.add("blogger.deletePost");
200         result.add("blogger.getRecentPosts");
201         result.add("blogger.getUsersBlogs");
202         result.add("blogger.getUserInfo");
203         
204         result.add("metaWeblog.newPost");
205         result.add("metaWeblog.editPost");
206         result.add("metaWeblog.getPost");
207         result.add("metaWeblog.deletePost");
208         result.add("metaWeblog.getRecentPosts");
209         result.add("metaWeblog.getUsersBlogs");
210         result.add("metaWeblog.getUserInfo");
211         result.add("metaWeblog.getCategories");
212         result.add("metaWeblog.newMediaObject");
213         
214         result.add("mt.getRecentPostTitles");
215         result.add("mt.getCategoryList");
216         result.add("mt.getPostCategories");
217         result.add("mt.getTrackbackPings");
218         result.add("mt.setPostCategories");
219         result.add("mt.supportedMethods");
220         result.add("mt.supportedTextFilters");
221         
222         return result;
223     }
224     
225     /**
226      * Retrieve information about the text formatting plugins supported by
227      * the server.
228      */

229     public Vector JavaDoc supportedTextFilters() throws XmlRpcException {
230         log.debug("mt.supportedTextFilters()");
231         return new Vector JavaDoc(0);
232     }
233     
234     /**
235      * Retrieve the list of TrackBack pings posted to a particular entry.
236      * This could be used to programmatically retrieve the list of pings for a
237      * particular entry, then iterate through each of those pings doing the same,
238      * until one has built up a graph of the web of entries referencing one
239      * another on a particular topic.
240      */

241     public Vector JavaDoc getTrackbackPings(
242             final String JavaDoc postID)
243             throws XmlRpcException {
244         log.debug("mt.getTrackbackPings: "+postID);
245         
246         AbstractAction action = new GetTrackBackPingsAction(postID);
247         
248         try {
249             return (Vector JavaDoc)action.execute();
250         } catch (Exception JavaDoc e) {
251             e.printStackTrace();
252             if (e.getMessage().indexOf("Login") != -1) {
253                 throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
254                         AUTHORIZATION_EXCEPTION_MSG);
255             } else {
256                 throw new XmlRpcException(UNKNOWN_EXCEPTION, e.getMessage());
257             }
258         } finally {
259             action = null;
260         }
261     }
262     
263     /**
264      * Publish (rebuild) all of the static files related to an entry from your
265      * weblog. Equivalent to saving an entry in the system (but without the ping).
266      */

267     public boolean publishPost(
268             final String JavaDoc blogID,
269             final String JavaDoc userName,
270             final String JavaDoc passWord)
271             throws XmlRpcException {
272         
273         log.debug("mt.publishPost: " +blogID+ ", " +userName+
274                 ", " +passWord);
275         throw new XmlRpcException(UNSUPPORTED_EXCEPTION,
276                 UNSUPPORTED_EXCEPTION_MSG);
277         
278     }
279 }
280
Popular Tags