Examples of RollerMessages


Examples of org.apache.roller.util.RollerMessages

        TestUtils.endSession(true);
       
        /* NOTE: upload dir for unit tests is set in
               roller/personal/testing/roller-custom.properties */
        FileManager fmgr = RollerFactory.getRoller().getFileManager();
        RollerMessages msgs = new RollerMessages();
       
        // store a file
        InputStream is = getClass().getResourceAsStream("/bookmarks.opml");
        fmgr.saveFile(testWeblog.getHandle(), "bookmarks.opml", "text/plain", 1545, is);
       
View Full Code Here

Examples of org.apache.roller.util.RollerMessages

     */
    public void saveFile(String weblogHandle, String name, String contentType,
                         long size, InputStream is)
            throws RollerException {
       
        if (!canSave(weblogHandle, name, contentType, size, new RollerMessages())) {
            throw new RollerException("ERROR: upload denied");
        }
       
        byte[] buffer = new byte[8192];
        int bytesRead = 0;
View Full Code Here

Examples of org.apache.roller.util.RollerMessages

           
            byte[] bits = (byte[]) struct.get("bits");
           
            Roller roller = RollerFactory.getRoller();
            FileManager fmgr = roller.getFileManager();
            RollerMessages msgs = new RollerMessages();
           
            // If save is allowed by Roller system-wide policies
            if (fmgr.canSave(website.getHandle(), name, type, bits.length, msgs)) {
                // Then save the file
                fmgr.saveFile(website.getHandle(), name, type, bits.length, new ByteArrayInputStream(bits));
               
                // TODO: build URL to uploaded file should be done in FileManager
                String uploadPath = RollerFactory.getRoller().getFileManager().getUploadUrl();
                uploadPath += "/" + website.getHandle() + "/" + name;
                String fileLink = URLUtilities.getWeblogResourceURL(website, name, true);
               
                Hashtable returnStruct = new Hashtable(1);
                returnStruct.put("url", fileLink);
                return returnStruct;
            }
            throw new XmlRpcException(UPLOAD_DENIED_EXCEPTION,
                    "File upload denied because:" + msgs.toString());
        } catch (RollerException e) {
            String msg = "ERROR in MetaWeblogAPIHandler.newMediaObject";
            mLogger.error(msg,e);
            throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
        }
View Full Code Here

Examples of org.apache.roller.util.RollerMessages

            String title, String slug, String contentType, InputStream is)
            throws AtomException {
        try {
            // authenticated client posted a weblog entry
            File tempFile = null;
            RollerMessages msgs = new RollerMessages();
            String handle = pathInfo[0];
            WebsiteData website =
                mRoller.getUserManager().getWebsiteByHandle(handle);
            if (canEdit(website) && pathInfo.length > 1) {
                // save to temp file
                String fileName = createFileName(website, (slug != null) ? slug : title, contentType);
                try {
                    FileManager fmgr = mRoller.getFileManager();
                    tempFile = File.createTempFile(fileName, "tmp");
                    FileOutputStream fos = new FileOutputStream(tempFile);
                    Utilities.copyInputToOutput(is, fos);
                    fos.close();

                    // If save is allowed by Roller system-wide policies
                    if (fmgr.canSave(website.getHandle(), fileName, contentType, tempFile.length(), msgs)) {
                        // Then save the file
                        FileInputStream fis = new FileInputStream(tempFile);
                        fmgr.saveFile(website.getHandle(), fileName, contentType, tempFile.length(), fis);
                        fis.close();

                        File resource = new File(fmgr.getUploadDir() + File.separator + fileName);
                        return createAtomResourceEntry(website, resource);
                    }

                } catch (IOException e) {
                    String msg = "ERROR reading posted file";
                    mLogger.error(msg,e);
                    throw new AtomException(msg, e);
                } finally {
                    if (tempFile != null) tempFile.delete();
                }
            }
            // TODO: AtomUnsupportedMediaType and AtomRequestEntityTooLarge needed?
            throw new AtomException("File upload denied because:" + msgs.toString());
       
        } catch (RollerException re) {
            throw new AtomException("ERROR: posting media");
        }
    }
View Full Code Here

Examples of org.apache.roller.util.RollerMessages

            HttpServletResponse response)
            throws Exception {
       
        ActionForward fwd = mapping.findForward("access-denied");
        WebsiteData website = getWebsite(request);
        RollerMessages rollerMessages = new RollerMessages();
        RollerSession rses = RollerSession.getRollerSession(request);
        List lastUploads = new ArrayList();
       
        if ( rses.isUserAuthorizedToAuthor(website)) {
           
            FileManager fmgr = RollerFactory.getRoller().getFileManager();
            fwd = mapping.findForward("uploadFiles.page");
            ActionMessages messages = new ActionMessages();
            ActionErrors errors = new ActionErrors();
            UploadFileForm theForm = (UploadFileForm)actionForm;
            if (theForm.getUploadedFiles().length > 0) {
                ServletContext app = servlet.getServletConfig().getServletContext();
               
                boolean uploadEnabled =
                        RollerRuntimeConfig.getBooleanProperty("uploads.enabled");
               
                if ( !uploadEnabled ) {
                    errors.add(ActionErrors.GLOBAL_ERROR,
                            new ActionError("error.upload.disabled", ""));
                    saveErrors(request, errors);
                    return fwd;
                }
               
                //this line is here for when the input page is upload-utf8.jsp,
                //it sets the correct character encoding for the response
                String encoding = request.getCharacterEncoding();
                if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8"))) {
                    response.setContentType("text/html; charset=utf-8");
                }
               
                //retrieve the file representation
                FormFile[] files = theForm.getUploadedFiles();
                int fileSize = 0;
                try {
                    for (int i=0; i<files.length; i++) {
                        if (files[i] == null) continue;
                       
                        // retrieve the file name
                        String fileName= files[i].getFileName();
                        int terminated = fileName.indexOf("\000");
                        if (terminated != -1) {
                            // disallow sneaky null terminated strings
                            fileName = fileName.substring(0, terminated).trim();
                        }
                       
                        fileSize = files[i].getFileSize();
                       
                        //retrieve the file data
                        if (fmgr.canSave(website.getHandle(), fileName,
                                files[i].getContentType(), fileSize, rollerMessages)) {
                            InputStream stream = files[i].getInputStream();
                            fmgr.saveFile(website.getHandle(), fileName,
                                    files[i].getContentType(), fileSize, stream);
                            lastUploads.add(fileName);
                        }
                       
                        //destroy the temporary file created
                        files[i].destroy();
                    }
                } catch (Exception e) {
                    errors.add(ActionErrors.GLOBAL_ERROR,
                            new ActionError("error.upload.file",e.toString()));
                    mLogger.error("Error saving uploaded file", e);
                }
            }
           
            UploadFilePageModel pageModel = new UploadFilePageModel(
                    request, response, mapping, website, lastUploads);
            request.setAttribute("model", pageModel);
            pageModel.setWebsite(website);
           
            RollerContext rctx = RollerContext.getRollerContext();
            String baseURL = RollerRuntimeConfig.getAbsoluteContextURL();
            String resourcesBaseURL = baseURL + fmgr.getUploadUrl() + "/" + website.getHandle();
            Iterator uploads = lastUploads.iterator();
            if (uploads.hasNext()) {
                messages.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("uploadFiles.uploadedFiles"));
            }
            while (uploads.hasNext()) {
                messages.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("uploadFiles.uploadedFile",
                        URLUtilities.getWeblogResourceURL(website, (String)uploads.next(), true)));
            }
            saveMessages(request, messages);
           
            Iterator iter = rollerMessages.getErrors();
            while (iter.hasNext()) {
                RollerMessages.RollerMessage error =
                        (RollerMessages.RollerMessage)iter.next();
                errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError(error.getKey(), error.getArgs()));
View Full Code Here

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

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

        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

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

        );
        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

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

        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

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

        } 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
TOP
Copyright © 2018 www.massapi.com. 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.