1 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 ; 52 import java.util.Vector ; 53 54 import org.apache.xmlrpc.XmlRpcException; 55 56 import org.apache.log4j.Logger; 57 58 63 public class MetaWeblogAPIImpl extends BloggerAPIImpl implements MetaWeblogAPI, 64 XMLRPCConstants { 65 66 static Logger log = Logger.getLogger(MetaWeblogAPIImpl.class); 68 69 71 public boolean editPost(final String postID, final String userName, 72 final String password, final Hashtable 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 )action.execute()).booleanValue(); 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 } finally { 91 action = null; 92 } 93 } 94 95 97 public Hashtable getPost(final String postID, final String userName, 98 final String 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 )action.execute(); 107 } catch (Exception 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 122 public Vector getRecentPosts(final String blogID, final String userName, 123 final String 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 )action.execute(); 132 } catch (Exception 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 147 public String newPost(final String blogID, final String userName, 148 final String password, final Hashtable 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 )action.execute(); 158 } catch (Exception 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 176 public String newPost(final String blogID, final String userName, 177 final String password, final Hashtable 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 )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 202 public boolean deletePost(String postID, String userName, String 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 )action.execute()).booleanValue(); 212 } catch (Exception 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 227 public Hashtable getCategories(final String blogID, final String userName, 228 final String 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 )action.execute(); 237 } catch (Exception 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 252 public Hashtable newMediaObject(final String blogID, final String userName, 253 final String password, final Hashtable 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 )action.execute(); 262 } catch (Exception 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 |