Package org.apache.roller.model

Examples of org.apache.roller.model.FileManager


        pmgr.saveProperties(config);
        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);
       
        // make sure file was stored successfully
        assertEquals(1, fmgr.getFiles(testWeblog.getHandle()).length);
       
        // delete a file
        fmgr.deleteFile(testWeblog.getHandle(), "bookmarks.opml");
       
        // make sure delete was successful
        Thread.sleep(2000);
        assertEquals(0, fmgr.getFiles(testWeblog.getHandle()).length);
    }
View Full Code Here


            mLogger.debug("newMediaObject type: " + type);
           
            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);
View Full Code Here

                mRoller.getUserManager().getWebsiteByHandle(handle);
            if (website == null) {
                throw new AtomNotFoundException(
                    "ERROR: cannot find specified weblog");
            }
            FileManager fmgr = mRoller.getFileManager();
            File[] files = fmgr.getFiles(website.getHandle());
                       
            if (canView(website)) {
                Feed feed = new Feed();
                feed.setId(URLUtilities.getAtomProtocolURL(true)
                    +"/"+website.getHandle() + "/entries/" + start);               
View Full Code Here

                        try {                           
                            String fileName = pathInfo[2];
                            if (pathInfo[2].endsWith(".media-link")) {
                                fileName = fileName.substring(0, pathInfo[2].length() - ".media-link".length());
                            }
                            FileManager fmgr = mRoller.getFileManager();
                            fmgr.deleteFile(website.getHandle(), fileName);
                        } catch (Exception e) {
                            String msg = "ERROR in atom.deleteResource";
                            mLogger.error(msg,e);
                            throw new AtomException(msg);
                        }
View Full Code Here

                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";
View Full Code Here

        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"));
            }
View Full Code Here

        int count = 0;
        RollerSession rses = RollerSession.getRollerSession(request);
        if (rses.isUserAuthorizedToAuthor(website)) {
            fwd = mapping.findForward("uploadFiles.page");
            try {
                FileManager fmgr = RollerFactory.getRoller().getFileManager();
                String[] deleteFiles = theForm.getDeleteFiles();
                for (int i=0; i<deleteFiles.length; i++) {
                    if (    deleteFiles[i].trim().startsWith("/")
                    || deleteFiles[i].trim().startsWith("\\")
                    || deleteFiles[i].indexOf("..") != -1) {
                        // ignore absolute paths, or paths that contiain '..'
                    } else {
                        fmgr.deleteFile(website.getHandle(), deleteFiles[i]);
                        count++;
                    }
                }
            } catch (Exception e) {
                errors.add(ActionErrors.GLOBAL_ERROR,
View Full Code Here

           
            super("uploadFiles.title", req, res, mapping);
           
            Roller roller = RollerFactory.getRoller();
            PropertiesManager pmgr = roller.getPropertiesManager();
            FileManager fmgr = roller.getFileManager();
           
            String dir = fmgr.getUploadDir();
            resourcesBaseURL = URLUtilities.getWeblogResourceURL(weblog, "", false);
           
            RollerRequest rreq = RollerRequest.getRollerRequest(req);
            WebsiteData website = UploadFileFormAction.getWebsite(req);
            maxDirMB = RollerRuntimeConfig.getProperty("uploads.dir.maxsize");
            maxFileMB = RollerRuntimeConfig.getProperty("uploads.file.maxsize");
           
            overQuota = fmgr.overQuota(weblog.getHandle());
            uploadEnabled = RollerRuntimeConfig.getBooleanProperty("uploads.enabled");
           
            files = new ArrayList();
            File[] rawFiles = fmgr.getFiles(weblog.getHandle());
            for (int i=0; i<rawFiles.length; i++) {
                files.add(new FileBean(rawFiles[i]));
                totalSize += rawFiles[i].length();
            }
            Collections.sort(files, new FileBeanNameComparator());
View Full Code Here

TOP

Related Classes of org.apache.roller.model.FileManager

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.