Package org.apache.struts.upload

Examples of org.apache.struts.upload.FormFile


            //retrieve the query string value
            String queryValue = theForm.getQueryParam();

            //retrieve the file representation
            FormFile file = theForm.getTheFile();

            //retrieve the file name
            String fileName= file.getFileName();

            //retrieve the content type
            String contentType = file.getContentType();

            boolean writeFile = theForm.getWriteFile();

            //retrieve the file size
            String size = (file.getFileSize() + " bytes");

            String data = null;

            try {
                //retrieve the file data
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                InputStream stream = file.getInputStream();
                if (!writeFile) {
                    //only write files out that are less than 1MB
                    if (file.getFileSize() < (4*1024000)) {

                        byte[] buffer = new byte[8192];
                        int bytesRead = 0;
                        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                            baos.write(buffer, 0, bytesRead);
                        }
                        data = new String(baos.toByteArray());
                    }
                    else {
                        data = new String("The file is greater than 4MB, " +
                                " and has not been written to stream." +
                                " File Size: " + file.getFileSize() + " bytes. This is a" +
                                " limitation of this particular web application, hard-coded" +
                                " in org.apache.struts.webapp.upload.UploadAction");
                    }
                }
                else {
                    //write the file to the file specified
                    OutputStream bos = new FileOutputStream(theForm.getFilePath());
                    int bytesRead = 0;
                    byte[] buffer = new byte[8192];
                    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                        bos.write(buffer, 0, bytesRead);
                    }
                    bos.close();
                    data = "The file has been written to \"" + theForm.getFilePath() + "\"";
                }
                //close the stream
                stream.close();
            }
            catch (FileNotFoundException fnfe) {
                return null;
            }
            catch (IOException ioe) {
                return null;
            }

            //place the data into the request for retrieval from display.jsp
            request.setAttribute("text", text);
            request.setAttribute("queryValue", queryValue);
            request.setAttribute("fileName", fileName);
            request.setAttribute("contentType", contentType);
            request.setAttribute("size", size);
            request.setAttribute("data", data);

            //destroy the temporary file created
            file.destroy();

            //return a forward to display.jsp
            return mapping.findForward("display");
        }

View Full Code Here


            //retrieve the text data
            String text = theForm.getTheText();

            //retrieve the file representation
            FormFile file = theForm.getTheFile();

            //retrieve the file name
            String fileName= file.getFileName();

            //retrieve the content type
            String contentType = file.getContentType();

            boolean writeFile = theForm.getWriteFile();

            //retrieve the file size
            String size = (file.getFileSize() + " bytes");

            String data = null;

            try {
                //retrieve the file data
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                InputStream stream = file.getInputStream();
                if (!writeFile) {
                    //only write files out that are less than 1MB
                    if (file.getFileSize() < (4*1024000)) {

                        byte[] buffer = new byte[8192];
                        int bytesRead = 0;
                        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                            baos.write(buffer, 0, bytesRead);
                        }
                        data = new String(baos.toByteArray());
                    }
                    else {
                        data = new String("The file is greater than 4MB, " +
                                " and has not been written to stream." +
                                " File Size: " + file.getFileSize() + " bytes. This is a" +
                                " limitation of this particular web application, hard-coded" +
                                " in org.apache.struts.webapp.upload.UploadAction");
                    }
                }
                else {
                    //write the file to the file specified
                    OutputStream bos = new FileOutputStream(theForm.getFilePath());
                    int bytesRead = 0;
                    byte[] buffer = new byte[8192];
                    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                        bos.write(buffer, 0, bytesRead);
                    }
                    bos.close();
                    data = "The file has been written to \"" + theForm.getFilePath() + "\"";
                }
                //close the stream
                stream.close();
            }
            catch (FileNotFoundException fnfe) {
                return null;
            }
            catch (IOException ioe) {
                return null;
            }

            //place the data into the request for retrieval from display.jsp
            request.setAttribute("text", text);
            request.setAttribute("fileName", fileName);
            request.setAttribute("contentType", contentType);
            request.setAttribute("size", size);
            request.setAttribute("data", data);

            //destroy the temporary file created
            file.destroy();

            //return a forward to display.jsp
            return mapping.findForward("display");
        }

View Full Code Here

  }
  public ActionForward execute(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    UploadForm uploadForm = (UploadForm) form;
    FormFile file = uploadForm.getFile();
    InputStream stream = file.getInputStream();
    String applicationId = (String) request.getSession().getAttribute(ConsoleCst.APPLICATION_ID);
    Application application = applicationService.get(applicationId,(Collection)request.getSession().getAttribute(ConsoleCst.APPLICATIONS_SESSION_BEAN));
    mappingService.importApplicationConfig(application,stream);
    stream.close();
    file.destroy();
    request.setAttribute("retUpload","true");
    request.getSession().setAttribute(ConsoleCst.IS_APPLICATION_MODIFIED,ConsoleCst.APPLICATION_MODIFIED);
    return mapping.findForward("index");
  }
View Full Code Here

        if(sysimgForm.getUpFile().getFileSize() > 0){
         
          try{
            sqlMap.startTransaction();
            sqlMap.update("SystemImg.systemimgUpdate", sysimgForm);
            FormFile uploadFile = sysimgForm.getUpFile();
            FileManager.fileUpload(uploadFile, sysimgForm.getSysimgUid(), sysimgForm.getSysimgGubun());
           
            /**
             * 파일을 삭제합니다.
             */
 
View Full Code Here

       
      SystemImg sysimgForm = (SystemImg)form;
        try{
          sqlMap.startTransaction();
          int sysimgUid = (Integer) sqlMap.insert("SystemImg.systemimgInsert", sysimgForm);
          FormFile uploadFile = sysimgForm.getUpFile();
          FileManager.fileUpload(uploadFile, sysimgUid, sysimgForm.getSysimgGubun());
         
          sqlMap.commitTransaction();
         
      ActionMessages messages = new ActionMessages();
View Full Code Here

        super.populateObject(request, object, form);

        NoteEditorForm noteForm = (NoteEditorForm)form;
        Note note = (Note)object;

        FormFile formFile = noteForm.getFormFile();
        if (formFile != null) {
            String filename = formFile.getFileName();
            if (StringUtils.isNotEmpty(filename)) {
                String contentType = formFile.getContentType();
                InputStream input = formFile.getInputStream();
                int fileSize = formFile.getFileSize();
                int projectId = request.getParameter("projectId") != null ?
                        Integer.parseInt(request.getParameter("projectId")) : 0;
                Directory directory = fileSystem.getDirectory("/attachments/project/"+projectId);
                File file = fileSystem.createFile(directory, filename, contentType, fileSize, input);
                note.setFile(file);
View Full Code Here

                fform.setAction("list");
                fform.setDirectoryId(Integer.toString(
                        fileSystem.getRootDirectory().getId()));
            }
            if (fform.getAction().equals("upload")) {
                FormFile formFile = fform.getFormFile();
                fileSystem.createFile(hibernateSession, Integer.parseInt(fform.getDirectoryId()), formFile.getFileName(),
                        formFile.getContentType(), formFile.getFileSize(), formFile.getInputStream());
            } else if (fform.getAction().equals("download")) {
                File file = fileSystem.getFile(hibernateSession, Integer.parseInt(fform.getFileId()));
                writeFileToResponse(response, file);
            } else if (fform.getAction().equals("delete")) {
                fileSystem.deleteFile(hibernateSession, Integer.parseInt(fform.getFileId()));
View Full Code Here

    protected void setUp() throws Exception {
        support = new XPlannerTestSupport();
        form = new NoteEditorForm();
        form.setSubject("subject");
        form.setBody("body");
        FormFile testFile = new DiskFile("data/TestAttachment.txt");
        form.setFormFile(testFile);
        form.setAuthorId(100);
    }
View Full Code Here

        AbstractContest contest = context.getContest();

        InputStream in = null;
        String filePath = context.getRequest().getParameter("problemFilePath");
        FormFile file = ((ProblemImportForm) form).getProblemFile();

        if (filePath != null && filePath.trim().length() > 0) {
            in = new FileInputStream(filePath);
        } else if (file != null) {
            in = file.getInputStream();
        }
        if (in != null) {
            ActionMessages messages = new ActionMessages();
            pack = ProblemManager.importProblem(in, messages);
            // seePackage(pack, messages);
View Full Code Here

            //retrieve the query string value
            String queryValue = theForm.getQueryParam();

            //retrieve the file representation
            FormFile file = theForm.getTheFile();

            //retrieve the file name
            String fileName= file.getFileName();

            //retrieve the content type
            String contentType = file.getContentType();

            boolean writeFile = theForm.getWriteFile();

            //retrieve the file size
            String size = (file.getFileSize() + " bytes");

            String data = null;

            try {
                //retrieve the file data
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                InputStream stream = file.getInputStream();
                if (!writeFile) {
                    //only write files out that are less than 1MB
                    if (file.getFileSize() < (4*1024000)) {

                        byte[] buffer = new byte[8192];
                        int bytesRead = 0;
                        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                            baos.write(buffer, 0, bytesRead);
                        }
                        data = new String(baos.toByteArray());
                    }
                    else {
                        data = new String("The file is greater than 4MB, " +
                                " and has not been written to stream." +
                                " File Size: " + file.getFileSize() + " bytes. This is a" +
                                " limitation of this particular web application, hard-coded" +
                                " in org.apache.struts.webapp.upload.UploadAction");
                    }
                }
                else {
                    //write the file to the file specified
                    OutputStream bos = new FileOutputStream(theForm.getFilePath());
                    int bytesRead = 0;
                    byte[] buffer = new byte[8192];
                    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                        bos.write(buffer, 0, bytesRead);
                    }
                    bos.close();
                    data = "The file has been written to \"" + theForm.getFilePath() + "\"";
                }
                //close the stream
                stream.close();
            }
            catch (FileNotFoundException fnfe) {
                return null;
            }
            catch (IOException ioe) {
                return null;
            }

            //place the data into the request for retrieval from display.jsp
            request.setAttribute("text", text);
            request.setAttribute("queryValue", queryValue);
            request.setAttribute("fileName", fileName);
            request.setAttribute("contentType", contentType);
            request.setAttribute("size", size);
            request.setAttribute("data", data);

            //destroy the temporary file created
            file.destroy();

            //return a forward to display.jsp
            return mapping.findForward("display");
        }

View Full Code Here

TOP

Related Classes of org.apache.struts.upload.FormFile

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.