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 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

      throw new InputException(resources.getMessage(locale, "um.userSetNotFound",userSetId));
    }
   
    checkAccessRights(req, userSet.getGroup());
   
    FormFile csvFile = userImportForm.getCsvFile();
    if (csvFile != null && csvFile.getFileName() != null && csvFile.getFileName().length() != 0){
      try {
        InputStream inputStream = csvFile.getInputStream();
        UserManager userManager = new UserManager(locale,session);
       
        UserImportResult importResult = userManager.importData(inputStream, userImportForm.getCharacterSet(), userImportForm.getDelimiter(),userSet,
            userImportForm.getMergeSelection().equals("userName"),
            userImportForm.getMergeSelection().equals("msisdn"),
            userImportForm.getMergeSelection().equals("personnelNumber"));
        inputStream.close();
       
        req.setAttribute("userImportCounter", importResult.getUsersCreated());
        req.setAttribute("userUpdateCounter", importResult.getUsersUpdated());
        req.setAttribute("userIgnoreCounter", importResult.getUsersIgnored());
        req.setAttribute("userImportErrormessages", importResult.getErrorMessages());
       
      } catch (FileNotFoundException e){
        throw new InputException(resources.getMessage(locale, "um.fileNotFound",csvFile.getFileName()),e);
      } catch (IOException e) {
        throw new InputException(resources.getMessage(locale, "um.couldNotReadFile",csvFile.getFileName()),e);
      }
    } else {
      throw new InputException(resources.getMessage(locale, "um.fileNotFound"));
    }
   
View Full Code Here

                response.setContentType("text/html; charset=utf-8");
            }           
            boolean writeFile = false;
           
            //retrieve the file representation
            FormFile file = theForm.getBookmarksFile();
            String data = null;
            InputStream stream = null;
            try {
              
                //retrieve the file data
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                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());
                       
                        SimpleDateFormat formatter =
                                new SimpleDateFormat("yyyyMMddHHmmss");
                        Date now = new Date();
                        String folderName = "imported-" + formatter.format(now);
                       
                        // Use Roller BookmarkManager to import bookmarks

                        bm.importBookmarks(website, folderName, data)
                        RollerFactory.getRoller().flush();
                        CacheManager.invalidate(website);
                       
                        ActionMessages messages = new ActionMessages();
                        messages.add(ActionMessages.GLOBAL_MESSAGE,
                           new ActionMessage("bookmarksImport.imported", folderName));
                        saveMessages(request, messages);
                    }
                    else {
                        data = "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";
                        errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError("bookmarksImport.error",data));
                    }
                }
               
            }
            catch (Exception e) {
                errors.add(ActionErrors.GLOBAL_ERROR,
                     new ActionError("bookmarksImport.error",e.toString()));
                saveErrors(request,errors);
                mLogger.error("ERROR: importing bookmarks",e);
            }
            finally {
                if ( stream!=null ) {
                    try { stream.close(); }
                    catch (Exception e) { mLogger.error("Closing stream",e); };
                }
            }           
            //destroy the temporary file created
            file.destroy();
        }
        else if (!rses.isUserAuthorizedToAuthor(website)) {
            fwd = mapping.findForward("access-denied");
        }       
        return fwd;
View Full Code Here

    FileItem currentItem;
    for (int i = 0; i < items.size(); i++) {

      currentItem = (FileItem) items.get(i);
      FormFile formFile = new CommonsFormFile(currentItem);

      elementsFile.put(currentItem.getFieldName(), formFile);
      elementsAll.put(currentItem.getFieldName(), formFile);
    }
  }
View Full Code Here

  public void rollback() {

    Iterator iter = elementsFile.values().iterator();

    while (iter.hasNext()) {
      FormFile formFile = (FormFile) iter.next();

      formFile.destroy();
    }
  }
View Full Code Here

  private static Object rationalizeMultipleFileProperty(Object bean, String name, Object parameterValue) throws ServletException {
    if (!(parameterValue instanceof FormFile)) {
      return parameterValue;
    }

    FormFile formFileValue = (FormFile) parameterValue;
    try {
      Class propertyType = PropertyUtils.getPropertyType(bean, name);

      if (propertyType == null) {
        return parameterValue;
View Full Code Here

    private static Object rationalizeMultipleFileProperty(Object bean, String name, Object parameterValue) throws ServletException {
        if (!(parameterValue instanceof FormFile)) {
            return parameterValue;
        }

        FormFile formFileValue = (FormFile) parameterValue;
        try {
            Class propertyType = PropertyUtils.getPropertyType(bean, name);

            if (List.class.isAssignableFrom(propertyType)) {
                ArrayList list = new ArrayList(1);
View Full Code Here

    public ActionForward execute(ActionMapping mapping, ActionForm form,
        UserContainer user, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
        DataConfig config = (DataConfig) getDataConfig();
        StylesEditorForm stylesForm = (StylesEditorForm) form;
        FormFile file = stylesForm.getSldFile();
        final String filename = file.getFileName();
        final String styleID = stylesForm.getStyleID();

        StyleConfig style = user.getStyle();
       

       
        boolean doFullValidation = stylesForm.getFullyValidate();
        if (stylesForm.getFullyValidateChecked() == false) {
          doFullValidation = false;
        }
       
        if (doFullValidation)
        {
          List l = getSchemaExceptions(file,request);
          if (l.size() !=0)
          {
            handleValidationErrors(l,file,stylesForm);           
            return mapping.findForward("schemaErrors");
          }
        }

        if (style == null) {
            // Must of bookmarked? Redirect so they can select           
            return mapping.findForward("config.data.style");
        }

 
  ServletContext sc = getServlet().getServletContext();
        //DJB: changed for geoserver_data_dir
        //File rootDir = new File(getServlet().getServletContext().getRealPath("/"));
        File rootDir = GeoserverDataDirectory.getGeoserverDataDirectory(sc);
 
  File styleDir;
  try {
      styleDir = GeoserverDataDirectory.findConfigDir(rootDir, "styles");
  } catch (ConfigurationException cfe) {
            LOGGER.warning("no style dir found, creating new one");
            //if for some bizarre reason we don't fine the dir, make a new one.
            styleDir = new File(rootDir, "styles");
  }
        // send content of FormFile to /styles :
        // there nothing to keep the styles in memory for XMLConfigWriter.store()
        InputStreamReader isr = new InputStreamReader(file.getInputStream());
        File newSldFile = new File(styleDir, filename);

        //here we do a check to see if the file we are trying to upload is
        //overwriting another style file.
        LOGGER.fine("new sld file is: " + newSldFile + ", exists: "
View Full Code Here

                response.setContentType("text/html; charset=utf-8");
            }           
            boolean writeFile = false;
           
            //retrieve the file representation
            FormFile file = theForm.getBookmarksFile();
            String data = null;
            InputStream stream = null;
            try {
              
                //retrieve the file data
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                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());
                       
                        SimpleDateFormat formatter =
                                new SimpleDateFormat("yyyyMMddHHmmss");
                        Date now = new Date();
                        String folderName = "imported-" + formatter.format(now);
                       
                        // Use Roller BookmarkManager to import bookmarks

                        bm.importBookmarks(website, folderName, data)
                        RollerFactory.getRoller().flush();
                        CacheManager.invalidate(website);
                       
                        ActionMessages messages = new ActionMessages();
                        messages.add(ActionMessages.GLOBAL_MESSAGE,
                           new ActionMessage("bookmarksImport.imported", folderName));
                        saveMessages(request, messages);
                    }
                    else {
                        data = "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";
                        errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError("bookmarksImport.error",data));
                    }
                }
               
            }
            catch (Exception e) {
                errors.add(ActionErrors.GLOBAL_ERROR,
                     new ActionError("bookmarksImport.error",e.toString()));
                saveErrors(request,errors);
                mLogger.error("ERROR: importing bookmarks",e);
            }
            finally {
                if ( stream!=null ) {
                    try { stream.close(); }
                    catch (Exception e) { mLogger.error("Closing stream",e); };
                }
            }           
            //destroy the temporary file created
            file.destroy();
        }
        else if (!rses.isUserAuthorizedToAuthor(website)) {
            fwd = mapping.findForward("access-denied");
        }       
        return fwd;
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.