Package org.apache.struts.upload

Examples of org.apache.struts.upload.FormFile


    JSONEscapeObject jsonResult = new JSONEscapeObject();

    Item item = new Item();
    item = ItemDAO.load(site.getSiteId(), Format.getLong(form.getKey()));

    FormFile file = form.getFile();
    byte fileData[] = file.getFileData();
    ActionMessages errors = validateUploadImage(form, file);
    if (errors.size() != 0) {
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("error.string.required"));
      streamWebService(response, jsonResult.toHtmlString());
    }
   
    ImageScaler scaler = null;
    try {
      scaler = new ImageScaler(fileData, file.getContentType());
      scaler.resize(600);
    }
    catch (OutOfMemoryError outOfMemoryError) {
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("content.error.image.size"));
      streamWebService(response, jsonResult.toHtmlString());
          return null;
    }
    catch (Throwable e) {
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("error.image.invalid"));
      streamWebService(response, jsonResult.toHtmlString());
          return null;
    }
   
    ItemLanguage itemLanguage = null;
    for (ItemLanguage language : item.getItemLanguages()) {
      if (language.getSiteProfileClass().getSiteProfileClassId().equals(form.getSiteProfileClassId())) {
        itemLanguage = language;
        break;
      }
    }
   
    if (form.isSiteProfileClassDefault()) {
      ItemImage itemImage = new ItemImage();
      itemImage.setImageName(file.getFileName());
      itemImage.setContentType("image/jpeg");
      itemImage.setImageValue(scaler.getBytes());
      itemImage.setImageHeight(scaler.getHeight());
      itemImage.setImageWidth(scaler.getWidth());
      itemImage.setRecUpdateBy(adminBean.getUser().getUserId());
      itemImage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
      itemImage.setRecCreateBy(adminBean.getUser().getUserId());
      itemImage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
      em.persist(itemImage);
      if (itemLanguage.getImage() == null) {
        itemLanguage.setImage(itemImage);
      }
      else {
        itemImage.setItemLanguage(itemLanguage);
        itemLanguage.getImages().add(itemImage);
      }
      itemLanguage.setRecUpdateBy(adminBean.getUser().getUserId());
      itemLanguage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
      em.persist(itemLanguage);
    }
    else {
      if (itemLanguage == null) {
        itemLanguage = new ItemLanguage();
        itemLanguage.setItem(item);
        itemLanguage.setRecCreateBy(adminBean.getUser().getUserId());
        itemLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
        SiteProfileClass siteProfileClass = SiteProfileClassDAO.load(form.getSiteProfileClassId());
        itemLanguage.setSiteProfileClass(siteProfileClass);
      }
      ItemImage itemImage = new ItemImage();
      itemImage.setImageName(file.getFileName());
      itemImage.setContentType("image/jpeg");
      itemImage.setImageValue(scaler.getBytes());
      itemImage.setImageHeight(scaler.getHeight());
      itemImage.setImageWidth(scaler.getWidth());
      itemImage.setRecUpdateBy(adminBean.getUser().getUserId());
View Full Code Here


    JSONEscapeObject jsonResult = new JSONEscapeObject();
   
    Content content = new Content();
    content = ContentDAO.load(site.getSiteId(), Format.getLong(form.getKey()));

    FormFile file = form.getFile();
    byte fileData[] = file.getFileData();
    if (Format.isNullOrEmpty(file.getFileName())) {
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("error.string.required"));
      streamWebService(response, jsonResult.toHtmlString());
          return null;
    }
   
    ImageScaler scaler = null;
    try {
      scaler = new ImageScaler(fileData, file.getContentType());
      scaler.resize(600);
    }
    catch (OutOfMemoryError outOfMemoryError) {
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("content.error.image.size"));
      streamWebService(response, jsonResult.toHtmlString());
          return null;
    }
    catch (Throwable e) {
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("error.image.invalid"));
      streamWebService(response, jsonResult.toHtmlString());
          return null;
    }
   
    ContentLanguage contentLanguage = null;
    for (ContentLanguage language : content.getContentLanguages()) {
      if (language.getSiteProfileClass().getSiteProfileClassId().equals(form.getSiteProfileClassId())) {
        contentLanguage = language;
        break;
      }
    }
   
    if (form.isSiteProfileClassDefault()) {
      ContentImage contentImage = new ContentImage();
      contentImage.setImageName(file.getFileName());
      contentImage.setContentType("image/jpeg");
      contentImage.setImageValue(scaler.getBytes());
      contentImage.setImageHeight(scaler.getHeight());
      contentImage.setImageWidth(scaler.getWidth());
      contentImage.setRecUpdateBy(adminBean.getUser().getUserId());
      contentImage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
      contentImage.setRecCreateBy(adminBean.getUser().getUserId());
      contentImage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
      em.persist(contentImage);
      if (contentLanguage.getImage() == null) {
        contentLanguage.setImage(contentImage);
      }
      else {
        contentImage.setContentLanguage(contentLanguage);
        contentLanguage.getImages().add(contentImage);
      }
      contentLanguage.setRecUpdateBy(adminBean.getUser().getUserId());
      contentLanguage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
      em.persist(contentLanguage);
    }
    else {
      if (contentLanguage == null) {
        contentLanguage = new ContentLanguage();
        contentLanguage.setContent(content);
        contentLanguage.setRecCreateBy(adminBean.getUser().getUserId());
        contentLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
        SiteProfileClass siteProfileClass = SiteProfileClassDAO.load(form.getSiteProfileClassId());
        contentLanguage.setSiteProfileClass(siteProfileClass);
        em.persist(contentLanguage);
      }
      ContentImage contentImage = new ContentImage();
      contentImage.setImageName(file.getFileName());
      contentImage.setContentType("image/jpeg");
      contentImage.setImageValue(scaler.getBytes());
      contentImage.setImageHeight(scaler.getHeight());
      contentImage.setImageWidth(scaler.getWidth());
      contentImage.setRecUpdateBy(adminBean.getUser().getUserId());
View Full Code Here

      return actionMapping.findForward("error");
        }
       
        String templateName = form.getTemplateName();
        if (Format.isNullOrEmpty(templateName)) {
          FormFile file = form.getFile();
          File f = new File(file.getFileName());
          String filename = f.getName().toLowerCase();
          templateName = filename.replaceAll("\\.jar", "");
      }
       
      String prefix = Utility.getTemplatePrefix(site, templateName);
View Full Code Here

   
    String siteDomainId = form.getSiteDomainId();
        SiteDomain siteDomain = SiteDomainDAO.load(Format.getLong(siteDomainId));

        JSONEscapeObject json = new JSONEscapeObject();
    FormFile file = form.getFile();
    byte fileData[] = file.getFileData();
    if (file.getFileName().length() == 0) {
      json.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      json.put("filename", resources.getMessage("error.string.required"));
      streamWebService(response, json.toHtmlString());
      return null;
    }
    ImageScaler scaler = new ImageScaler(fileData, file.getContentType());
    scaler.resize(600);

    initSiteProfiles(form, site);
        if (form.isSiteProfileClassDefault()) {
        siteDomain.getSiteDomainLanguage().setSiteLogoValue(scaler.getBytes());
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

     
      //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();
     
      //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();
                                byte[] buffer = new byte[file.getFileSize()];
                                stream.read(buffer);
                                baos.write(buffer);
                                data = new String(baos.toByteArray());
      }
      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

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

        FileData[] filedata = new FileData[files[0].size()];
        //populate filedata
        for (int i = 0; i < filedata.length; i++) {
            FileData fdata = new FileData();
            FileDataInfo finfo = new FileDataInfo();
            FormFile file = (FormFile) files[0].get(i);

            finfo.setContentType(file.getContentType());
            fdata.setData(file.getFileData());

            finfo.setDescription((String) files[1].get(i));
            finfo.setMessageId(mid);
            finfo.setName(file.getFileName());
            finfo.setSize(file.getFileSize());

            fdata.setInfo(finfo);

            filedata[i] = fdata;
        }
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

            // getName(), getType, isIndexed(), isMapped()
            if (df.get(oneName) != null && df.get(oneName) instanceof FormFile)
            {
              log.debug("Formfile");

              FormFile fileInfo = (FormFile) df.get(oneName);

              if (fileInfo != null && fileInfo.getFileSize() > 0)
              {
                BufferedInputStream inStream = null;

                try
                {
                  inStream = new BufferedInputStream(fileInfo.getInputStream(), BUFFER_SIZE);
                }
                catch (IOException e)
                {
                  throw new ClientException(e.getMessage(), e);
                }

                // Problem - DefaultFileItem is not comprised
                // completely of serializable components.
                // final FileItem fileItem =
                // DFIF.createItem(oneName,
                // fileInfo.getContentType(), false,
                // fileInfo.getFileName());
                // So we use BinaryWrapper instead, which is
                // completely serializable
                // TODO: Reset First parameter with Context Name
                // so that this will work over distributed
                // environments(I could not find the call to get
                // it - SPD)
                final BinaryWrapper fileWrapper = new BinaryWrapper(null, hreq.getContentType(),
                        fileInfo.getFileName(), BUFFER_SIZE, null);

                try
                {
                  final long written = fileWrapper.writeFrom(inStream);
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.