Package org.apache.roller.weblogger.util

Examples of org.apache.roller.weblogger.util.RollerMessages


        TestUtils.teardownWeblog(weblog.getId());
        TestUtils.teardownUser(user.getId());
    }
   
    public void testExcessSizeCommentValidator() {
        RollerMessages msgs = new RollerMessages();
        WeblogEntryComment comment = createEmptyComment();

        // string that exceeds default excess size threshold of 1000
        StringBuffer sb = new StringBuffer();
        for (int i=0; i<101; i++) {
View Full Code Here


        comment.setContent(sb.toString());
        assertTrue(mgr.validateComment(comment, msgs) != 100);
    }
   
    public void testExcessLinksCommentValidator() {
        RollerMessages msgs = new RollerMessages();
        WeblogEntryComment comment = createEmptyComment();
       
        comment.setContent("<a href=\"http://example.com\">link1</a>");
        assertEquals(100, mgr.validateComment(comment, msgs));
View Full Code Here

        );
        assertTrue(mgr.validateComment(comment, msgs) != 100);       
    }
   
    public void testBlacklistCommentValidator() {
        RollerMessages msgs = new RollerMessages();
        WeblogEntryComment comment = createEmptyComment();
      
        comment.setContent("nice friendly stuff");
        assertEquals(100, mgr.validateComment(comment, msgs));
View Full Code Here

        if (!hasActionErrors()) {
           
            MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();

            RollerMessages errors = new RollerMessages();
            List<MediaFile> uploaded = new ArrayList();
            File[] uploads = getUploadedFiles();

            if (uploads != null && uploads.length > 0) {

                // loop over uploaded files and try saving them
                for (int i = 0; i < uploads.length; i++) {

                    // skip null files
                    if (uploads[i] == null || !uploads[i].exists()) {
                        continue;
                    }

                    try {
                        MediaFile mediaFile = new MediaFile();
                        bean.copyTo(mediaFile);

                        String fileName = getUploadedFilesFileName()[i];
                        int terminated = fileName.indexOf("\000");
                        if (terminated != -1) {
                            // disallow sneaky null terminated strings
                            fileName = fileName.substring(0, terminated).trim();
                        }

                        // make sure fileName is valid
                        if (fileName.indexOf("/") != -1 ||
                                fileName.indexOf("\\") != -1 ||
                                fileName.indexOf("..") != -1) {
                            addError("uploadFiles.error.badPath", fileName);
                            continue;
                        }

                        mediaFile.setName(       fileName);
                        mediaFile.setDirectorygetDirectory());
                        mediaFile.setWeblog(     getActionWeblog());
                        mediaFile.setLength(     this.uploadedFiles[i].length());
                        mediaFile.setInputStream(new FileInputStream(this.uploadedFiles[i]));
                        mediaFile.setContentType(this.uploadedFilesContentType[i]);

                        // insome cases Struts2 is not able to guess the content
                        // type correctly and assigns the default, which is
                        // octet-stream. So in cases where we see octet-stream
                        // we double check and see if we can guess the content
                        // type via the Java MIME type facilities.
                        mediaFile.setContentType(this.uploadedFilesContentType[i]);
                        if (mediaFile.getContentType() == null
                                || mediaFile.getContentType().endsWith("/octet-stream")) {
                           
                            String ctype = Utilities.getContentTypeFromFileName(mediaFile.getName());
                            if (null != ctype) {
                                mediaFile.setContentType(ctype);
                            }
                        }

                        manager.createMediaFile(getActionWeblog(), mediaFile, errors);
                        WebloggerFactory.getWeblogger().flush();

                        if (mediaFile.isImageFile()) {
                            newImages.add(mediaFile);
                        } else {
                            newFiles.add(mediaFile);
                        }

                        uploaded.add(mediaFile);

                    } catch (Exception e) {
                        log.error("Error uploading media file", e);
                        // TODO: i18n
                        addError("mediaFileAdd.errorUploading", bean.getName());
                    }
                }

                for (Iterator it = errors.getErrors(); it.hasNext();) {
                    RollerMessage msg = (RollerMessage) it.next();
                    addError(msg.getKey(), Arrays.asList(msg.getArgs()));
                }

                if (uploaded.size() > 0 && !this.errorsExist()) {
View Full Code Here

        } else if(!getEntry().getWebsite().equals(getActionWeblog())) {
            return DENIED;
        }
       
        if(!StringUtils.isEmpty(getTrackbackUrl())) {
            RollerMessages results = null;
            try {
                Trackback trackback = new Trackback(getEntry(), getTrackbackUrl());
                results = trackback.send();
            } catch(TrackbackNotAllowedException ex) {
                addError("error.trackbackNotAllowed");
            } catch(Throwable t) {
                log.error("Error sending trackback", t);
                // TODO: error handling
                addError("error.general", t.getMessage());
            }
           
            if(results != null) {
                for (Iterator mit = results.getMessages(); mit.hasNext();) {
                    RollerMessage msg = (RollerMessage) mit.next();
                    if(msg.getArgs() == null) {
                        addMessage(msg.getKey());
                    } else {
                        addMessage(msg.getKey(), Arrays.asList(msg.getArgs()));
                    }
                }
               
                for (Iterator eit = results.getErrors(); eit.hasNext();) {
                    RollerMessage err = (RollerMessage) eit.next();
                    if(err.getArgs() == null) {
                        addError(err.getKey());
                    } else {
                        addError(err.getKey(), Arrays.asList(err.getArgs()));
View Full Code Here

        PrintWriter pw = response.getWriter();
       
        Weblog weblog = null;
        WeblogEntry entry = null;
       
        RollerMessages messages = new RollerMessages();
       
        WeblogTrackbackRequest trackbackRequest = null;
        if (!WebloggerRuntimeConfig.getBooleanProperty("users.trackbacks.enabled")) {
            // TODO: i18n
            error = "Trackbacks are disabled for this site";
View Full Code Here

       
        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
            UserManager uMgr = WebloggerFactory.getWeblogger().getUserManager();
            weblog = uMgr.getWebsiteByHandle(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(new Boolean(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;
                   
                    StringBuffer buf = new StringBuffer();
                    buf.append("<ul>");
                    while(errors.hasNext()) {
View Full Code Here

        if(path.startsWith("/")) {
            savePath = path.substring(1);
        }
       
        // make sure we are allowed to save this file
        RollerMessages msgs = new RollerMessages();
        if (checkCanSave && !canSave(weblog, savePath, contentType, size, msgs)) {
            throw new FileIOException(msgs.toString());
        }
       
        // make sure uploads area exists for this weblog
        File dirPath = this.getRealFile(weblog, null);
       
View Full Code Here

           
            byte[] bits = (byte[]) struct.get("bits");
           
            Weblogger roller = WebloggerFactory.getWeblogger();
            FileManager fmgr = roller.getFileManager();
            RollerMessages msgs = new RollerMessages();
           
            // Try to save file
            fmgr.saveFile(website, name, type, bits.length, new ByteArrayInputStream(bits));
           
            String fileLink = WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogResourceURL(website, name, true);
View Full Code Here

       
        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()) {
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.util.RollerMessages

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.