Package org.apache.roller.business

Examples of org.apache.roller.business.FileManager


        ((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 files and 0 directories
        assertEquals(0, fmgr.getFiles(testWeblog, null).length);
        assertEquals(0, fmgr.getDirectories(testWeblog).length);
       
        // create a directory
        fmgr.createDirectory(testWeblog, "bucket1");
       
        // make sure directory was created
        WeblogResource[] dirs = fmgr.getDirectories(testWeblog);
        assertNotNull(dirs);
        assertEquals(1, dirs.length);
        assertEquals("bucket1", dirs[0].getName());
       
        // store a file into a subdirectory
        InputStream is = getClass().getResourceAsStream("/bookmarks.opml");
        fmgr.saveFile(testWeblog, "bucket1/bookmarks.opml", "text/plain", 1545, is);
       
        // make sure file was stored successfully
        assertEquals("bucket1/bookmarks.opml",
                fmgr.getFile(testWeblog, "bucket1/bookmarks.opml").getPath());
        assertEquals(1, fmgr.getFiles(testWeblog, "bucket1").length);
       
        // cleanup
        fmgr.deleteFile(testWeblog, "bucket1/bookmarks.opml");
        fmgr.deleteFile(testWeblog, "bucket1");
       
        // we should be back to 0 files and 0 directories
        assertEquals(0, fmgr.getFiles(testWeblog, null).length);
        assertEquals(0, fmgr.getDirectories(testWeblog).length);
    }
View Full Code Here


     *
     * This should test all conditions where a save should fail.
     */
    public void testCanSave() throws Exception {
       
        FileManager fmgr = RollerFactory.getRoller().getFileManager();
        PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager();
        Map config = config = pmgr.getProperties();
        ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00");
        ((RollerPropertyData)config.get("uploads.types.forbid")).setValue("");
        ((RollerPropertyData)config.get("uploads.types.allowed")).setValue("");
        ((RollerPropertyData)config.get("uploads.enabled")).setValue("true");
        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        Exception exception = null;
        InputStream is = null;
       
        try {
            // path check should fail
            fmgr.saveFile(testWeblog, "some/path/foo.gif", "text/plain", 10, is);
        } catch (Exception ex) {
            log.error(ex);
            exception = ex;
        }
        assertNotNull(exception);
        exception = null;
       
        config = pmgr.getProperties();
        ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00");
        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        try {
            // quota check should fail
            fmgr.saveFile(testWeblog, "test.gif", "text/plain", 2500000, is);
        } catch (Exception ex) {
            log.error(ex);
            exception = ex;
        }
        assertNotNull(exception);
        exception = null;
       
       
        config = pmgr.getProperties();
        ((RollerPropertyData)config.get("uploads.types.forbid")).setValue("gif");
        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        try {
            // forbidden types check should fail
            fmgr.saveFile(testWeblog, "test.gif", "text/plain", 10, is);
        } catch (Exception ex) {
            log.error(ex);
            exception = ex;
        }
        assertNotNull(exception);
        exception = null;
       
       
        config = pmgr.getProperties();
        ((RollerPropertyData)config.get("uploads.enabled")).setValue("false");
        pmgr.saveProperties(config);
        TestUtils.endSession(true);
       
        try {
            // uploads disabled should fail
            fmgr.saveFile(testWeblog, "test.gif", "text/plain", 10, is);
        } catch (Exception ex) {
            log.error(ex);
            exception = ex;
        }
        assertNotNull(exception);
View Full Code Here

           
            // save our updated website
            userMgr.saveWebsite(website);
           
            // now lets import all the theme resources
            FileManager fileMgr = RollerFactory.getRoller().getFileManager();
           
            List resources = theme.getResources();
            Iterator iterat = resources.iterator();
            File resourceFile = null;
            while ( iterat.hasNext() ) {
                resourceFile = (File) iterat.next();
               
                String path = resourceFile.getAbsolutePath().substring(
                        this.themeDir.length()+theme.getName().length()+1);
               
                // make sure path isn't prefixed with a /
                if(path.startsWith("/")) {
                    path = path.substring(1);
                }
               
                log.debug("Importing resource "+resourceFile.getAbsolutePath()+" to "+path);
               
                try {
                    if(resourceFile.isDirectory()) {
                        fileMgr.createDirectory(website, path);
                    } else {
                        fileMgr.saveFile(website, path, "text/plain",
                                resourceFile.length(), new FileInputStream(resourceFile));
                    }
                } catch (Exception ex) {
                    log.info(ex);
                }
View Full Code Here

                mRoller.getUserManager().getWebsiteByHandle(handle);
            if (website == null) {
                throw new AtomNotFoundException(
                    "ERROR: cannot find specified weblog");
            }
            FileManager fmgr = mRoller.getFileManager();
            WeblogResource[] files = fmgr.getFiles(website, null);
                       
            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, 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();

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