Examples of RollerMessages


Examples of org.apache.roller.util.RollerMessages

     * @param size Size of file to be saved
     * @param is Read file from input stream
     */
    public void saveFile(String weblogHandle, String name, long size, InputStream is)
    throws RollerException {
        if (!canSave(weblogHandle, name, 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

        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        // test quota functionality
        FileManager fmgr = RollerFactory.getRoller().getFileManager();
        RollerMessages msgs = new RollerMessages();
        assertFalse(fmgr.canSave(testWeblog.getHandle(), "test.gif", 2500000, msgs));
    }
View Full Code Here

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", 1545, is);
       
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, fileSize, rollerMessages)) {
                            InputStream stream = files[i].getInputStream();
                            fmgr.saveFile(website.getHandle(), fileName, 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()));
                }
            }       
            UploadFilePageModel pageModel = new UploadFilePageModel(
                request, response, mapping, website.getHandle(), lastUploads);
            request.setAttribute("model", pageModel);
            pageModel.setWebsite(website);
           
            RollerContext rctx = RollerContext.getRollerContext();
        String baseURL = rctx.getAbsoluteContextUrl(request);
            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",
                        resourcesBaseURL + "/" + (String)uploads.next()));
            }
            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.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, bits.length, msgs)) {
                // Then save the file
                fmgr.saveFile(
                        website.getHandle(), name, bits.length, new ByteArrayInputStream(bits));
               
                RollerRequest rreq = RollerRequest.getRollerRequest();
                HttpServletRequest request = rreq.getRequest();
               
                // TODO: build URL to uploaded file should be done in FileManager
                String uploadPath = RollerFactory.getRoller().getFileManager().getUploadUrl();
                uploadPath += "/" + website.getHandle() + "/" + name;
                String fileLink = RequestUtils.printableURL(
                        RequestUtils.absoluteURL(request, uploadPath));
               
                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

    public Entry postMedia(String[] pathInfo,
            String name, String contentType, InputStream is)
            throws Exception {
        // 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
            if (name == null) {
                throw new Exception("ERROR[postResource]: No 'name' present in HTTP headers");
            }
            try {
                FileManager fmgr = mRoller.getFileManager();
                tempFile = File.createTempFile(name,"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(), name, tempFile.length(), msgs)) {
                    // Then save the file
                    FileInputStream fis = new FileInputStream(tempFile);
                    fmgr.saveFile(website.getHandle(), name, tempFile.length(), fis);
                    fis.close();
                   
                    File resource = new File(fmgr.getUploadDir() + File.separator + name);
                    return createAtomResourceEntry(website, resource);
                }

            } catch (Exception e) {
                String msg = "ERROR in atom.postResource";
                mLogger.error(msg,e);
                throw new Exception(msg);
            } finally {
                if (tempFile != null) tempFile.delete();
            }
        }
        throw new Exception("File upload denied because:" + msgs.toString());
    }
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();
           
            // Try to save file
            fmgr.saveFile(website, name, type, bits.length, new ByteArrayInputStream(bits));
           
            String fileLink = URLUtilities.getWeblogResourceURL(website, name, true);
View Full Code Here

Examples of org.apache.roller.util.RollerMessages

        if(path.startsWith("/")) {
            savePath = path.substring(1);
        }
       
        // make sure we are allowed to save this file
        RollerMessages msgs = new RollerMessages();
        if (!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);
        File saveFile = new File(dirPath.getAbsolutePath() + File.separator + savePath);
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();

                    // Try saving file
                    FileInputStream fis = new FileInputStream(tempFile);
                    fmgr.saveFile(website, fileName, contentType, tempFile.length(), fis);
                    fis.close();
                   
                    WeblogResource resource = fmgr.getFile(website, 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

        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        // test quota functionality
        FileManager fmgr = RollerFactory.getRoller().getFileManager();
        RollerMessages msgs = new RollerMessages();
        assertFalse(fmgr.canSave(testWeblog.getHandle(), "test.gif", "text/plain", 2500000, msgs));
    }
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.