Package org.apache.roller.ui.authoring.struts.formbeans

Examples of org.apache.roller.ui.authoring.struts.formbeans.UploadFileForm


        if (rses.isUserAuthorizedToAuthor(website)) {
           
            fwd = mapping.findForward("uploadFiles.page");
           
            // this is the path in the uploads area that is being used
            UploadFileForm uploadForm = (UploadFileForm) actionForm;
            String path = uploadForm.getPath();
           
            UploadFilePageModel pageModel = new UploadFilePageModel(
                    request, response, mapping, website, path);
            pageModel.setWebsite(website);
            request.setAttribute("model", pageModel);
View Full Code Here


            throws Exception {
       
        ActionForward fwd = mapping.findForward("access-denied");
        ActionMessages messages = new ActionMessages();
        ActionErrors errors = new ActionErrors();
        UploadFileForm theForm = (UploadFileForm) actionForm;
       
        WebsiteData website = getWebsite(request);
        RollerSession rses = RollerSession.getRollerSession(request);
        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) {
View Full Code Here

            throws Exception {
       
        ActionForward fwd = mapping.findForward("access-denied");
        ActionMessages messages = new ActionMessages();
        ActionErrors errors = new ActionErrors();
        UploadFileForm theForm = (UploadFileForm) actionForm;
       
        WebsiteData website = getWebsite(request);
        RollerSession rses = RollerSession.getRollerSession(request);
        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);
                       
                        //destroy the temporary file created
                        files[i].destroy();
                    } catch (FilePathException ex) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                                new ActionError("uploadFiles.error.badPath", fileName));
                    } catch (FileNotFoundException ex) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                                new ActionError("uploadFiles.error.badPath", fileName));
                    } catch (FileIOException ex) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                                new ActionError("uploadFiles.error.upload", fileName));
                    }
                }
            }
           
            if(uploaded.size() > 0) {
                messages.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("uploadFiles.uploadedFiles"));
               
                Iterator uploads = uploaded.iterator();
                while (uploads.hasNext()) {
                    messages.add(ActionMessages.GLOBAL_MESSAGE,
                            new ActionMessage("uploadFiles.uploadedFile",
                            URLUtilities.getWeblogResourceURL(website, (String)uploads.next(), true)));
                }
                saveMessages(request, messages);
            }
           
            if(!errors.isEmpty()) {
                saveErrors(request, errors);
            }
           
            UploadFilePageModel pageModel = new UploadFilePageModel(
                    request, response, mapping, website, theForm.getPath(), uploaded);
            request.setAttribute("model", pageModel);
            pageModel.setWebsite(website);
        }
       
        return fwd;
View Full Code Here

            throws Exception {
       
        ActionForward fwd = mapping.findForward("access-denied");
        ActionMessages messages = new ActionMessages();
        ActionErrors errors = new ActionErrors();
        UploadFileForm theForm = (UploadFileForm) actionForm;
       
        WebsiteData website = getWebsite(request);
        RollerSession rses = RollerSession.getRollerSession(request);
        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) {
                            errors.add(ActionErrors.GLOBAL_ERROR,
                                    new ActionError("uploadFiles.error.badPath"));
                        } catch (FileIOException ex) {
                            errors.add(ActionErrors.GLOBAL_ERROR,
                                    new ActionError("uploadFiles.error.delete", deleteFiles[i]));
                        }
                       
                    }
                }
            }
           
            if(numDeleted > 0) {
                messages.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("uploadFiles.deletedFiles", new Integer(numDeleted)));
                saveMessages(request, messages);
            }
           
            if(!errors.isEmpty()) {
                saveErrors(request,errors);
            }
           
            UploadFilePageModel pageModel = new UploadFilePageModel(
                    request, response, mapping, website, theForm.getPath());
            pageModel.setWebsite(website);
            request.setAttribute("model", pageModel);
        }
       
        return fwd;
View Full Code Here

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

            HttpServletResponse response)
            throws Exception {
       
        ActionMessages messages = new ActionMessages();
        ActionErrors errors = new ActionErrors();
        UploadFileForm theForm = (UploadFileForm)actionForm;
        ActionForward fwd = mapping.findForward("access-denied");
        WebsiteData website = getWebsite(request);
       
        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 '..'
View Full Code Here

TOP

Related Classes of org.apache.roller.ui.authoring.struts.formbeans.UploadFileForm

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.