/** * Get a generic attributes response from a file item * * @param fileItem The file item * @param entry The entry * @param bCreatePhysicalFile True to create the physical file associated with the file of the * response, false otherwise. Note that the physical file will never be saved in the database * by this method, like any other created object. * @return The created response */ private Response getResponseFromFile( FileItem fileItem, Entry entry, boolean bCreatePhysicalFile) { if (fileItem instanceof GenAttFileItem) { GenAttFileItem genAttFileItem = (GenAttFileItem) fileItem; if (genAttFileItem.getIdResponse() > 0) { Response response = ResponseHome.findByPrimaryKey(genAttFileItem.getIdResponse()); response.setEntry(entry); response.setFile(FileHome.findByPrimaryKey(response.getFile().getIdFile())); if (bCreatePhysicalFile) { response.getFile().getPhysicalFile().setValue(fileItem.get()); } return response; } } Response response = new Response(); response.setEntry(entry); File file = new File(); file.setTitle(fileItem.getName()); file.setSize( (fileItem.getSize() < Integer.MAX_VALUE) ? (int) fileItem.getSize() : Integer.MAX_VALUE); if (bCreatePhysicalFile) { file.setMimeType(FileSystemUtil.getMIMEType(file.getTitle())); PhysicalFile physicalFile = new PhysicalFile(); physicalFile.setValue(fileItem.get()); file.setPhysicalFile(physicalFile); } response.setFile(file); return response; }
/** {@inheritDoc} */ @Override public GenericAttributeError getResponseData( Entry entry, HttpServletRequest request, List<Response> listResponse, Locale locale) { List<FileItem> listFilesSource = null; if (request instanceof MultipartHttpServletRequest) { List<FileItem> asynchronousFileItem = getFileSources(entry, request); if (asynchronousFileItem != null) { listFilesSource = asynchronousFileItem; } GenericAttributeError genAttError = null; if (getAsynchronousUploadHandler() .hasRemoveFlag( request, IEntryTypeService.PREFIX_ATTRIBUTE + Integer.toString(entry.getIdEntry())) || getAsynchronousUploadHandler() .hasAddFileFlag( request, IEntryTypeService.PREFIX_ATTRIBUTE + Integer.toString(entry.getIdEntry()))) { if ((listFilesSource != null) && !listFilesSource.isEmpty()) { for (FileItem fileItem : listFilesSource) { listResponse.add(getResponseFromFile(fileItem, entry, false)); } } genAttError = new GenericAttributeError(); genAttError.setErrorMessage(StringUtils.EMPTY); genAttError.setMandatoryError(false); genAttError.setIsDisplayableError(false); return genAttError; } if ((listFilesSource != null) && !listFilesSource.isEmpty()) { genAttError = checkResponseData(entry, listFilesSource, locale, request); for (FileItem fileItem : listFilesSource) { listResponse.add(getResponseFromFile(fileItem, entry, genAttError == null)); } if (genAttError != null) { return genAttError; } for (FileItem fileItem : listFilesSource) { if (checkForImages()) { genAttError = doCheckforImages(fileItem, entry, request.getLocale()); } } return genAttError; } if (entry.isMandatory()) { genAttError = new MandatoryError(entry, locale); Response response = new Response(); response.setEntry(entry); listResponse.add(response); } return genAttError; } return entry.isMandatory() ? new MandatoryError(entry, locale) : null; }