protected void internalValueChanged(Object newValue) { fileName = newValue == null ? null : ((FileDescriptor) newValue).getName(); if (!internalValueChangedOnUpload) { fileId = null; tempFileId = null; } }
/** * Creates HTML link for downloading a file. * * @param fd file descriptor * @param newWindow adds target="_blank" * @param attachment sets Content-Disposition: attachment * @return HTML string */ public static String makeLink(FileDescriptor fd, boolean newWindow, boolean attachment) { StringBuilder sb = new StringBuilder(); sb.append("<a href=\""); sb.append(makeUrl(fd, attachment)); sb.append("\""); if (newWindow) sb.append(" target=\"_blank\""); sb.append(">"); sb.append(fd.getName()); sb.append("</a>"); return sb.toString(); }
@Override protected void doSetValue(FileDescriptor fileDescriptor) { this.value = fileDescriptor; setFileNameButtonCaption(fileDescriptor == null ? null : fileDescriptor.getName()); onSetInternalValue(fileDescriptor); }
@Override public void show(FileDescriptor fileDescriptor, ExportFormat format) { show(new FileDataProvider(fileDescriptor), fileDescriptor.getName(), format); }
protected void updateOutputType() { if (outputType.getValue() == null) { String extension = FilenameUtils.getExtension(templateUploadField.getFileDescriptor().getName()).toUpperCase(); ReportOutputType reportOutputType = ReportOutputType.getTypeFromExtension(extension); if (reportOutputType != null) { outputType.setValue(reportOutputType); } } }
protected ResponseEntity<FileInfo> createFileInfoResponseEntity(HttpServletRequest request, FileDescriptor fd) { FileInfo fileInfo = new FileInfo(fd.getId(), fd.getName(), fd.getSize()); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(request.getRequestURL().toString()) .path("/{id}") .buildAndExpand(fd.getId().toString()); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uriComponents.toUri()); return new ResponseEntity<>(fileInfo, httpHeaders, HttpStatus.CREATED); }
response.setHeader("Content-Type", getContentType(fd)); response.setHeader("Content-Disposition", (BooleanUtils.isTrue(attachment) ? "attachment" : "inline") + "; filename=\"" + fd.getName() + "\"");
protected String createAllFieldContent(Entity entity, EntityDescr descr) throws IndexingException { StringBuilder sb = new StringBuilder(); for (String propName : descr.getLocalProperties()) { Object value = entity.getValueEx(propName); // using getValueEx() to support embedded entities String str = valueFormatter.format(value); if (str != null && !StringUtils.isBlank(str)) { if (ftsConfig.getStoreContentInIndex()) { appendString(sb, makeFieldName(propName)); } appendString(sb, str); } } if (entity instanceof FileDescriptor) { appendString(sb, makeFieldName(FTS.FILE_CONT_PROP)); sb.append(FTS.FIELD_SEP).append(((FileDescriptor) entity).getName().replaceAll("\\s+", FTS.FIELD_SEP)); appendFileContent(sb, (FileDescriptor) entity); } if (log.isTraceEnabled()) log.trace("Entity {} all field: {}", entity, sb.toString()); return sb.toString(); }
@Override public InputStream downloadFile(FileDescriptor fileDescriptor) throws FileStorageException { FileDescriptor descriptor; try { // FileDescriptor must be available for the current user and be non deleted descriptor = dataManager.secure().reload(fileDescriptor, View.LOCAL); } catch (EntityAccessException e) { throw new FileStorageException(FileStorageException.Type.FILE_NOT_FOUND, fileDescriptor.getName(), e); } return fileStorage.openStream(descriptor); } }
throw new FileStorageException(FileStorageException.Type.FILE_NOT_FOUND, fileDescr.getName());
@Override protected void createResource() { String name = StringUtils.isNotEmpty(fileName) ? fileName : fileDescriptor.getName(); resource = new StreamResource(() -> { try { return new ByteArrayDataProvider(AppBeans.get(FileStorageService.class).loadFile(fileDescriptor)) .provide(); } catch (FileStorageException e) { throw new RuntimeException(FILE_STORAGE_EXCEPTION_MESSAGE, e); } }, name); StreamResource streamResource = (StreamResource) this.resource; streamResource.setCacheTime(cacheTime); streamResource.setBufferSize(bufferSize); }
String fileName = URLEncodeUtils.encodeUtf8(fd.getName());
String fileName = URLEncodeUtils.encodeUtf8(fd.getName());
sb.append(fileDescriptor.getId()) .append(", ") .append(fileDescriptor.getName()) .append(", ") .append(fileDescriptor.getCreateDate())
public void apply() { FileDescriptor fileDescriptor = uploadField.getValue(); if (fileDescriptor == null) { showNotification(getMessage("fileNotUploaded")); return; } String pathFieldValue = parse(configPathField.getRawValue().trim()); try { Path filePath = configDir.resolve(pathFieldValue); String fileName = fileDescriptor.getName(); File targetFile = new File(filePath.toString(), fileName); if (targetFile.exists()) { confirmOverwriteFile(fileName, targetFile); } else { createNewFile(targetFile); } } catch (InvalidPathException e) { showNotification(formatMessage(getMessage("pathValidMessage"), pathFieldValue)); } }
protected void initComponent() { component.addFileNameClickListener(e -> { FileDescriptor value = getValue(); if (value == null) { return; } switch (mode) { case MANUAL: String name = getFileName(); String fileName = StringUtils.isEmpty(name) ? value.getName() : name; exportDisplay.show(this::getFileContent, fileName); break; case IMMEDIATE: exportDisplay.show(value); break; } }); component.setClearButtonListener(this::clearButtonClicked); component.setRequiredError(null); }
protected void checkIfFileDescriptorExists(FileDescriptor fd) throws FileStorageException { try (Transaction tx = persistence.getTransaction()) { FileDescriptor existingFile = persistence.getEntityManager().find(FileDescriptor.class, fd.getId()); if (existingFile == null || entityStates.isDeleted(existingFile)) { throw new FileStorageException(FileStorageException.Type.FILE_NOT_FOUND, fd.getName()); } tx.commit(); } } }
protected void exportFile(SendingAttachment attachment) { try { FileDescriptor fd; if (emailService.isFileStorageUsed() && attachment.getContentFile() != null && fileLoader.fileExists(attachment.getContentFile())) { fd = attachment.getContentFile(); } else { fd = getFileDescriptor(attachment); } AppConfig.createExportDisplay(this) .show(new FileDataProvider(fd), fd.getName(), ExportFormat.OCTET_STREAM); } catch (FileStorageException e) { throw new RuntimeException("File export failed", e); } } }
@Override public void setStencil(ServiceTaskStencil stencil) { initialValueSet = true; super.setStencil(stencil); if (stencil.getIconFileId() != null && stencil.getIconFile() == null) { LoadContext<FileDescriptor> ctx = new LoadContext<>(FileDescriptor.class).setId(stencil.getIconFileId()); FileDescriptor fd = dataManager.load(ctx); stencil.setIconFile(fd); } if (!Strings.isNullOrEmpty(stencil.getMethodName())) { setInitialMethodNameValue(stencil); } String downloadIconBtnCaption = stencil.getIconFile() != null ? stencil.getIconFile().getName() : getMessage("notUploaded"); downloadIconBtn.setCaption(downloadIconBtnCaption); initialValueSet = false; }
label.setValue(fd.getName()); return label; } else {