org.apache.struts.upload.FormFile Java Examples
The following examples show how to use
org.apache.struts.upload.FormFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Email.java From unitime with Apache License 2.0 | 6 votes |
public void addAttachment(final FormFile file) throws Exception { addAttachment(file.getFileName(), new DataHandler(new DataSource() { @Override public OutputStream getOutputStream() throws IOException { throw new IOException("No output stream."); } @Override public String getName() { return file.getFileName(); } @Override public InputStream getInputStream() throws IOException { return file.getInputStream(); } @Override public String getContentType() { return file.getContentType(); } })); }
Example #2
Source File: KualiMaintenanceForm.java From rice with Educational Community License v2.0 | 6 votes |
private void populateAttachmentFile(MaintenanceDocumentBase maintenanceDocument, String propertyName, FormFile propertyValue) { if(StringUtils.isNotEmpty(((FormFile)propertyValue).getFileName())) { Object boClass; String boPropertyName; Matcher matcher = ELEMENT_IN_COLLECTION.matcher(propertyName); if (propertyName.startsWith(KRADConstants.MAINTENANCE_ADD_PREFIX)) { String prefix = matcher.matches() ? "" : KRADConstants.MAINTENANCE_ADD_PREFIX; String collectionName = parseAddCollectionName(propertyName.substring(prefix.length())); boClass = maintenanceDocument.getNewMaintainableObject().getNewCollectionLine(collectionName); boPropertyName = propertyName.substring(prefix.length()).substring(collectionName.length() + 1); setAttachmentProperty(boClass, boPropertyName, propertyValue); } else { boClass = maintenanceDocument.getNewMaintainableObject().getBusinessObject(); boPropertyName = propertyName; if(StringUtils.isNotEmpty(((FormFile)propertyValue).getFileName()) && !matcher.matches()) { maintenanceDocument.setFileAttachment((FormFile) propertyValue); } setAttachmentProperty(boClass, boPropertyName, propertyValue); } } }
Example #3
Source File: FormComponentsAction.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private List<String> getDuplicateFilenames(FormComponentsForm actionForm) { ArrayList<String> validFilenames = new ArrayList<>(); ArrayList<String> duplicateFilenames = new ArrayList<>(); for (Map.Entry<Integer, FormFile> entry : actionForm.getAllNewFiles().entrySet()) { String filename = entry.getValue().getFileName(); // Skip empty entries if (StringUtils.isNotBlank(filename)) { if (validFilenames.contains(filename)) { duplicateFilenames.add(filename); } else { validFilenames.add(filename); } } } return duplicateFilenames; }
Example #4
Source File: StrutsDelegate.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Util to get the String file name of a file upload form. * * @param form to get the contents from * @param paramName of the FormFile * @return String file name of the upload. */ public String getFormFileName(DynaActionForm form, String paramName) { if (form.getDynaClass().getDynaProperty(paramName) == null) { return ""; } FormFile f = (FormFile)form.get(paramName); return f.getFileName(); }
Example #5
Source File: ExtendedMultiPartRequestHandler.java From jivejdon with Apache License 2.0 | 5 votes |
/** * Cleans up when a problem occurs during request processing. */ public void rollback() { Iterator iter = elementsFile.values().iterator(); while (iter.hasNext()) { FormFile formFile = (FormFile) iter.next(); formFile.destroy(); } }
Example #6
Source File: MyTools.java From Films with Apache License 2.0 | 5 votes |
public static String uploadFilmPhoto(HttpServletRequest request,FormFile ff,String id){ String newPhotoName=""; try{ //���Ǹ�ÿ���û������Լ����ļ���. String filePath=request.getSession().getServletContext().getRealPath("/"); //filePath���ǵ�ǰ���webӦ���Ǿ��·�� F:\apache-tomcat-6.0.20\webapps\xiaoneinew //E:\Workspaces\MyEclipse 10\.metadata\.me_tcat\webapps\Films\ InputStream stream = ff.getInputStream();// ���ļ����� String oldPhotoName=ff.getFileName(); newPhotoName=id+oldPhotoName.substring(oldPhotoName.indexOf("."), oldPhotoName.length()); String newFullNewPath=filePath+File.separator+"upload"+File.separator+"movie"+File.separator; //�ж�newFullNewPath�ļ����Ƿ���� File f=new File(newFullNewPath); if(!f.isDirectory()){ //�����ļ���,�������� f.mkdirs(); } //���ϴ���ͷ�������ɳ� ���.�� OutputStream bos = new FileOutputStream(newFullNewPath+ newPhotoName); int len = 0; byte[] buffer = new byte[8192]; while ((len = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, len);// ���ļ�д������� } bos.close(); stream.close(); } catch (Exception e) { e.printStackTrace(); } return newPhotoName; }
Example #7
Source File: ConfigFileForm.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Validate a file-upload. This checks that: * <ul> * <li>The file exists * <li>The file isn't too large * <li>If the file is text, its contents are valid after macro-substitution * </ul> * @param request the incoming request * @return a ValidatorResult.. The list is empty if everything is OK */ public ValidatorResult validateUpload(HttpServletRequest request) { ValidatorResult msgs = new ValidatorResult(); FormFile file = (FormFile)get(REV_UPLOAD); //make sure there is a file if (file == null || file.getFileName() == null || file.getFileName().trim().length() == 0) { msgs.addError(new ValidatorError("error.config-not-specified")); } else if (file.getFileSize() == 0) { msgs.addError(new ValidatorError("error.config-empty", file.getFileName())); } //make sure they didn't send in something huge else if (file.getFileSize() > ConfigFile.getMaxFileSize()) { msgs.addError(new ValidatorError("error.configtoolarge", StringUtil.displayFileSize(ConfigFile.getMaxFileSize(), false))); } // It exists and isn't too big - is it text? else if (!isBinary()) { try { String content = new String(file.getFileData()); String startDelim = getString(REV_MACROSTART); String endDelim = getString(REV_MACROEND); msgs.append(ConfigurationValidation.validateContent( content, startDelim, endDelim)); } catch (Exception e) { msgs.addError(new ValidatorError("error.fatalupload", StringUtil.displayFileSize( ConfigFile.getMaxFileSize(), false))); } } return msgs; }
Example #8
Source File: ComMailingAttachmentsAction.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private static boolean newAttachmentHasName(ComMailingAttachmentsForm form) { FormFile file = form.getNewAttachment(); if (file == null || file.getFileSize() <= 0) { // No upload file (size <= 0)? Then we don't need a name. return true; } else { return StringUtils.isNotBlank(form.getNewAttachmentName()); } }
Example #9
Source File: StrutsDelegate.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Util to get the String version of a file upload form. Not useful if the * upload is binary. * * @param form to get the contents from * @param paramName of the FormFile * @return String version of the upload. */ // TODO Write unit tests for getFormFileString(DynaActionForm, String) public String getFormFileString(DynaActionForm form, String paramName) { if (form.getDynaClass().getDynaProperty(paramName) == null) { return ""; } FormFile f = (FormFile)form.get(paramName); return extractString(f); }
Example #10
Source File: StrutsDelegate.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Util to get the String file name of a file upload form. * * @param form to get the contents from * @param paramName of the FormFile * @return String file name of the upload. */ public String getFormFileName(DynaActionForm form, String paramName) { if (form.getDynaClass().getDynaProperty(paramName) == null) { return ""; } FormFile f = (FormFile)form.get(paramName); return f.getFileName(); }
Example #11
Source File: AdvancedModeDetailsAction.java From spacewalk with GNU General Public License v2.0 | 5 votes |
private void validateInput(DynaActionForm form, RequestContext context) { String label = form.getString(KICKSTART_LABEL_PARAM); KickstartBuilder builder = new KickstartBuilder(context.getCurrentUser()); if (isCreateMode(context.getRequest())) { builder.validateNewLabel(label); } else { KickstartRawData data = getKsData(context); if (!data.getLabel().equals(label)) { builder.validateNewLabel(label); } } ValidatorResult result = RhnValidationHelper.validate(this.getClass(), makeValidationMap(form), null, VALIDATION_XSD); if (!result.isEmpty()) { throw new ValidatorException(result); } FormFile file = (FormFile) form.get(FILE_UPLOAD); String contents = form.getString(CONTENTS); if (!file.getFileName().equals("") && !contents.equals("")) { ValidatorException.raiseException("kickstart.details.duplicatefile"); } KickstartableTree tree = KickstartFactory.lookupKickstartTreeByIdAndOrg( (Long) form.get(KSTREE_ID_PARAM), context.getCurrentUser().getOrg()); KickstartVirtualizationType vType = KickstartFactory.lookupKickstartVirtualizationTypeByLabel( form.getString(VIRTUALIZATION_TYPE_LABEL_PARAM)); Distro distro = CobblerProfileCommand.getCobblerDistroForVirtType(tree, vType, context.getCurrentUser()); if (distro == null) { ValidatorException.raiseException("kickstart.cobbler.profile.invalidvirt"); } }
Example #12
Source File: ManageRevisionSubmit.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Accepts an uploaded file as the new revision for the current config file. * @param mapping struts action mapping. * @param form struts action form * @param request Http Request * @param response Http Response * @return The ActionForward to the next page. * @throws IOException If the file has trouble. */ public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { RequestContext requestContext = new RequestContext(request); checkAcl(requestContext); Long cfid = requestContext.getRequiredParam(ConfigActionHelper.FILE_ID); User user = requestContext.getCurrentUser(); //get a connection to the file stream ConfigFileForm cff = (ConfigFileForm)form; ValidatorResult result = cff.validateUpload(request); if (!result.isEmpty()) { getStrutsDelegate().saveMessages(request, result); return getStrutsDelegate().forwardParam( mapping.findForward(RhnHelper.DEFAULT_FORWARD), ConfigActionHelper.FILE_ID, cfid.toString()); } //The file is there and small enough, make a new revision! FormFile file = (FormFile)cff.get(ConfigFileForm.REV_UPLOAD); ConfigRevision rev = ConfigurationManager.getInstance() .createNewRevision(user, new BufferedInputStream(file.getInputStream()), cfid, (long) file.getFileSize()); //create the success message createUploadSuccessMessage(rev, request, cfid); return getStrutsDelegate().forwardParam( mapping.findForward(RhnHelper.DEFAULT_FORWARD), ConfigActionHelper.FILE_ID, cfid.toString()); }
Example #13
Source File: ProcurementCardAction.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * This method handles retrieving the actual upload file as an input stream into the document. * * @param isSource * @param form * @throws FileNotFoundException * @throws IOException */ protected void uploadTargetAccountingLines(ActionForm form, int tranasactionIndex) throws FileNotFoundException, IOException { ProcurementCardForm pcardForm = (ProcurementCardForm) form; List importedLines = null; ProcurementCardDocument procurementCardDocument = (ProcurementCardDocument) pcardForm.getFinancialDocument(); ProcurementCardTransactionDetail transactionDetail = (ProcurementCardTransactionDetail) procurementCardDocument.getTransactionEntries().get(tranasactionIndex); AccountingLineParser accountingLineParser = procurementCardDocument.getAccountingLineParser(); // import the lines String errorPathPrefix = null; try { errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.TARGET_ACCOUNTING_LINE_ERRORS; // get the import file FormFile targetFile = ((ProcurementCardTransactionDetail) (procurementCardDocument.getTransactionEntries().get(tranasactionIndex))).getTargetFile(); checkUploadFile(targetFile); importedLines = accountingLineParser.importTargetAccountingLines(targetFile.getFileName(), targetFile.getInputStream(), procurementCardDocument); } catch (AccountingLineParserException e) { GlobalVariables.getMessageMap().putError(errorPathPrefix, e.getErrorKey(), e.getErrorParameters()); } // add line to list for those lines which were successfully imported if (importedLines != null) { for (Iterator i = importedLines.iterator(); i.hasNext();) { ProcurementCardTargetAccountingLine importedLine = (ProcurementCardTargetAccountingLine) i.next(); importedLine.setFinancialDocumentTransactionLineNumber(transactionDetail.getFinancialDocumentTransactionLineNumber()); super.insertAccountingLine(false, pcardForm, importedLine); } } }
Example #14
Source File: FormComponentsAction.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private List<String> getInvalidFileformats(FormComponentsForm actionForm) { return actionForm.getAllNewFiles() .values() .stream() .map(FormFile::getFileName) .filter(name -> !ImageUtils.isValidImageFileExtension(AgnUtils.getFileExtension(name))) .collect(Collectors.toList()); }
Example #15
Source File: FilmCenterAction.java From Films with Apache License 2.0 | 5 votes |
public ActionForward postMovie(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); Film film = new Film(); MovieForm movieForm = (MovieForm) form; FormFile photo = movieForm.getFilmPhoto(); film.setFfilmName(movieForm.getFFilmName()); film.setFdiretor(movieForm.getFDirector()); film.setFplay(movieForm.getFPlay()); film.setFlanguage(movieForm.getFLanguage()); film.setFlong(Integer.parseInt(movieForm.getFLong())); film.setFdate(movieForm.getFDate()); film.setFtype(movieForm.getFType()); film.setFintro(movieForm.getFIntro()); //get sort Sort sort = (Sort) sortService.findById(Sort.class, Integer.valueOf(movieForm.getSortID())); //get area Area area = (Area) areaService.findById(Area.class, Integer.valueOf(movieForm.getFAid())); film.setArea(area); film.setSort(sort); filmService.save(film); String fphoto = MyTools.uploadFilmPhoto(request, photo, film.getFid()+""); film.setFphoto(fphoto); filmService.save(film); out.print("<script language='javascript'>alert('post success!');window.history.back(-1);</script>"); return null; }
Example #16
Source File: KualiAccountingDocumentActionBase.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * This method determines whether we are uploading source or target lines, and then calls uploadAccountingLines directly on the * document object. This method handles retrieving the actual upload file as an input stream into the document. * * @param isSource * @param form * @throws FileNotFoundException * @throws IOException */ protected void uploadAccountingLines(boolean isSource, ActionForm form) throws FileNotFoundException, IOException { KualiAccountingDocumentFormBase tmpForm = (KualiAccountingDocumentFormBase) form; List importedLines = null; AccountingDocument financialDocument = tmpForm.getFinancialDocument(); AccountingLineParser accountingLineParser = financialDocument.getAccountingLineParser(); // import the lines String errorPathPrefix = null; try { if (isSource) { errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.SOURCE_ACCOUNTING_LINE_ERRORS; FormFile sourceFile = tmpForm.getSourceFile(); checkUploadFile(sourceFile); importedLines = accountingLineParser.importSourceAccountingLines(sourceFile.getFileName(), sourceFile.getInputStream(), financialDocument); } else { errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.TARGET_ACCOUNTING_LINE_ERRORS; FormFile targetFile = tmpForm.getTargetFile(); checkUploadFile(targetFile); importedLines = accountingLineParser.importTargetAccountingLines(targetFile.getFileName(), targetFile.getInputStream(), financialDocument); } } catch (AccountingLineParserException e) { GlobalVariables.getMessageMap().putError(errorPathPrefix, e.getErrorKey(), e.getErrorParameters()); } // add line to list for those lines which were successfully imported if (importedLines != null) { for (Iterator i = importedLines.iterator(); i.hasNext();) { AccountingLine importedLine = (AccountingLine) i.next(); insertAccountingLine(isSource, tmpForm, importedLine); } } }
Example #17
Source File: ComMailingComponentsServiceImpl.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
@Override public UploadStatistics uploadZipArchive(Mailing mailing, FormFile zipFile) throws Exception { UploadStatisticsImpl statistics = new UploadStatisticsImpl(); try (ZipInputStream zipStream = new ZipInputStream(zipFile.getInputStream())) { for (ZipEntry entry = zipStream.getNextEntry(); entry != null; entry = zipStream.getNextEntry()) { final String path = entry.getName(); final String name = FilenameUtils.getName(path); if (!entry.isDirectory() && ImageUtils.isValidImageFileExtension(FilenameUtils.getExtension(name))) { statistics.newFound(); logger.info("uploadZipArchive(): found image file '" + path + "' in ZIP stream"); byte[] content = StreamHelper.streamToByteArray(zipStream); if (ImageUtils.isValidImage(content)) { addComponent(mailing, content, name); statistics.newStored(); } } zipStream.closeEntry(); } } catch (IOException e) { logger.error("uploadZipArchive()", e); throw e; } return statistics; }
Example #18
Source File: AttachmentSample.java From rice with Educational Community License v2.0 | 4 votes |
public void setAttachmentFile(FormFile attachmentFile) { this.attachmentFile = attachmentFile; }
Example #19
Source File: TravelAuthorizationForm.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * @return the encapsulation of an uploaded file of accounting lines to associate with the travel advance */ public FormFile getAdvanceAccountingFile() { return advanceAccountingFile; }
Example #20
Source File: KualiBatchInputFileForm.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * Gets the uploadFile attribute. */ public FormFile getUploadFile() { return uploadFile; }
Example #21
Source File: PurchasingFormBase.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
public void setItemImportFile(FormFile itemImportFile) { this.itemImportFile = itemImportFile; }
Example #22
Source File: KualiAccountingDocumentActionBase.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
protected void checkUploadFile(FormFile file) { if (file == null) { throw new AccountingLineParserException("invalid (null) upload file", KFSKeyConstants.ERROR_UPLOADFILE_NULL); } }
Example #23
Source File: NoteAction.java From rice with Educational Community License v2.0 | 4 votes |
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { NoteForm noteForm = (NoteForm) form; Note noteToSave = null; if (noteForm.getShowEdit().equals("yes")) { noteToSave = noteForm.getNote(); noteToSave.setNoteCreateDate(new Timestamp(noteToSave.getNoteCreateLongDate().longValue())); } else { noteToSave = new Note(); noteToSave.setNoteId(null); noteToSave.setDocumentId(noteForm.getDocId()); noteToSave.setNoteCreateDate(new Timestamp((new Date()).getTime())); noteToSave.setNoteAuthorWorkflowId(getUserSession().getPrincipalId()); noteToSave.setNoteText(noteForm.getAddText()); } CustomNoteAttribute customNoteAttribute = null; DocumentRouteHeaderValue routeHeader = getRouteHeaderService().getRouteHeader(noteToSave.getDocumentId()); boolean canEditNote = false; boolean canAddNotes = false; if (routeHeader != null) { customNoteAttribute = routeHeader.getCustomNoteAttribute(); if (customNoteAttribute != null) { customNoteAttribute.setUserSession(GlobalVariables.getUserSession()); canAddNotes = customNoteAttribute.isAuthorizedToAddNotes(); canEditNote = customNoteAttribute.isAuthorizedToEditNote(noteToSave); } } if ((noteForm.getShowEdit().equals("yes") && canEditNote) || (!noteForm.getShowEdit().equals("yes") && canAddNotes)) { FormFile uploadedFile = (FormFile)noteForm.getFile(); if (uploadedFile != null && StringUtils.isNotBlank(uploadedFile.getFileName())) { Attachment attachment = new Attachment(); attachment.setAttachedObject(uploadedFile.getInputStream()); attachment.setFileName(uploadedFile.getFileName()); attachment.setMimeType(uploadedFile.getContentType()); attachment.setNote(noteToSave); noteToSave.getAttachments().add(attachment); } else { if(noteToSave.getNoteId() != null) { //note is not new and we need to ensure the attachments are preserved noteToSave.setAttachments(getNoteService().getNoteByNoteId(noteToSave.getNoteId()).getAttachments()); } } getNoteService().saveNote(noteToSave); } if (noteForm.getShowEdit().equals("yes")) { noteForm.setNote(new Note()); } else { noteForm.setAddText(null); } noteForm.setShowEdit("no"); noteForm.setNoteIdNumber(null); retrieveNoteList(request, noteForm); flushDocumentHeaderCache(); return start(mapping, form, request, response); }
Example #24
Source File: MovieForm.java From Films with Apache License 2.0 | 4 votes |
public FormFile getFilmPhoto() { return filmPhoto; }
Example #25
Source File: AccountFaceFileForm.java From jivejdon with Apache License 2.0 | 4 votes |
public FormFile getTheFile() { return theFile; }
Example #26
Source File: UpLoadFileForm.java From jivejdon with Apache License 2.0 | 4 votes |
public void setTheFile(FormFile theFile) { this.theFile = theFile; }
Example #27
Source File: KualiAccountingDocumentFormBase.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * @param sourceFile The sourceFile to set. */ public void setSourceFile(FormFile sourceFile) { this.sourceFile = sourceFile; }
Example #28
Source File: KualiDocumentFormBase.java From rice with Educational Community License v2.0 | 4 votes |
/** * @param attachmentFile The attachmentFile to set. */ public void setAttachmentFile(FormFile attachmentFile) { this.attachmentFile = attachmentFile; }
Example #29
Source File: KualiBatchInputFileForm.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * Sets the uploadFile attribute value. */ public void setUploadFile(FormFile uploadFile) { this.uploadFile = uploadFile; }
Example #30
Source File: ImportBaseFileForm.java From openemm with GNU Affero General Public License v3.0 | 4 votes |
public FormFile getCsvFile() { return csvFile; }