Package org.apache.roller.weblogger.pojos

Examples of org.apache.roller.weblogger.pojos.WeblogEntry


       
        // check cache first
        // NOTE: if we ever allow changing anchors then this needs updating
        if(this.entryAnchorToIdMap.containsKey(mappingKey)) {
           
            WeblogEntry entry = this.getWeblogEntry((String) this.entryAnchorToIdMap.get(mappingKey));
            if(entry != null) {
                log.debug("entryAnchorToIdMap CACHE HIT - "+mappingKey);
                return entry;
            } else {
                // mapping hit with lookup miss?  mapping must be old, remove it
                this.entryAnchorToIdMap.remove(mappingKey);
            }
        }
       
        // cache failed, do lookup
        Query q = strategy.getNamedQuery(
                "WeblogEntry.getByWebsite&AnchorOrderByPubTimeDesc");
        q.setParameter(1, website);
        q.setParameter(2, anchor);
        WeblogEntry entry = null;
        try {
            entry = (WeblogEntry)q.getSingleResult();
        } catch (NoResultException e) {
            entry = null;
        }
       
        // add mapping to cache
        if(entry != null) {
            log.debug("entryAnchorToIdMap CACHE MISS - "+mappingKey);
            this.entryAnchorToIdMap.put(mappingKey, entry.getId());
        }
        return entry;
    }
View Full Code Here


            cal.setTimeZone(website.getTimeZoneInstance());
        }
       
        SimpleDateFormat formatter = DateUtil.get8charDateFormat();
        for (Iterator wbItr = entries.iterator(); wbItr.hasNext();) {
            WeblogEntry entry = (WeblogEntry) wbItr.next();
            Date sDate = DateUtil.getNoonOfDay(entry.getPubTime(), cal);
            if (stringsOnly) {
                if (map.get(sDate) == null)
                    map.put(sDate, formatter.format(sDate));
            } else {
                List dayEntries = (List) map.get(sDate);
View Full Code Here

    /**
     * @inheritDoc
     */
    public WeblogEntry getNextEntry(WeblogEntry current,
            String catName, String locale) throws WebloggerException {
        WeblogEntry entry = null;
        List entryList = getNextPrevEntries(current, catName, locale, 1, true);
        if (entryList != null && entryList.size() > 0) {
            entry = (WeblogEntry)entryList.get(0);
        }
        return entry;
View Full Code Here

    /**
     * @inheritDoc
     */
    public WeblogEntry getPreviousEntry(WeblogEntry current,
            String catName, String locale) throws WebloggerException {
        WeblogEntry entry = null;
        List entryList = getNextPrevEntries(current, catName, locale, 1, false);
        if (entryList != null && entryList.size() > 0) {
            entry = (WeblogEntry)entryList.get(0);
        }
        return entry;
View Full Code Here

    }
   
    public String applyWeblogEntryPlugins(Map pagePlugins,WeblogEntry entry, String str) {

        String ret = str;
        WeblogEntry copy = new WeblogEntry(entry);
        List entryPlugins = copy.getPluginsList();

        if (entryPlugins != null && !entryPlugins.isEmpty()) {
            Iterator iter = entryPlugins.iterator();
            while (iter.hasNext()) {
                String key = (String)iter.next();
View Full Code Here

                    null,                      // sortby (null means pubTime)
                    WeblogManager.DESCENDING,  // sortorder, null means DESCENDING
                    locale,                    // locale
                    0, 1);                     // offset, range
            if (prevEntries.size() > 0) {
                WeblogEntry prevEntry = (WeblogEntry)prevEntries.get(0);
                prevMonth = DateUtil.getStartOfMonth(new Date(prevEntry.getPubTime().getTime()),getCalendar());
            }
        } catch (WebloggerException e) {
            log.error("ERROR determining previous non-empty month");
        }
       
        // Determine next non-empty month
        // Get entries after endDate, using category restriction limit 1
        // Use entry's date as next month
        try {
            WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
            List nextEntries = mgr.getWeblogEntries(
                   
                    weblog,                    // website
                    null,                      // user
                    // since we need an entry.pubTime>endDate, but the method use >=
                    new Date(endDate.getTime()+1),                   // startDate
                    null,                      // endDate
                    cat,                       // cat
                    null,WeblogEntry.PUBLISHED, // status
                    null,                      // text
                    null,                      // sortby (null means pubTime)
                    WeblogManager.ASCENDING,   // sortorder
                    locale,                    // locale
                    0, 1);                     // offset, range
            if (nextEntries.size() > 0) {
                WeblogEntry nextEntry = (WeblogEntry)nextEntries.get(0);
                nextMonth = DateUtil.getStartOfMonth(new Date(nextEntry.getPubTime().getTime()),getCalendar());
            }
        } catch (WebloggerException e) {
            log.error("ERROR determining next non-empty month");
       
       
View Full Code Here

                                                   WeblogCategory cat,
                                                   Weblog weblog,
                                                   User user)
            throws Exception {
       
        WeblogEntry testEntry = new WeblogEntry();
        testEntry.setTitle(anchor);
        testEntry.setLink("testEntryLink");
        testEntry.setText("blah blah entry");
        testEntry.setAnchor(anchor);
        testEntry.setPubTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        testEntry.setUpdateTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        testEntry.setStatus(WeblogEntry.PUBLISHED);
        testEntry.setWebsite(getManagedWebsite(weblog));
        testEntry.setCreatorUserName(getManagedUser(user).getUserName());
        testEntry.setCategory(cat);
       
        // store entry
        WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
        mgr.saveWeblogEntry(testEntry);
       
        // flush to db
        WebloggerFactory.getWeblogger().flush();
       
        // query for object
        WeblogEntry entry = mgr.getWeblogEntry(testEntry.getId());
       
        if(entry == null)
            throw new WebloggerException("error setting up weblog entry");
       
        return entry;
View Full Code Here

     */
    public static void teardownWeblogEntry(String id) throws Exception {
       
        // lookup the entry
        WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
        WeblogEntry entry = mgr.getWeblogEntry(id);
       
        // remove the entry
        mgr.removeWeblogEntry(entry);
       
        // flush to db
View Full Code Here

            WeblogEntryManager wmgr = roller.getWeblogEntryManager();
            currEntry = wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
            if (currEntry != null) {
               
                // clone the entry since we don't want to work with the real pojo
                WeblogEntry tmpEntry = new WeblogEntry();
                tmpEntry.setData(currEntry);
               
                // set the pubtime to the current time if it is unset
                if(tmpEntry.getPubTime() == null) {
                    tmpEntry.setPubTime(new Timestamp(System.currentTimeMillis()));
                }
               
                // store the entry in the collection
                entries = new TreeMap();
                entries.put(tmpEntry.getPubTime(),Collections.singletonList(WeblogEntryWrapper.wrap(tmpEntry, urlStrategy)));
            }
        } catch (Exception e) {
            log.error("ERROR: fetching entry", e);
        }
View Full Code Here

       
        String error = null;
        String dispatch_url = null;
       
        Weblog weblog = null;
        WeblogEntry entry = null;
       
        String message = null;
        RollerMessages messages = new RollerMessages();
       
        // are we doing a preview?  or a post?
        String method = request.getParameter("method");
        final boolean preview;
        if (method != null && method.equals("preview")) {
            preview = true;
            messages.addMessage("commentServlet.previewCommentOnly");
            log.debug("Handling comment preview post");
        } else {
            preview = false;
            log.debug("Handling regular comment post");
        }
       
        // throttling protection against spammers
        if(commentThrottle != null &&
                commentThrottle.processHit(request.getRemoteAddr())) {
           
            log.debug("ABUSIVE "+request.getRemoteAddr());
            IPBanList.getInstance().addBannedIp(request.getRemoteAddr());
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        WeblogCommentRequest commentRequest = null;
        try {
            commentRequest = new WeblogCommentRequest(request);
           
            // lookup weblog specified by comment request
            weblog = WebloggerFactory.getWeblogger().getWeblogManager()
                    .getWeblogByHandle(commentRequest.getWeblogHandle());
           
            if(weblog == null) {
                throw new WebloggerException("unable to lookup weblog: "+
                        commentRequest.getWeblogHandle());
            }
           
            // lookup entry specified by comment request
            entry = commentRequest.getWeblogEntry();
            if(entry == null) {
                throw new WebloggerException("unable to lookup entry: "+
                        commentRequest.getWeblogAnchor());
            }
           
            // we know what the weblog entry is, so setup our urls
            dispatch_url = "/roller-ui/rendering/page/"+weblog.getHandle();
            if(commentRequest.getLocale() != null) {
                dispatch_url += "/"+commentRequest.getLocale();
            }
            dispatch_url += "/entry/"+URLUtilities.encode(commentRequest.getWeblogAnchor());
           
        } catch (Exception e) {
            // some kind of error parsing the request or looking up weblog
            log.debug("error creating page request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
       
        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
        WeblogEntryComment comment = new WeblogEntryComment();
        comment.setName(commentRequest.getName());
        comment.setEmail(commentRequest.getEmail());
        comment.setUrl(commentRequest.getUrl());
        comment.setContent(commentRequest.getContent());
        comment.setNotify(Boolean.valueOf(commentRequest.isNotify()));
        comment.setWeblogEntry(entry);
        comment.setRemoteHost(request.getRemoteHost());
        comment.setPostTime(new Timestamp(System.currentTimeMillis()));
       
        // set comment content-type depending on if html is allowed
        if(WebloggerRuntimeConfig.getBooleanProperty("users.comments.htmlenabled")) {
            comment.setContentType("text/html");
        } else {
            comment.setContentType("text/plain");
        }
       
        // set whatever comment plugins are configured
        comment.setPlugins(WebloggerRuntimeConfig.getProperty("users.comments.plugins"));
       
        WeblogEntryCommentForm cf = new WeblogEntryCommentForm();
        cf.setData(comment);
        if (preview) {
            cf.setPreview(comment);
        }
       
        I18nMessages messageUtils = I18nMessages.getMessages(commentRequest.getLocaleInstance());
       
        // check if comments are allowed for this entry
        // this checks site-wide settings, weblog settings, and entry settings
        if(!entry.getCommentsStillAllowed() || !entry.isPublished()) {
            error = messageUtils.getString("comments.disabled");
           
        // if this is a real comment post then authenticate request
        } else if(!preview && !this.authenticator.authenticate(request)) {
            error = messageUtils.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;
        }
       
        int validationScore = commentValidationManager.validateComment(comment, messages);
        log.debug("Comment Validation score: " + validationScore);
       
        if (!preview) {
           
            if (validationScore == 100 && weblog.getCommentModerationRequired()) {
                // Valid comments go into moderation if required
                comment.setStatus(WeblogEntryComment.PENDING);
                message = messageUtils.getString("commentServlet.submittedToModerator");
            } else if (validationScore == 100) {
                // else they're approved
                comment.setStatus(WeblogEntryComment.APPROVED);
                message = messageUtils.getString("commentServlet.commentAccepted");
            } else {
                // Invalid comments are marked as spam
                log.debug("Comment marked as spam");
                comment.setStatus(WeblogEntryComment.SPAM);
                error = messageUtils.getString("commentServlet.commentMarkedAsSpam");
               
                // add specific error messages if they exist
                if(messages.getErrorCount() > 0) {
                    Iterator errors = messages.getErrors();
                    RollerMessage errorKey = null;
                   
                    StringBuilder buf = new StringBuilder();
                    buf.append("<ul>");
                    while(errors.hasNext()) {
                        errorKey = (RollerMessage)errors.next();
                       
                        buf.append("<li>");
                        if(errorKey.getArgs() != null) {
                            buf.append(messageUtils.getString(errorKey.getKey(), errorKey.getArgs()));
                        } else {
                            buf.append(messageUtils.getString(errorKey.getKey()));
                        }
                        buf.append("</li>");
                    }
                    buf.append("</ul>");
                   
                    error += buf.toString();
                }
               
            }
           
            try {              
                if(!WeblogEntryComment.SPAM.equals(comment.getStatus()) ||
                        !WebloggerRuntimeConfig.getBooleanProperty("comments.ignoreSpam.enabled")) {
                   
                    WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
                    mgr.saveComment(comment);
                    WebloggerFactory.getWeblogger().flush();
                   
                    // Send email notifications only to subscribers if comment is 100% valid
                    boolean notifySubscribers = (validationScore == 100);
                    MailUtil.sendEmailNotification(comment, messages, messageUtils, notifySubscribers);
                   
                    // only re-index/invalidate the cache if comment isn't moderated
                    if(!weblog.getCommentModerationRequired()) {
                        IndexManager manager = WebloggerFactory.getWeblogger().getIndexManager();
                       
                        // remove entry before (re)adding it, or in case it isn't Published
                        manager.removeEntryIndexOperation(entry);
                       
                        // if published, index the entry
                        if (entry.isPublished()) {
                            manager.addEntryIndexOperation(entry);
                        }
                       
                        // Clear all caches associated with comment
                        CacheManager.invalidate(comment);
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.pojos.WeblogEntry

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.