Package org.apache.roller.business

Examples of org.apache.roller.business.FileManager


        if (rses.isUserAuthorizedToAuthor(website)) {
           
            // display the main uploads page with the results
            fwd = mapping.findForward("uploadFiles.page");
           
            FileManager fmgr = RollerFactory.getRoller().getFileManager();
           
            String path = theForm.getPath();
            String newDir = theForm.getNewDir();
            if(newDir != null &&
                    newDir.trim().length() > 0 &&
                    newDir.indexOf("/") == -1 &&
                    newDir.indexOf("\\") == -1 &&
                    newDir.indexOf("..") == -1) {
               
                // figure the new directory path
                String newDirPath = newDir;
                if(path != null && path.trim().length() > 0) {
                    newDirPath = path + "/" + newDir;
                }
               
                try {
                    // add the new subdirectory
                    fmgr.createDirectory(website, newDirPath);
                   
                    messages.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("uploadFiles.createdDir", newDirPath));
                    saveMessages(request, messages);
                   
View Full Code Here


        if (rses.isUserAuthorizedToAuthor(website)) {
           
            // display the main uploads page with the results
            fwd = mapping.findForward("uploadFiles.page");
           
            FileManager fmgr = RollerFactory.getRoller().getFileManager();
           
            List uploaded = new ArrayList();
            if (theForm.getUploadedFiles() != null &&
                    theForm.getUploadedFiles().length > 0) {
               
                // make sure uploads are enabled
                if(!RollerRuntimeConfig.getBooleanProperty("uploads.enabled")) {
                    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");
                }
               
                // loop over uploaded files and try saving them
                FormFile[] files = theForm.getUploadedFiles();
                for (int i=0; i < files.length; i++) {
                   
                    // skip null files
                    if (files[i] == null)
                        continue;
                   
                    // figure file name and path
                    String fileName= files[i].getFileName();
                    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) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                                new ActionError("uploadFiles.error.badPath", fileName));
                        continue;
                    }
                   
                    // add on the path element if needed
                    if(theForm.getPath() != null &&
                            theForm.getPath().trim().length() > 0) {
                        fileName = theForm.getPath() + "/" + fileName;
                    }
                   
                   
                    try {
                        fmgr.saveFile(website, fileName,
                                files[i].getContentType(),
                                files[i].getFileSize(),
                                files[i].getInputStream());
                       
                        uploaded.add(fileName);
View Full Code Here

        if (rses.isUserAuthorizedToAuthor(website)) {
           
            // display the main uploads page with the results
            fwd = mapping.findForward("uploadFiles.page");
           
            FileManager fmgr = RollerFactory.getRoller().getFileManager();
           
            int numDeleted = 0;
            String[] deleteFiles = theForm.getDeleteFiles();
            if(deleteFiles != null) {
                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 {
                        try {
                            fmgr.deleteFile(website, deleteFiles[i]);
                            numDeleted++;
                        } catch (FileNotFoundException ex) {
                            errors.add(ActionErrors.GLOBAL_ERROR,
                                    new ActionError("uploadFiles.error.badPath"));
                        } catch (FilePathException ex) {
View Full Code Here

                String uploadsPath,
                List lastUploads) throws RollerException {
           
            super("uploadFiles.title", req, res, mapping);
           
            FileManager fmgr = RollerFactory.getRoller().getFileManager();
           
            path = uploadsPath;
           
            // are we showing the root of the weblog's upload area?
            // are we in a subdirectory which has a parent path?
            if(uploadsPath != null && !uploadsPath.trim().equals("")) {
                showingRoot = false;
                if(uploadsPath.indexOf("/") != -1) {
                    parentPath = uploadsPath.substring(0, uploadsPath.lastIndexOf("/"));
                }
            }
           
            resourcesBaseURL = URLUtilities.getWeblogResourceURL(weblog, "", false);
           
            maxDirMB = RollerRuntimeConfig.getProperty("uploads.dir.maxsize");
            maxFileMB = RollerRuntimeConfig.getProperty("uploads.file.maxsize");
           
            overQuota = fmgr.overQuota(weblog);
            uploadEnabled = RollerRuntimeConfig.getBooleanProperty("uploads.enabled");
           
            // get files, add them to the list
            WeblogResource[] resources = fmgr.getFiles(weblog, uploadsPath);
            for (int i=0; i<resources.length; i++) {
                totalSize += resources[i].getLength();
            }
            files = new ArrayList(Arrays.asList(resources));
           
            // get directories, only if we are at the default/root view
            if(showingRoot) {
                WeblogResource[] dirs = fmgr.getDirectories(weblog);
                files.addAll(Arrays.asList(dirs));
            }
           
            // sort them
            Collections.sort(files, new WeblogResourceComparator());
View Full Code Here

        }
       
        // if not from theme then see if resource is in weblog's upload dir
        if(resourceStream == null) {
            try {
                FileManager fileMgr = RollerFactory.getRoller().getFileManager();
                WeblogResource resource = fileMgr.getFile(weblog,
                        resourceRequest.getResourcePath());
                resourceLastMod = resource.getLastModified();
                resourceStream = resource.getInputStream();
            } catch (Exception ex) {
                // still not found? then we don't have it, 404.
View Full Code Here

                {
                    // "default" values
                    WebsiteData website = rreq.getWebsite();

                    // load selected file
                    FileManager fMgr = RollerFactory.getRoller().getFileManager();
                    WeblogResource f = fMgr.getFile(website, form.getImportFileName());

                    //ArchiveParser archiveParser =
                        //new ArchiveParser(RollerFactory.getRoller(), rreq.getWebsite(), f);
                    String parseMessages = null; // archiveParser.parse();
View Full Code Here

        }
       
        // if not from theme then see if resource is in weblog's upload dir
        if(resourceStream == null) {
            try {
                FileManager fileMgr = RollerFactory.getRoller().getFileManager();
                WeblogResource resource = fileMgr.getFile(weblog,
                        resourceRequest.getResourcePath());
                resourceLastMod = resource.getLastModified();
                resourceStream = resource.getInputStream();
            } catch (Exception ex) {
                // still not found? then we don't have it, 404.
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();
           
            // Try to save file
            fmgr.saveFile(website, name, type, bits.length, new ByteArrayInputStream(bits));
           
            String fileLink = URLUtilities.getWeblogResourceURL(website, name, true);
           
            Hashtable returnStruct = new Hashtable(1);
            returnStruct.put("url", fileLink);
View Full Code Here

        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        /* NOTE: upload dir for unit tests is set in
               roller/testdata/roller-custom.properties */
        FileManager fmgr = RollerFactory.getRoller().getFileManager();
       
        // we should be starting with 0 files
        assertEquals(0, fmgr.getFiles(testWeblog, null).length);
       
        // store a file
        InputStream is = getClass().getResourceAsStream("/bookmarks.opml");
        fmgr.saveFile(testWeblog, "bookmarks.opml", "text/plain", 1545, is);
       
        // make sure file was stored successfully
        assertEquals("bookmarks.opml", fmgr.getFile(testWeblog, "bookmarks.opml").getName());
        assertEquals(1, fmgr.getFiles(testWeblog, null).length);
       
        // delete file
        fmgr.deleteFile(testWeblog, "bookmarks.opml");
       
        // make sure delete was successful
        assertEquals(0, fmgr.getFiles(testWeblog, null).length);
    }
View Full Code Here

        ((RollerPropertyData)config.get("uploads.types.allowed")).setValue("opml");
        ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00");
        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        FileManager fmgr = RollerFactory.getRoller().getFileManager();
       
        // we should be starting with 0 directories
        assertEquals(0, fmgr.getDirectories(testWeblog).length);
       
        // create a directory
        fmgr.createDirectory(testWeblog, "bucket0");
       
        // make sure directory was created
        WeblogResource[] dirs = fmgr.getDirectories(testWeblog);
        assertNotNull(dirs);
        assertEquals(1, dirs.length);
        assertEquals("bucket0", dirs[0].getName());
       
        // cleanup
        fmgr.deleteFile(testWeblog, "bucket0");
       
        // make sure delete was successful
        assertEquals(0, fmgr.getDirectories(testWeblog).length);
    }
View Full Code Here

TOP

Related Classes of org.apache.roller.business.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.