Source Code Cross Referenced for BloggerAPIHandler.java in  » Blogger-System » blojsom-3.1 » org » blojsom » extension » xmlrpc » handler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Blogger System » blojsom 3.1 » org.blojsom.extension.xmlrpc.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2003-2007, David A. Czarnecki
003:         * All rights reserved.
004:         *
005:         * Redistribution and use in source and binary forms, with or without
006:         * modification, are permitted provided that the following conditions are met:
007:         *
008:         * Redistributions of source code must retain the above copyright notice, this list of conditions and the
009:         *     following disclaimer.
010:         * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
011:         *     following disclaimer in the documentation and/or other materials provided with the distribution.
012:         * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
013:         *     endorse or promote products derived from this software without specific prior written permission.
014:         * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
015:         *     without prior written permission of David A. Czarnecki.
016:         *
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
018:         * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
019:         * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020:         * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
021:         * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
022:         * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
025:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026:         * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027:         * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
029:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030:         */package org.blojsom.extension.xmlrpc.handler;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.apache.xmlrpc.XmlRpcException;
035:        import org.blojsom.BlojsomException;
036:        import org.blojsom.authorization.AuthorizationException;
037:        import org.blojsom.blog.Category;
038:        import org.blojsom.blog.Entry;
039:        import org.blojsom.fetcher.FetcherException;
040:        import org.blojsom.plugin.admin.event.EntryAddedEvent;
041:        import org.blojsom.plugin.admin.event.EntryDeletedEvent;
042:        import org.blojsom.plugin.admin.event.EntryUpdatedEvent;
043:        import org.blojsom.util.BlojsomConstants;
044:        import org.blojsom.util.BlojsomUtils;
045:        import org.blojsom.util.BlojsomMetaDataConstants;
046:
047:        import java.util.*;
048:
049:        /**
050:         * Blogger API handler
051:         *
052:         * @author David Czarnecki
053:         * @since blojsom 3.0
054:         * @version $Id: BloggerAPIHandler.java,v 1.6 2007/01/17 02:35:07 czarneckid Exp $
055:         */
056:        public class BloggerAPIHandler extends APIHandler {
057:
058:            private Log _logger = LogFactory.getLog(BloggerAPIHandler.class);
059:
060:            /**
061:             * Blogger API "url" key
062:             */
063:            private static final String MEMBER_URL = "url";
064:
065:            /**
066:             * Blogger API "blogid" key
067:             */
068:            private static final String MEMBER_BLOGID = "blogid";
069:
070:            /**
071:             * Blogger APU "postid" key
072:             */
073:            private static final String MEMBER_POSTID = "postid";
074:
075:            /**
076:             * Blogger API "blogName" key
077:             */
078:            private static final String MEMBER_BLOGNAME = "blogName";
079:
080:            /**
081:             * Blogger API "title" key
082:             */
083:            private static final String MEMBER_TITLE = "title";
084:
085:            /**
086:             * Blogger API "content" key
087:             */
088:            private static final String MEMBER_CONTENT = "content";
089:
090:            /**
091:             * Blogger API "dateCreated" key
092:             */
093:            private static final String MEMBER_DATECREATED = "dateCreated";
094:
095:            /**
096:             * Blogger API "authorName" key
097:             */
098:            private static final String MEMBER_AUTHORNAME = "authorName";
099:
100:            /**
101:             * Blogger API "authorEmail" key
102:             */
103:            private static final String MEMBER_AUTHOREMAIL = "authorEmail";
104:
105:            /**
106:             * Blogger API "nickname" key
107:             */
108:            private static final String MEMBER_NICKNAME = "nickname";
109:
110:            /**
111:             * Blogger API "userid" key
112:             */
113:            private static final String MEMBER_USERID = "userid";
114:
115:            /**
116:             * Blogger API "email" key
117:             */
118:            private static final String MEMBER_EMAIL = "email";
119:
120:            /**
121:             * Blogger API "firstname" key
122:             */
123:            private static final String MEMBER_FIRSTNAME = "firstname";
124:
125:            /**
126:             * Blogger API "lastname" key
127:             */
128:            private static final String MEMBER_LASTNAME = "lastname";
129:
130:            private static final String TITLE_TAG_START = "<title>";
131:            private static final String TITLE_TAG_END = "</title>";
132:
133:            private static final String API_PREFIX = "blogger";
134:
135:            private static final String BLOGGER_API_PERMISSION = "post_via_blogger_api_permission";
136:
137:            /**
138:             * Create a new instance of the Blogger API handler
139:             */
140:            public BloggerAPIHandler() {
141:            }
142:
143:            /**
144:             * Retrieve the API handler name
145:             *
146:             * @return API handler name "blogger"
147:             */
148:            public String getName() {
149:                return API_PREFIX;
150:            }
151:
152:            /**
153:             * Authenticates a user and returns basic user info (name, email, userid, etc.).
154:             *
155:             * @param appkey   Unique identifier/passcode of the application sending the post
156:             * @param userid   Login for a Blogger user who has permission to post to the blog
157:             * @param password Password for said username
158:             * @return Basic user information (name, email, userid)
159:             * @throws org.apache.xmlrpc.XmlRpcException If there is an error 
160:             *
161:             */
162:            public Object getUserInfo(String appkey, String userid,
163:                    String password) throws Exception {
164:                _logger.debug("getUserInfo() Called =====[ SUPPORTED ]=======");
165:                _logger.debug("     Appkey: " + appkey);
166:                _logger.debug("     UserId: " + userid);
167:                _logger.debug("   Password: *********");
168:
169:                try {
170:                    _authorizationProvider.authorize(_blog, null, userid,
171:                            password);
172:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
173:
174:                    Hashtable userinfo = new Hashtable();
175:                    userinfo.put(MEMBER_EMAIL, _blog.getBlogOwnerEmail());
176:                    userinfo.put(MEMBER_NICKNAME, userid);
177:                    userinfo.put(MEMBER_USERID, "1");
178:                    userinfo.put(MEMBER_URL, _blog.getBlogURL());
179:
180:                    String _ownerName = _blog.getBlogOwner();
181:                    int _split = _ownerName.indexOf(" ");
182:                    if (_split > 0) {
183:                        userinfo.put(MEMBER_FIRSTNAME, _ownerName.substring(0,
184:                                _split));
185:                        userinfo.put(MEMBER_LASTNAME, _ownerName
186:                                .substring(_split + 1));
187:                    } else {
188:                        userinfo.put(MEMBER_FIRSTNAME, "blojsom");
189:                        userinfo.put(MEMBER_LASTNAME, _ownerName);
190:                    }
191:
192:                    return userinfo;
193:
194:                } catch (BlojsomException e) {
195:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
196:                            AUTHORIZATION_EXCEPTION_MSG);
197:                }
198:            }
199:
200:            /**
201:             * Returns information on all the blogs a given user is a member of
202:             *
203:             * @param appkey   Unique identifier/passcode of the application sending the post
204:             * @param userid   Login for a Blogger user who has permission to post to the blog
205:             * @param password Password for said username
206:             * @return Blog category list
207:             * @throws XmlRpcException If there are no categories or the user was not authenticated correctly
208:             */
209:            public Object getUsersBlogs(String appkey, String userid,
210:                    String password) throws Exception {
211:                _logger.debug("getUsersBlogs() Called ===[ SUPPORTED ]=======");
212:                _logger.debug("     Appkey: " + appkey);
213:                _logger.debug("     UserId: " + userid);
214:                _logger.debug("   Password: *********");
215:
216:                try {
217:                    _authorizationProvider.authorize(_blog, null, userid,
218:                            password);
219:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
220:
221:                    Vector result = new Vector();
222:
223:                    Category[] categories = _fetcher.loadAllCategories(_blog);
224:
225:                    if (categories != null) {
226:                        for (int x = 0; x < categories.length; x++) {
227:                            Hashtable _bloglist = new Hashtable(3);
228:                            Category category = categories[x];
229:
230:                            String description;
231:                            if (!BlojsomUtils.checkNullOrBlank(category
232:                                    .getDescription())) {
233:                                description = category.getDescription();
234:                            } else {
235:                                description = category.getName();
236:                            }
237:
238:                            _bloglist.put(MEMBER_URL, _blog.getBlogURL()
239:                                    + category.getName());
240:                            _bloglist.put(MEMBER_BLOGID, Integer
241:                                    .toString(category.getId().intValue()));
242:                            _bloglist.put(MEMBER_BLOGNAME, description);
243:
244:                            result.add(_bloglist);
245:                        }
246:                    } else {
247:                        throw new XmlRpcException(NOBLOGS_EXCEPTION,
248:                                NOBLOGS_EXCEPTION_MSG);
249:                    }
250:
251:                    return result;
252:                } catch (BlojsomException e) {
253:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
254:                            AUTHORIZATION_EXCEPTION_MSG);
255:                }
256:            }
257:
258:            /**
259:             * Find a title in a content string delimited by &lt;title&gt;...&lt;/title&gt;
260:             *
261:             * @param content Content
262:             * @return Title found in content or <code>null</code> if the title was not present in &lt;title&gt; tags
263:             */
264:            private String findTitleInContent(String content) {
265:                String titleFromContent = null;
266:                int titleTagStartIndex = content.indexOf(TITLE_TAG_START);
267:
268:                if (titleTagStartIndex != -1) {
269:                    int titleTagEndIndex = content.indexOf(TITLE_TAG_END);
270:
271:                    if (titleTagEndIndex != -1
272:                            && (titleTagEndIndex > titleTagStartIndex)) {
273:                        titleFromContent = content.substring(titleTagStartIndex
274:                                + TITLE_TAG_START.length(), titleTagEndIndex);
275:                    }
276:                }
277:
278:                return titleFromContent;
279:            }
280:
281:            /**
282:             * Makes a new post to a designated blog. Optionally, will publish the blog after making the post
283:             *
284:             * @param appkey   Unique identifier/passcode of the application sending the post
285:             * @param blogid   Unique identifier of the blog the post will be added to
286:             * @param userid   Login for a Blogger user who has permission to post to the blog
287:             * @param password Password for said username
288:             * @param content  Contents of the post
289:             * @param publish  If true, the blog will be published immediately after the post is made
290:             * @return Post ID of the added entry
291:             * @throws XmlRpcException If the user was not authenticated correctly or if there was an I/O exception
292:             */
293:            public String newPost(String appkey, String blogid, String userid,
294:                    String password, String content, boolean publish)
295:                    throws Exception {
296:                _logger.debug("newPost() Called ===========[ SUPPORTED ]=====");
297:                _logger.debug("     Appkey: " + appkey);
298:                _logger.debug("     BlogId: " + blogid);
299:                _logger.debug("     UserId: " + userid);
300:                _logger.debug("   Password: *********");
301:                _logger.debug("    Publish: " + publish);
302:                _logger.debug("     Content:\n " + content);
303:
304:                try {
305:                    _authorizationProvider.authorize(_blog, null, userid,
306:                            password);
307:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
308:
309:                    String result;
310:                    String title = findTitleInContent(content);
311:
312:                    Integer blogID;
313:                    try {
314:                        blogID = Integer.valueOf(blogid);
315:                    } catch (NumberFormatException e) {
316:                        throw new XmlRpcException(UNKNOWN_EXCEPTION,
317:                                UNKNOWN_EXCEPTION_MSG);
318:                    }
319:
320:                    try {
321:                        Category category = _fetcher
322:                                .loadCategory(_blog, blogID);
323:                        Entry entry = _fetcher.newEntry();
324:
325:                        if (title != null) {
326:                            content = BlojsomUtils
327:                                    .replace(content, TITLE_TAG_START + title
328:                                            + TITLE_TAG_END, "");
329:                            entry.setTitle(title);
330:                        }
331:
332:                        entry.setBlogId(_blog.getId());
333:                        entry.setBlogCategoryId(category.getId());
334:                        entry.setDate(new Date());
335:                        entry.setModifiedDate(entry.getDate());
336:                        entry.setTitle(title);
337:                        entry.setDescription(content);
338:                        entry.setAuthor(userid);
339:
340:                        if (publish) {
341:                            entry
342:                                    .setStatus(BlojsomMetaDataConstants.PUBLISHED_STATUS);
343:                        } else {
344:                            entry
345:                                    .setStatus(BlojsomMetaDataConstants.DRAFT_STATUS);
346:                        }
347:
348:                        _fetcher.saveEntry(_blog, entry);
349:
350:                        result = Integer.toString(entry.getId().intValue());
351:
352:                        // Send out an add blog entry event
353:                        _eventBroadcaster.broadcastEvent(new EntryAddedEvent(
354:                                this , new Date(), entry, _blog));
355:                    } catch (FetcherException e) {
356:                        throw new XmlRpcException(UNKNOWN_EXCEPTION,
357:                                UNKNOWN_EXCEPTION_MSG);
358:                    }
359:
360:                    return result;
361:                } catch (BlojsomException e) {
362:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
363:                            AUTHORIZATION_EXCEPTION_MSG);
364:                }
365:            }
366:
367:            /**
368:             * Edits a given post. Optionally, will publish the blog after making the edit
369:             *
370:             * @param appkey   Unique identifier/passcode of the application sending the post
371:             * @param postid   Unique identifier of the post to be changed
372:             * @param userid   Login for a Blogger user who has permission to post to the blog
373:             * @param password Password for said username
374:             * @param content  Contents of the post
375:             * @param publish  If true, the blog will be published immediately after the post is made
376:             * @return <code>true</code> if the entry was edited, <code>false</code> otherwise
377:             * @throws XmlRpcException If the user was not authenticated correctly, if there was an I/O exception,
378:             *                         or if the entry permalink ID is invalid
379:             */
380:            public boolean editPost(String appkey, String postid,
381:                    String userid, String password, String content,
382:                    boolean publish) throws Exception {
383:                _logger.debug("editPost() Called ========[ SUPPORTED ]=====");
384:                _logger.debug("     Appkey: " + appkey);
385:                _logger.debug("     PostId: " + postid);
386:                _logger.debug("     UserId: " + userid);
387:                _logger.debug("   Password: *********");
388:                _logger.debug("    Publish: " + publish);
389:                _logger.debug("     Content:\n " + content);
390:
391:                try {
392:                    _authorizationProvider.authorize(_blog, null, userid,
393:                            password);
394:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
395:
396:                    boolean result;
397:
398:                    Integer postID;
399:                    try {
400:                        postID = Integer.valueOf(postid);
401:                    } catch (NumberFormatException e) {
402:                        throw new XmlRpcException(INVALID_POSTID,
403:                                INVALID_POSTID_MSG);
404:                    }
405:
406:                    try {
407:                        Entry entryToEdit = _fetcher.loadEntry(_blog, postID);
408:
409:                        if (!userid.equals(entryToEdit.getAuthor())) {
410:                            checkXMLRPCPermission(userid,
411:                                    ALL_XMLRPC_EDIT_PERMISSION);
412:                        }
413:
414:                        String title = findTitleInContent(content);
415:                        if (title != null) {
416:                            content = BlojsomUtils
417:                                    .replace(content, TITLE_TAG_START + title
418:                                            + TITLE_TAG_END, "");
419:                            entryToEdit.setTitle(title);
420:                        } else {
421:                            entryToEdit.setTitle("");
422:                        }
423:                        entryToEdit.setDescription(content);
424:                        entryToEdit.setModifiedDate(new Date());
425:
426:                        if (publish) {
427:                            entryToEdit
428:                                    .setStatus(BlojsomMetaDataConstants.PUBLISHED_STATUS);
429:                        } else {
430:                            entryToEdit
431:                                    .setStatus(BlojsomMetaDataConstants.DRAFT_STATUS);
432:                        }
433:
434:                        _fetcher.saveEntry(_blog, entryToEdit);
435:
436:                        result = true;
437:
438:                        _eventBroadcaster.broadcastEvent(new EntryUpdatedEvent(
439:                                this , new Date(), entryToEdit, _blog));
440:                    } catch (FetcherException e) {
441:                        throw new XmlRpcException(UNKNOWN_EXCEPTION,
442:                                UNKNOWN_EXCEPTION_MSG);
443:                    }
444:
445:                    return result;
446:                } catch (AuthorizationException e) {
447:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
448:                            AUTHORIZATION_EXCEPTION_MSG);
449:                }
450:            }
451:
452:            /**
453:             * Get a particular post for a blojsom category
454:             *
455:             * @param appkey   Unique identifier/passcode of the application sending the post
456:             * @param postid   Unique identifier of the blog post
457:             * @param userid   Login for a Blogger user who has permission to post to the blog
458:             * @param password Password for said username
459:             * @return Post to the blog
460:             * @throws XmlRpcException If the user was not authenticated correctly
461:             */
462:            public Object getPost(String appkey, String postid, String userid,
463:                    String password) throws Exception {
464:                _logger.debug("getPost() Called ===========[ SUPPORTED ]=====");
465:                _logger.debug("     Appkey: " + appkey);
466:                _logger.debug("     PostId: " + postid);
467:                _logger.debug("     UserId: " + userid);
468:                _logger.debug("   Password: *********");
469:
470:                try {
471:                    _authorizationProvider.authorize(_blog, null, userid,
472:                            password);
473:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
474:
475:                    Integer postID;
476:                    try {
477:                        postID = Integer.valueOf(postid);
478:                    } catch (NumberFormatException e) {
479:                        throw new XmlRpcException(INVALID_POSTID,
480:                                INVALID_POSTID_MSG);
481:                    }
482:
483:                    try {
484:                        Entry entry = _fetcher.loadEntry(_blog, postID);
485:
486:                        Hashtable entrystruct = new Hashtable();
487:                        entrystruct.put(MEMBER_POSTID, Integer.toString(entry
488:                                .getId().intValue()));
489:                        entrystruct.put(MEMBER_BLOGID, Integer.toString(entry
490:                                .getBlogCategory().getId().intValue()));
491:                        entrystruct.put(MEMBER_TITLE, entry.getTitle());
492:                        entrystruct.put(MEMBER_URL, _blog.getBlogURL()
493:                                + entry.getCategory() + entry.getPostSlug());
494:                        entrystruct.put(MEMBER_CONTENT, entry.getTitle()
495:                                + BlojsomConstants.LINE_SEPARATOR
496:                                + entry.getDescription());
497:                        entrystruct.put(MEMBER_DATECREATED, entry.getDate());
498:                        entrystruct
499:                                .put(MEMBER_AUTHORNAME, _blog.getBlogOwner());
500:                        entrystruct.put(MEMBER_AUTHOREMAIL, _blog
501:                                .getBlogOwnerEmail());
502:
503:                        return entrystruct;
504:                    } catch (FetcherException e) {
505:                        throw new XmlRpcException(INVALID_POSTID,
506:                                INVALID_POSTID_MSG);
507:                    }
508:                } catch (AuthorizationException e) {
509:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
510:                            AUTHORIZATION_EXCEPTION_MSG);
511:                }
512:            }
513:
514:            /**
515:             * Delete a Post
516:             *
517:             * @param appkey   Unique identifier/passcode of the application sending the post
518:             * @param postid   Unique identifier of the post to be changed
519:             * @param userid   Login for a Blogger user who has permission to post to the blog
520:             * @param password Password for said username
521:             * @param publish  Ignored
522:             * @return <code>true</code> if the entry was delete, <code>false</code> otherwise
523:             * @throws XmlRpcException If there is an error deleting the post
524:             */
525:            public boolean deletePost(String appkey, String postid,
526:                    String userid, String password, boolean publish)
527:                    throws Exception {
528:                _logger.debug("deletePost() Called =====[ SUPPORTED ]=====");
529:                _logger.debug("     Appkey: " + appkey);
530:                _logger.debug("     PostId: " + postid);
531:                _logger.debug("     UserId: " + userid);
532:                _logger.debug("   Password: *********");
533:
534:                boolean result;
535:
536:                try {
537:                    _authorizationProvider.authorize(_blog, null, userid,
538:                            password);
539:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
540:
541:                    Integer postID;
542:                    try {
543:                        postID = Integer.valueOf(postid);
544:                    } catch (NumberFormatException e) {
545:                        throw new XmlRpcException(INVALID_POSTID,
546:                                INVALID_POSTID_MSG);
547:                    }
548:
549:                    try {
550:                        Entry entryToDelete = _fetcher.loadEntry(_blog, postID);
551:                        _fetcher.deleteEntry(_blog, entryToDelete);
552:
553:                        result = true;
554:                        _eventBroadcaster.broadcastEvent(new EntryDeletedEvent(
555:                                this , new Date(), entryToDelete, _blog));
556:                    } catch (FetcherException e) {
557:                        throw new XmlRpcException(UNKNOWN_EXCEPTION,
558:                                UNKNOWN_EXCEPTION_MSG);
559:                    }
560:                } catch (AuthorizationException e) {
561:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
562:                            AUTHORIZATION_EXCEPTION_MSG);
563:                }
564:
565:                return result;
566:            }
567:
568:            /**
569:             * Get a list of recent posts for a blojsom category
570:             *
571:             * @param appkey   Unique identifier/passcode of the application sending the post
572:             * @param blogid   Unique identifier of the blog the post will be added to
573:             * @param userid   Login for a Blogger user who has permission to post to the blog
574:             * @param password Password for said username
575:             * @param numposts Number of Posts to Retrieve
576:             * @return Recent posts to the blog
577:             * @throws XmlRpcException If the user was not authenticated correctly
578:             */
579:            public Object getRecentPosts(String appkey, String blogid,
580:                    String userid, String password, int numposts)
581:                    throws Exception {
582:                _logger
583:                        .debug("getRecentPosts() Called ===========[ SUPPORTED ]=====");
584:                _logger.debug("     Appkey: " + appkey);
585:                _logger.debug("     BlogId: " + blogid);
586:                _logger.debug("     UserId: " + userid);
587:                _logger.debug("   Password: *********");
588:                _logger.debug("   Numposts: " + numposts);
589:
590:                Vector recentPosts = new Vector();
591:
592:                try {
593:                    _authorizationProvider.authorize(_blog, null, userid,
594:                            password);
595:                    checkXMLRPCPermission(userid, BLOGGER_API_PERMISSION);
596:
597:                    Entry[] entries;
598:                    try {
599:                        entries = _fetcher.loadEntriesForCategory(_blog,
600:                                Integer.valueOf(blogid), new Integer(numposts));
601:                    } catch (FetcherException e) {
602:                        throw new XmlRpcException(UNKNOWN_EXCEPTION,
603:                                UNKNOWN_EXCEPTION_MSG);
604:                    } catch (NumberFormatException e) {
605:                        throw new XmlRpcException(UNKNOWN_EXCEPTION,
606:                                UNKNOWN_EXCEPTION_MSG);
607:                    }
608:
609:                    if (entries != null && entries.length > 0) {
610:                        for (int x = 0; x < entries.length; x++) {
611:                            Entry entry = entries[x];
612:                            Hashtable entrystruct = new Hashtable();
613:                            entrystruct.put(MEMBER_POSTID, Integer
614:                                    .toString(entry.getId().intValue()));
615:                            entrystruct.put(MEMBER_BLOGID, Integer
616:                                    .toString(entry.getBlogCategory().getId()
617:                                            .intValue()));
618:                            entrystruct.put(MEMBER_TITLE, entry.getTitle());
619:                            entrystruct
620:                                    .put(MEMBER_URL, _blog.getBlogURL()
621:                                            + entry.getCategory()
622:                                            + entry.getPostSlug());
623:                            entrystruct.put(MEMBER_CONTENT, entry.getTitle()
624:                                    + BlojsomConstants.LINE_SEPARATOR
625:                                    + entry.getDescription());
626:                            entrystruct
627:                                    .put(MEMBER_DATECREATED, entry.getDate());
628:                            entrystruct.put(MEMBER_AUTHORNAME, _blog
629:                                    .getBlogOwner());
630:                            entrystruct.put(MEMBER_AUTHOREMAIL, _blog
631:                                    .getBlogOwnerEmail());
632:                            recentPosts.add(entrystruct);
633:                        }
634:                    }
635:
636:                    return recentPosts;
637:                } catch (AuthorizationException e) {
638:                    throw new XmlRpcException(AUTHORIZATION_EXCEPTION,
639:                            AUTHORIZATION_EXCEPTION_MSG);
640:                }
641:            }
642:
643:            /**
644:             * Edits the main or archive index template of a given blog (NOT IMPLEMENTED)
645:             *
646:             * @param appkey       Unique identifier/passcode of the application sending the post
647:             * @param blogid       Unique identifier of the blog the post will be added to
648:             * @param userid       Login for a Blogger user who has permission to post to the blog
649:             * @param password     Password for said username
650:             * @param template     The text for the new template (usually mostly HTML). Must contain opening and closing <Blogger> tags, since they're needed to publish
651:             * @param templateType Determines which of the blog's templates will be returned. Currently, either "main" or "archiveIndex"
652:             * @return Not supported
653:             * @throws XmlRpcException Not supported
654:             */
655:            public boolean setTemplate(String appkey, String blogid,
656:                    String userid, String password, String template,
657:                    String templateType) throws Exception {
658:                _logger.debug("setTemplate() Called =====[ UNSUPPORTED ]=====");
659:                _logger.debug("     Appkey: " + appkey);
660:                _logger.debug("     BlogId: " + blogid);
661:                _logger.debug("     UserId: " + userid);
662:                _logger.debug("   Password: *********");
663:                _logger.debug("   Template: " + template);
664:                _logger.debug("       Type: " + templateType);
665:
666:                throw new XmlRpcException(UNSUPPORTED_EXCEPTION,
667:                        UNSUPPORTED_EXCEPTION_MSG);
668:            }
669:
670:            /**
671:             * Returns the main or archive index template of a given blog (NOT IMPLEMENTED)
672:             *
673:             * @param appkey       Unique identifier/passcode of the application sending the post
674:             * @param blogid       Unique identifier of the blog the post will be added to
675:             * @param userid       Login for a Blogger user who has permission to post to the blog
676:             * @param password     Password for said username
677:             * @param templateType Determines which of the blog's templates will be returned. Currently, either "main" or "archiveIndex"
678:             * @return Not supported
679:             * @throws XmlRpcException Not supported
680:             */
681:            public String getTemplate(String appkey, String blogid,
682:                    String userid, String password, String templateType)
683:                    throws Exception {
684:                _logger.debug("getTemplate() Called =====[ UNSUPPORTED ]=====");
685:                _logger.debug("     Appkey: " + appkey);
686:                _logger.debug("     BlogId: " + blogid);
687:                _logger.debug("     UserId: " + userid);
688:                _logger.debug("   Password: *********");
689:                _logger.debug("       Type: " + templateType);
690:
691:                throw new XmlRpcException(UNSUPPORTED_EXCEPTION,
692:                        UNSUPPORTED_EXCEPTION_MSG);
693:            }
694:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.