1 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 ; 52 import java.util.Hashtable ; 53 54 import org.apache.xmlrpc.XmlRpcException; 55 56 import org.apache.log4j.Logger; 57 58 63 public class BloggerAPIImpl implements BloggerAPI, XMLRPCConstants { 64 65 static Logger log = Logger.getLogger(BloggerAPIImpl.class); 67 68 70 public String newPost(final String appKey, final String blogID, 71 final String userName, final String password, final String 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 )action.execute(); 81 82 } catch (Exception 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 98 public boolean editPost(final String appKey, final String postID, 99 final String userName, final String password, final String 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 )action.execute()).booleanValue(); 109 110 } catch (Exception 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 125 public Hashtable getPost(final String appKey, final String postID, 126 final String userName, final String 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 )action.execute(); 135 } catch (Exception 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 150 public boolean deletePost(final String appKey, final String postID, 151 final String userName, final String 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 )action.execute()).booleanValue(); 161 } catch (Exception 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 176 public Vector getRecentPosts(final String appKey, final String blogID, 177 final String userName, final String 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 )action.execute(); 187 } catch (Exception 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 204 public boolean setTemplate(final String appKey, final String blogID, 205 final String userName, final String password, 206 final String templateData, final String 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 218 public String getTemplate(final String appKey, final String blogID, 219 final String userName, final String password, 220 final String 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 230 public Hashtable getUserInfo(final String appKey, final String userName, 231 final String 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 )action.execute(); 239 } catch (Exception 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 254 public Vector getUsersBlogs(final String appKey, final String userName, 255 final String 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 )action.execute(); 263 } catch (Exception 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 |