| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
package net.sourceforge.pebble.webservice; |
| 33 | |
|
| 34 | |
import net.sourceforge.pebble.domain.Blog; |
| 35 | |
import net.sourceforge.pebble.domain.BlogEntry; |
| 36 | |
import net.sourceforge.pebble.domain.Category; |
| 37 | |
import net.sourceforge.pebble.domain.Tag; |
| 38 | |
import net.sourceforge.pebble.api.decorator.ContentDecoratorContext; |
| 39 | |
import net.sourceforge.pebble.Constants; |
| 40 | |
import org.apache.commons.logging.Log; |
| 41 | |
import org.apache.commons.logging.LogFactory; |
| 42 | |
import org.apache.xmlrpc.XmlRpcException; |
| 43 | |
|
| 44 | |
import java.util.Collection; |
| 45 | |
import java.util.Hashtable; |
| 46 | |
import java.util.Iterator; |
| 47 | |
import java.util.Vector; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | 0 | public class PebbleAPIHandler extends AbstractAPIHandler { |
| 55 | |
|
| 56 | |
public static final String ID = "id"; |
| 57 | |
public static final String UUID = "uuid"; |
| 58 | |
public static final String DATE = "date"; |
| 59 | |
public static final String AUTHOR = "author"; |
| 60 | |
public static final String TITLE = "title"; |
| 61 | |
public static final String SUBTITLE = "subtitle"; |
| 62 | |
public static final String EXCERPT = "excerpt"; |
| 63 | |
public static final String BODY = "body"; |
| 64 | |
public static final String PERMALINK = "permalink"; |
| 65 | |
public static final String CATEGORIES = "categories"; |
| 66 | |
public static final String TAGS = "tags"; |
| 67 | |
public static final String ATTACHMENT = "attachment"; |
| 68 | |
public static final String ATTACHMENT_URL = "attachment.url"; |
| 69 | |
public static final String ATTACHMENT_SIZE = "attachment.size"; |
| 70 | |
public static final String ATTACHMENT_TYPE = "attachment.type"; |
| 71 | |
|
| 72 | |
|
| 73 | 0 | private static Log log = LogFactory.getLog(PebbleAPIHandler.class); |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public Vector getRecentBlogEntries(String blogid, String username, String password, int numberOfPosts) throws XmlRpcException { |
| 86 | 0 | log.debug("pebble.getRecentBlogEntries(" + |
| 87 | |
blogid + ", " + |
| 88 | |
username + ", " + |
| 89 | |
"********)"); |
| 90 | |
|
| 91 | 0 | Blog blog = getBlogWithBlogId(blogid); |
| 92 | 0 | authenticate(blog, username, password); |
| 93 | |
|
| 94 | 0 | Vector posts = new Vector(); |
| 95 | 0 | Collection coll = blog.getRecentPublishedBlogEntries(numberOfPosts); |
| 96 | 0 | Iterator it = coll.iterator(); |
| 97 | |
BlogEntry entry; |
| 98 | 0 | while (it.hasNext()) { |
| 99 | 0 | entry = (BlogEntry)it.next(); |
| 100 | 0 | posts.add(adaptBlogEntry(entry)); |
| 101 | |
} |
| 102 | |
|
| 103 | 0 | return posts; |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
private Hashtable adaptBlogEntry(BlogEntry entry) { |
| 113 | |
|
| 114 | 0 | ContentDecoratorContext context = new ContentDecoratorContext(); |
| 115 | 0 | context.setView(ContentDecoratorContext.DETAIL_VIEW); |
| 116 | 0 | context.setMedia(ContentDecoratorContext.XML_RPC); |
| 117 | 0 | entry.getBlog().getContentDecoratorChain().decorate(context, entry); |
| 118 | |
|
| 119 | 0 | Hashtable post = new Hashtable(); |
| 120 | 0 | post.put(TITLE, entry.getTitle()); |
| 121 | 0 | post.put(SUBTITLE, entry.getSubtitle()); |
| 122 | 0 | post.put(PERMALINK, entry.getPermalink()); |
| 123 | 0 | post.put(EXCERPT, entry.getExcerpt()); |
| 124 | 0 | post.put(BODY, entry.getBody()); |
| 125 | 0 | post.put(DATE, entry.getDate()); |
| 126 | 0 | post.put(AUTHOR, entry.getAuthor()); |
| 127 | 0 | post.put(ID, entry.getId()); |
| 128 | 0 | post.put(UUID, formatPostId(entry.getBlog().getId(), entry.getId())); |
| 129 | |
|
| 130 | 0 | Vector categories = new Vector(); |
| 131 | 0 | Iterator it = entry.getCategories().iterator(); |
| 132 | 0 | while (it.hasNext()) { |
| 133 | 0 | Category cat = (Category)it.next(); |
| 134 | 0 | categories.add(cat.getId()); |
| 135 | 0 | } |
| 136 | 0 | post.put(CATEGORIES, categories); |
| 137 | |
|
| 138 | 0 | Vector tags = new Vector(); |
| 139 | 0 | it = entry.getTagsAsList().iterator(); |
| 140 | 0 | while (it.hasNext()) { |
| 141 | 0 | Tag tag = (Tag)it.next(); |
| 142 | 0 | tags.add(tag.getName()); |
| 143 | 0 | } |
| 144 | 0 | post.put(TAGS, tags); |
| 145 | |
|
| 146 | 0 | if (entry.getAttachment() != null) { |
| 147 | 0 | Hashtable attachment = new Hashtable(); |
| 148 | 0 | attachment.put(ATTACHMENT_URL, entry.getAttachment().getUrl()); |
| 149 | 0 | attachment.put(ATTACHMENT_SIZE, entry.getAttachment().getSize()); |
| 150 | 0 | attachment.put(ATTACHMENT_TYPE, entry.getAttachment().getType()); |
| 151 | |
|
| 152 | 0 | post.put(ATTACHMENT, attachment); |
| 153 | |
} |
| 154 | |
|
| 155 | 0 | return post; |
| 156 | |
} |
| 157 | |
|
| 158 | |
} |