Package org.b3log.latke.event

Examples of org.b3log.latke.event.EventException


                       new Object[]{event.getType(),
                                    article,
                                    AbstractAddArticleProcessor.class.getName()});
        } catch (final JSONException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException(e);
        }

        final String externalBloggingSys = getExternalBloggingSys();
        try {
            final JSONObject ret = new JSONObject();
            final JSONObject blogSyncMgmt =
                    blogSyncManagementRepository.getByExternalBloggingSystem(
                    externalBloggingSys);
            if (null == blogSyncMgmt) {
                LOGGER.log(Level.FINER,
                           "Not found syn management settings for external blogging system[{0}]",
                           externalBloggingSys);
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);

                return ret;
            }

            final boolean hasMultipleUsers = userUtils.hasMultipleUsers();
            if (hasMultipleUsers) {
                LOGGER.log(Level.FINER,
                           "Disabled article sync management caused by has multiple users");
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
                return ret;
            }

            LOGGER.log(Level.FINER,
                       "Got a blog sync management setting[{0}]",
                       blogSyncMgmt.toString(
                    SoloServletListener.JSON_PRINT_INDENT_FACTOR));
            if (!blogSyncMgmt.getBoolean(
                    BLOG_SYNC_MGMT_UPDATE_ENABLED)) {
                LOGGER.log(Level.INFO,
                           "External blogging system[{0}] need NOT to syn update article",
                           externalBloggingSys);
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);

                return ret;
            } else {
                final String userName = blogSyncMgmt.getString(
                        BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_NAME);
                final String userPwd = blogSyncMgmt.getString(
                        BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_PASSWORD);
                final Post externalArticle = new MetaWeblogPost(article);
                final String articleId = article.getString(Keys.OBJECT_ID);
                LOGGER.log(Level.FINEST,
                           "Getting External article-Solo article relation....");
                final JSONObject externalArticleSoloArticleRelation =
                        externalArticleSoloArticleRepository.getBySoloArticleId(
                        articleId, externalBloggingSys);
                if (null == externalArticleSoloArticleRelation) {
                    // This article published without sync adding enabled.
                    // See issue 72 for details
                    ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_FAIL);

                    return ret;
                }

                final String postId = externalArticleSoloArticleRelation.
                        getString(BLOG_SYNC_EXTERNAL_ARTICLE_ID);
                final MetaWeblog metaWeblog =
                        BlogFactory.getMetaWeblog(externalBloggingSys);
                metaWeblog.setUserName(userName);
                metaWeblog.setUserPassword(userPwd);
                metaWeblog.editPost(postId, externalArticle);

                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_ABSTRACT,
                        article.getString(Article.ARTICLE_ABSTRACT));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_CATEGORIES,
                        article.getString(Article.ARTICLE_TAGS_REF));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_CONTENT,
                        article.getString(Article.ARTICLE_CONTENT));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_CREATE_DATE,
                        article.get(Article.ARTICLE_CREATE_DATE));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_TITLE,
                        article.getString(Article.ARTICLE_TITLE));
                externalArticleSoloArticleRepository.update(
                        externalArticleSoloArticleRelation.getString(
                        Keys.OBJECT_ID), externalArticleSoloArticleRelation);
            }

            ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_SUCC);

            return ret;
        } catch (final SyncException e) {
            LOGGER.log(Level.WARNING,
                       "Can not update article sync, error msg[{0}]",
                       e.getMessage());
            throw e;
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, "Can not handle event[{0}], error msg[{1}]",
                       new String[]{getEventType(), e.getMessage()});
            throw new EventException("Can not handle event[" + getEventType()
                                     + "]");
        }
    }
View Full Code Here


                return;
            }

            final JSONObject preference = preferenceUtils.getPreference();
            if (null == preference) {
                throw new EventException("Not found preference");
            }

            final String blogTitle =
                    preference.getString(Preference.BLOG_TITLE);
            final String adminEmail =
                    preference.getString(Preference.ADMIN_EMAIL);

            final String commentContent =
                    comment.getString(Comment.COMMENT_CONTENT).
                    replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
            final String commentSharpURL =
                    comment.getString(Comment.COMMENT_SHARP_URL);
            final Message message = new Message();
            message.setFrom(adminEmail);
            message.addRecipient(originalCommentEmail);
            final String mailSubject = blogTitle + ": New reply of your comment";
            message.setSubject(mailSubject);
            final String articleTitle = article.getString(Article.ARTICLE_TITLE);
            final String blogHost = preference.getString(Preference.BLOG_HOST);
            final String articleLink = "http://" + blogHost + article.getString(
                    Article.ARTICLE_PERMALINK);
            final String commentName = comment.getString(Comment.COMMENT_NAME);
            final String commentURL = comment.getString(Comment.COMMENT_URL);
            String commenter = null;
            if (!"http://".equals(commentURL)) {
                commenter = "<a target=\"_blank\" " + "href=\"" + commentURL
                            + "\">" + commentName + "</a>";
            } else {
                commenter = commentName;
            }
            final String mailBody =
                    "Your comment on article[<a href='" + articleLink + "'>"
                    + articleTitle + "</a>] received an reply: <p>" + commenter
                    + ": <span><a href=\"http://" + blogHost + commentSharpURL
                    + "\">" + commentContent + "</a></span></p>";
            message.setHtmlBody(mailBody);
            LOGGER.log(Level.FINER,
                       "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
                       new Object[]{mailSubject, mailBody,
                                    originalCommentEmail});
            mailService.send(message);

        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException("Reply notifier error!");
        }
    }
View Full Code Here

                       new Object[]{event.getType(),
                                    article,
                                    AbstractAddArticleProcessor.class.getName()});
        } catch (final JSONException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException(e);
        }

        final JSONObject ret = new JSONObject();
        String postId = null;
        String articleId = null;
        final String externalBloggingSys = getExternalBloggingSys();
        try {
            articleId = article.getString(Keys.OBJECT_ID);
            final JSONObject blogSyncMgmt =
                    blogSyncManagementRepository.getByExternalBloggingSystem(
                    externalBloggingSys);
            if (null == blogSyncMgmt) {
                LOGGER.log(Level.FINER,
                           "Not found syn management settings for external blogging system[{0}]",
                           externalBloggingSys);
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
                return ret;
            }

            final boolean hasMultipleUsers = userUtils.hasMultipleUsers();
            if (hasMultipleUsers) {
                LOGGER.log(Level.FINER,
                           "Disabled article sync management caused by has multiple users");
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
                return ret;
            }

            LOGGER.log(Level.FINER,
                       "Got a blog sync management setting[{0}]",
                       blogSyncMgmt.toString(
                    SoloServletListener.JSON_PRINT_INDENT_FACTOR));
            if (!blogSyncMgmt.getBoolean(
                    BLOG_SYNC_MGMT_ADD_ENABLED)) {
                LOGGER.log(Level.INFO,
                           "External blogging system[{0}] need NOT to syn add article",
                           externalBloggingSys);
            } else {
                final String userName = blogSyncMgmt.getString(
                        BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_NAME);
                final String userPwd = blogSyncMgmt.getString(
                        BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_PASSWORD);

                final Post post = new MetaWeblogPost(article);
                final MetaWeblog metaWeblog =
                        BlogFactory.getMetaWeblog(externalBloggingSys);
                metaWeblog.setUserName(userName);
                metaWeblog.setUserPassword(userPwd);
                postId = metaWeblog.newPost(post);
                post.setId(postId);

                final JSONObject externalArticleSoloArticleRelation =
                        new JSONObject();
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_IMPORTED, true);
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_ID, postId);
                externalArticleSoloArticleRelation.put(Article.ARTICLE + "_"
                                                       + Keys.OBJECT_ID,
                                                       articleId);
                externalArticleSoloArticleRelation.put(
                        BlogSync.BLOG_SYNC_EXTERNAL_BLOGGING_SYS,
                        externalBloggingSys);

                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_ABSTRACT,
                        article.getString(Article.ARTICLE_ABSTRACT));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_CATEGORIES,
                        article.getString(Article.ARTICLE_TAGS_REF));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_CONTENT,
                        article.getString(Article.ARTICLE_CONTENT));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_CREATE_DATE,
                        article.get(Article.ARTICLE_CREATE_DATE));
                externalArticleSoloArticleRelation.put(
                        BLOG_SYNC_EXTERNAL_ARTICLE_TITLE,
                        article.getString(Article.ARTICLE_TITLE));

                externalArticleSoloArticleRepository.add(
                        externalArticleSoloArticleRelation);
                LOGGER.log(Level.FINER,
                           "Added external[{0}] blog article-solo article relation[{1}]",
                           new String[]{getExternalBloggingSys(),
                                        externalArticleSoloArticleRelation.
                            toString()});
            }

            ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_SUCC);

            return ret;
        } catch (final SyncException e) {
            LOGGER.log(Level.WARNING, "Can not add article sync, error msg[{0}]",
                       e.getMessage());
            throw e;
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, "Can not handle event[{0}], error msg[{1}]",
                       new String[]{getEventType(), e.getMessage()});
            throw new EventException("Can not handle event[" + getEventType()
                                     + "]");
        }
    }
View Full Code Here

                                PluginRefresher.class.getName()});
        try {
            Plugins.refresh(plugins);
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, "Processing plugin loaded event error", e);
            throw new EventException(e);
        }
    }
View Full Code Here

                return;
            }

            final JSONObject preference = preferenceUtils.getPreference();
            if (null == preference) {
                throw new EventException("Not found preference");
            }

            final String blogTitle =
                    preference.getString(Preference.BLOG_TITLE);
            final String adminEmail =
                    preference.getString(Preference.ADMIN_EMAIL);

            final String commentContent =
                    comment.getString(Comment.COMMENT_CONTENT).
                    replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
            final String commentSharpURL =
                    comment.getString(Comment.COMMENT_SHARP_URL);
            final Message message = new Message();
            message.setFrom(adminEmail);
            message.addRecipient(originalCommentEmail);
            final String mailSubject = blogTitle + ": New reply of your comment";
            message.setSubject(mailSubject);
            final String pageTitle = page.getString(Page.PAGE_TITLE);
            final String blogHost = preference.getString(Preference.BLOG_HOST);
            final String pageLink = "http://" + blogHost
                                    + page.getString(Page.PAGE_PERMALINK);
            final String commentName = comment.getString(Comment.COMMENT_NAME);
            final String commentURL = comment.getString(Comment.COMMENT_URL);
            String commenter = null;
            if (!"http://".equals(commentURL)) {
                commenter = "<a target=\"_blank\" " + "href=\"" + commentURL
                            + "\">" + commentName + "</a>";
            } else {
                commenter = commentName;
            }

            final String mailBody =
                    "Your comment on page[<a href='" + pageLink + "'>"
                    + pageTitle + "</a>] received an reply: <p>" + commenter
                    + ": <span><a href=\"http://" + blogHost + commentSharpURL
                    + "\">" + commentContent + "</a></span></p>";
            message.setHtmlBody(mailBody);
            LOGGER.log(Level.FINER,
                       "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
                       new Object[]{mailSubject, mailBody,
                                    originalCommentEmail});
            mailService.send(message);
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException("Reply notifier error!");
        }
    }
View Full Code Here

                       new Object[]{event.getType(),
                                    articleId,
                                    AbstractAddArticleProcessor.class.getName()});
        } catch (final JSONException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException(e);
        }

        try {
            final JSONObject ret = new JSONObject();
            final String externalBloggingSys = getExternalBloggingSys();
            final JSONObject blogSyncMgmt =
                    blogSyncManagementRepository.getByExternalBloggingSystem(
                    externalBloggingSys);
            if (null == blogSyncMgmt) {
                LOGGER.log(Level.FINER,
                           "Not found syn management settings for external blogging system[{0}]",
                           externalBloggingSys);
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);

                return ret;
            }

            final boolean hasMultipleUsers = userUtils.hasMultipleUsers();
            if (hasMultipleUsers) {
                LOGGER.log(Level.FINER,
                           "Disabled article sync management caused by has multiple users");
                ret.put(Keys.STATUS_CODE,
                        BlogSyncStatusCodes.BLOG_SYNC_NO_NEED_TO_SYNC);
                return ret;
            }

            LOGGER.log(Level.FINER,
                       "Got a blog sync management setting[{0}]",
                       blogSyncMgmt.toString(
                    SoloServletListener.JSON_PRINT_INDENT_FACTOR));
            if (!blogSyncMgmt.getBoolean(
                    BLOG_SYNC_MGMT_REMOVE_ENABLED)) {
                LOGGER.log(Level.INFO,
                           "External blogging system[{0}] need NOT to syn remove article",
                           externalBloggingSys);
            } else {
                final String userName = blogSyncMgmt.getString(
                        BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_NAME);
                final String userPwd = blogSyncMgmt.getString(
                        BLOG_SYNC_EXTERNAL_BLOGGING_SYS_USER_PASSWORD);
                final JSONObject externalArticleSoloArticleRelation =
                        externalArticleSoloArticleRepository.getBySoloArticleId(
                        articleId, externalBloggingSys);
                if (null == externalArticleSoloArticleRelation) {
                    // This article published without sync adding enabled.
                    // See issue 72 for details
                    ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_FAIL);

                    return ret;
                }

                final String externalArticleId =
                        externalArticleSoloArticleRelation.getString(
                        BLOG_SYNC_EXTERNAL_ARTICLE_ID);
                final MetaWeblog metaWeblog = BlogFactory.getMetaWeblog(
                        externalBloggingSys);
                metaWeblog.setUserName(userName);
                metaWeblog.setUserPassword(userPwd);
                metaWeblog.deletePost(externalArticleId);

                final String relationId =
                        externalArticleSoloArticleRelation.getString(
                        Keys.OBJECT_ID);
                externalArticleSoloArticleRepository.remove(relationId);
            }

            ret.put(Keys.STATUS_CODE, BlogSyncStatusCodes.BLOG_SYNC_SUCC);

            return ret;
        } catch (final SyncException e) {
            LOGGER.log(Level.WARNING,
                       "Can not remove article sync, error msg[{0}]",
                       e.getMessage());
            throw e;
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, "Can not handle event[{0}], error msg[{1}]",
                       new String[]{getEventType(), e.getMessage()});
            throw new EventException("Can not handle event[" + getEventType()
                                     + "]");
        }
    }
View Full Code Here

                return;
            }

            final JSONObject preference = preferenceUtils.getPreference();
            if (null == preference) {
                throw new EventException("Not found preference");
            }

            final String blogHost =
                    preference.getString(Preference.BLOG_HOST).toLowerCase();
            if (Preference.Default.DEFAULT_BLOG_HOST.equals(blogHost)
View Full Code Here

                events.put(BlogSync.BLOG_SYNC_CSDN_BLOG, blogSyncCSDNBlog);
            }

        } catch (final JSONException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException(e);
        }

        try {
            final JSONObject rslt = removeArticle(event);
            try {
                blogSyncCSDNBlog.put(Keys.CODE, rslt.getString(Keys.STATUS_CODE));
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        } catch (final SyncException e) {
            try {
                blogSyncCSDNBlog.put(Keys.CODE,
                                     BlogSyncStatusCodes.BLOG_SYNC_FAIL);
                blogSyncCSDNBlog.put(Keys.MSG, e.getMessage());
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        } catch (final EventException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            try {
                blogSyncCSDNBlog.put(Keys.CODE,
                                     BlogSyncStatusCodes.BLOG_SYNC_FAIL);
                blogSyncCSDNBlog.put(Keys.MSG, "Unknown exception :-(");
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        }
    }
View Full Code Here

                blogSyncCSDNBlog = new JSONObject();
                events.put(BlogSync.BLOG_SYNC_CSDN_BLOG, blogSyncCSDNBlog);
            }
        } catch (final JSONException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException(e);
        }

        try {
            final JSONObject rslt = updateArticle(event);
            try {
                blogSyncCSDNBlog.put(Keys.CODE, rslt.getString(Keys.STATUS_CODE));
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        } catch (final SyncException e) {
            try {
                blogSyncCSDNBlog.put(Keys.CODE,
                                     BlogSyncStatusCodes.BLOG_SYNC_FAIL);
                blogSyncCSDNBlog.put(Keys.MSG, e.getMessage());
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        } catch (final EventException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            try {
                blogSyncCSDNBlog.put(Keys.CODE,
                                     BlogSyncStatusCodes.BLOG_SYNC_FAIL);
                blogSyncCSDNBlog.put(Keys.MSG, "Unknown exception :-(");
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        }
    }
View Full Code Here

                blogSyncCSDNBlog = new JSONObject();
                events.put(BlogSync.BLOG_SYNC_CSDN_BLOG, blogSyncCSDNBlog);
            }
        } catch (final JSONException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            throw new EventException(e);
        }

        try {
            final JSONObject rslt = addArticle(event);
            try {
                blogSyncCSDNBlog.put(Keys.CODE, rslt.getString(Keys.STATUS_CODE));
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        } catch (final SyncException e) {
            try {
                blogSyncCSDNBlog.put(Keys.CODE,
                                     BlogSyncStatusCodes.BLOG_SYNC_FAIL);
                blogSyncCSDNBlog.put(Keys.MSG, e.getMessage());
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        } catch (final EventException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            try {
                blogSyncCSDNBlog.put(Keys.CODE,
                                     BlogSyncStatusCodes.BLOG_SYNC_FAIL);
                blogSyncCSDNBlog.put(Keys.MSG, "Unknown exception :-(");
            } catch (final JSONException ex) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
                throw new EventException(ex);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.b3log.latke.event.EventException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.