Package org.apache.roller.pojos

Examples of org.apache.roller.pojos.CommentData


        log.debug("Doing comment posting for entry = "+entry.getPermaLink());
       
        // collect input from request params and construct new comment object
        // fields: name, email, url, content, notify
        // TODO: data validation on collected comment data
        CommentData comment = new CommentData();
        comment.setName(commentRequest.getName());
        comment.setEmail(commentRequest.getEmail());
        comment.setUrl(commentRequest.getUrl());
        comment.setContent(commentRequest.getContent());
        comment.setNotify(new Boolean(commentRequest.isNotify()));
        comment.setWeblogEntry(entry);
        comment.setRemoteHost(request.getRemoteHost());
        comment.setPostTime(new Timestamp(System.currentTimeMillis()));
       
        WeblogEntryCommentForm cf = new WeblogEntryCommentForm();
        cf.setData(comment);
       
        // check if comments are allowed for this entry
        // this checks site-wide settings, weblog settings, and entry settings
        if(!entry.getCommentsStillAllowed() || !entry.isPublished()) {
            error = bundle.getString("comments.disabled");
       
        // make sure comment authentication passed
        } else if(!this.authenticator.authenticate(request)) {
            error = bundle.getString("error.commentAuthFailed");
            log.debug("Comment failed authentication");
        }
       
        // bail now if we have already found an error
        if(error != null) {
            cf.setError(error);
            request.setAttribute("commentForm", cf);
            RequestDispatcher dispatcher = request.getRequestDispatcher(dispatch_url);
            dispatcher.forward(request, response);
            return;
        }
       
       
        if (preview) {
            // TODO: i18n
            message = "This is a comment preview only";
            cf.setPreview(comment);
           
            // If comment contains blacklisted text, warn commenter
            SpamChecker checker = new SpamChecker();
            if (checker.checkComment(comment)) {
                error = bundle.getString("commentServlet.previewMarkedAsSpam");
                log.debug("Comment marked as spam");
            }
            log.debug("Comment is a preview");
           
        } else {
            // If comment contains blacklisted text, mark as spam
            SpamChecker checker = new SpamChecker();
            if (checker.checkComment(comment)) {
                comment.setSpam(Boolean.TRUE);
                error = bundle.getString("commentServlet.commentMarkedAsSpam");
                log.debug("Comment marked as spam");
            }
           
            // If comment moderation is on, set comment as pending
            if (weblog.getCommentModerationRequired()) {
                comment.setPending(Boolean.TRUE);
                comment.setApproved(Boolean.FALSE);
                message = bundle.getString("commentServlet.submittedToModerator");
            } else {
                comment.setPending(Boolean.FALSE);
                comment.setApproved(Boolean.TRUE);
            }
           
            try {
                WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
                mgr.saveComment(comment);
View Full Code Here


            }
           
            // Get all the subscribers to this comment thread
            Set subscribers = new TreeSet();
            for (Iterator it = comments.iterator(); it.hasNext();) {
                CommentData comment = (CommentData) it.next();
                if (!StringUtils.isEmpty(comment.getEmail())) {
                    // If user has commented twice,
                    // count the most recent notify setting
                    if (comment.getNotify().booleanValue()) {
                        // only add those with valid email
                        if (comment.getEmail().matches(EMAIL_ADDR_REGEXP)) {
                            subscribers.add(comment.getEmail());
                        }
                    } else {
                        // remove user who doesn't want to be notified
                        subscribers.remove(comment.getEmail());
                    }
                }
            }
           
            // Form array of commenter addrs
View Full Code Here

            if (comments != null) {
                StringBuffer commentEmailBuf = new StringBuffer();
                StringBuffer commentContentBuf = new StringBuffer();
                StringBuffer commentNameBuf = new StringBuffer();
                for (Iterator cItr = comments.iterator(); cItr.hasNext();) {
                    CommentData comment = (CommentData) cItr.next();
                    if (comment.getSpam() == null || !comment.getSpam().booleanValue()) {
                        if (comment.getContent() != null) {
                            commentContentBuf.append(comment.getContent());
                            commentContentBuf.append(",");
                        }
                        if (comment.getEmail() != null) {
                            commentEmailBuf.append(comment.getEmail());
                            commentEmailBuf.append(",");
                        }
                        if (comment.getName() != null) {
                            commentNameBuf.append(comment.getName());
                            commentNameBuf.append(",");
                        }
                    }
                }
                commentEmail = commentEmailBuf.toString();
View Full Code Here

            // check if trackbacks are allowed for this entry
            // this checks site-wide settings, weblog settings, and entry settings
            if (entry != null && entry.getCommentsStillAllowed() && entry.isPublished()) {
               
                // Track trackbacks as comments
                CommentData comment = new CommentData();
                comment.setContent("[Trackback] "+trackbackRequest.getExcerpt());
                comment.setName(trackbackRequest.getBlogName());
                comment.setUrl(trackbackRequest.getUrl());
                comment.setWeblogEntry(entry);
                comment.setNotify(Boolean.FALSE);
                comment.setPostTime(new Timestamp(new Date().getTime()));
               
                // If comment contains blacklisted text, mark as spam
                SpamChecker checker = new SpamChecker();
                if (checker.checkTrackback(comment)) {
                    comment.setSpam(Boolean.TRUE);
                    logger.debug("Trackback blacklisted: "+comment.getUrl());
                    error = "REJECTED: trackback contains spam words";
                }
                // Else, if trackback verification is on...
                else if (RollerRuntimeConfig.getBooleanProperty(
                        "site.trackbackVerification.enabled")) {
                   
                    // ...ensure trackbacker actually links to us
                    LinkbackExtractor linkback = new LinkbackExtractor(
                            comment.getUrl(), URLUtilities.getWeblogEntryURL(weblog, null, entry.getAnchor(), true));
                    if (linkback.getExcerpt() == null) {
                        comment.setPending(Boolean.TRUE);
                        comment.setApproved(Boolean.FALSE);
                        verified = false;
                        // if we can't verify trackback, then reject it
                        error = "REJECTED: trackback failed verification";
                        logger.debug("Trackback failed verification: "+comment.getUrl());
                    }
                }
               
                if (error == null) {
                    // If comment moderation is on, set comment as pending
                    if (verified && weblog.getCommentModerationRequired()) {
                        comment.setPending(Boolean.TRUE);
                        comment.setApproved(Boolean.FALSE);
                    } else if (verified) {
                        comment.setPending(Boolean.FALSE);
                        comment.setApproved(Boolean.TRUE);
                    }
                   
                    // save, commit, send response
                    WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
                    mgr.saveComment(comment);
                    RollerFactory.getRoller().flush();
                   
                    // only invalidate the cache if comment isn't moderated
                    if(!weblog.getCommentModerationRequired()) {
                        // Clear all caches associated with comment
                        CacheManager.invalidate(comment);
                    }
                   
                    // Send email notifications
                    String rootURL = RollerRuntimeConfig.getAbsoluteContextURL();
                    if (rootURL == null || rootURL.trim().length()==0) {
                        rootURL = RequestUtils.serverURL(request) + request.getContextPath();
                    }
                    CommentServlet.sendEmailNotification(comment, rootURL);
                   
                    if(comment.getPending().booleanValue()) {
                        pw.println(this.getSuccessResponse("Trackback submitted to moderator"));
                    } else {
                        pw.println(this.getSuccessResponse("Trackback accepted"));
                    }
                }
View Full Code Here

                    entries.remove(entries.size() - 1);
                }
               
                // wrap the results
                for (Iterator it = entries.iterator(); it.hasNext();) {
                    CommentData comment = (CommentData) it.next();
                    results.add(CommentDataWrapper.wrap(comment));
                }
               
            } catch (Exception e) {
                log.error("ERROR: fetching comment list", e);
View Full Code Here

     */
    public void testCommentCRUD() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
       
        CommentData comment = new CommentData();
        comment.setName("test");
        comment.setEmail("test");
        comment.setUrl("test");
        comment.setRemoteHost("foofoo");
        comment.setContent("this is a test comment");
        comment.setPostTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        comment.setWeblogEntry(testEntry);
        comment.setPending(Boolean.FALSE);
        comment.setApproved(Boolean.TRUE);
       
        // create a comment
        mgr.saveComment(comment);
        String id = comment.getId();
        TestUtils.endSession(true);
       
        // make sure comment was created
        comment = null;
        comment = mgr.getComment(id);
        assertNotNull(comment);
        assertEquals("this is a test comment", comment.getContent());
       
        // update a comment
        comment.setContent("testtest");
        mgr.saveComment(comment);
        TestUtils.endSession(true);
       
        // make sure comment was updated
        comment = null;
        comment = mgr.getComment(id);
        assertNotNull(comment);
        assertEquals("testtest", comment.getContent());
       
        // delete a comment
        mgr.removeComment(comment);
        TestUtils.endSession(true);
       
View Full Code Here

       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        List comments = null;
       
        // we need some comments to play with
        CommentData comment1 = TestUtils.setupComment("comment1", testEntry);
        CommentData comment2 = TestUtils.setupComment("comment2", testEntry);
        CommentData comment3 = TestUtils.setupComment("comment3", testEntry);
        TestUtils.endSession(true);
       
        // get all comments
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, null, null, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(3, comments.size());
       
        // get all comments for entry
        comments = null;
        comments = mgr.getComments(null, testEntry, null, null, null, null, null, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(3, comments.size());
       
        // make some changes
        comment3.setPending(Boolean.TRUE);
        comment3.setApproved(Boolean.FALSE);
        mgr.saveComment(comment3);
       
        // get pending comments
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, Boolean.TRUE, null, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(1, comments.size());
       
        // get approved comments
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, null, Boolean.TRUE, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(2, comments.size());
       
        // get comments with offset
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, null, null, null, false, 1, -1);
        assertNotNull(comments);
        assertEquals(2, comments.size());
       
        // remove test comments
        TestUtils.teardownComment(comment1.getId());
        TestUtils.teardownComment(comment2.getId());
        TestUtils.teardownComment(comment3.getId());
        TestUtils.endSession(true);
    }
View Full Code Here

     * Convenience method for creating a comment.
     */
    public static CommentData setupComment(String content, WeblogEntryData entry)
            throws Exception {
       
        CommentData testComment = new CommentData();
        testComment.setName("test");
        testComment.setEmail("test");
        testComment.setUrl("test");
        testComment.setRemoteHost("foofoo");
        testComment.setContent("this is a test comment");
        testComment.setPostTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        testComment.setWeblogEntry(entry);
        testComment.setPending(Boolean.FALSE);
        testComment.setApproved(Boolean.TRUE);
       
        // store testComment
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        mgr.saveComment(testComment);
       
        // query for object
        CommentData comment = mgr.getComment(testComment.getId());
       
        if(comment == null)
            throw new RollerException("error setting up comment");
       
        return comment;
View Full Code Here

     */
    public static void teardownComment(String id) throws Exception {
       
        // lookup the comment
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        CommentData comment = mgr.getComment(id);
       
        // remove the comment
        mgr.removeComment(comment);
    }
View Full Code Here

        ArrayList all = new ArrayList();
        ArrayList approvedList = new ArrayList();
        ArrayList spamList = new ArrayList();
        Iterator it = comments.iterator();
        while (it.hasNext()) {
            CommentData comment = (CommentData)it.next();
            all.add(comment.getId());
            if (comment.getApproved().booleanValue()) {
                approvedList.add(comment.getId());
            }           
            if (comment.getSpam().booleanValue()) {
                spamList.add(comment.getId());
            }
        }
        String[] idArray = (String[])all.toArray(
            new String[all.size()]);
        ids = Utilities.stringArrayToString(idArray,",");
View Full Code Here

TOP

Related Classes of org.apache.roller.pojos.CommentData

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.