public static Attachment deleteAttachmentByCode(TextConfiguration textConfiguration, String code) { Attachment attachment = findAttachmentById(textConfiguration, code); if (attachment == null) { return null; } else { textConfiguration.getAttachments().remove(attachment); return attachment; } } }
protected void commonUploadAttachment() throws IOException { logger.debug("Uploading attachment"); viewAttachmentUrl = null; InputStream attachmentStream = upload.getInputStream(); String attachmentId = RandomUtil.createRandomId(); File dataFile = RandomUtil.getCodeFile( pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachmentId); // copy the data FileOutputStream fileOutputStream = new FileOutputStream(dataFile); IOUtils.copyLarge(attachmentStream, fileOutputStream); if(textConfiguration == null) { textConfiguration = new TextConfiguration(); } Attachment attachment = TextLogic.createAttachment( textConfiguration, attachmentId, upload.getFileName(), upload.getContentType(), upload.getSize()); attachment.setDownloadable(uploadDownloadable); viewAttachmentUrl = generateViewAttachmentUrl(attachmentId); saveConfiguration(textConfiguration); logger.info("Attachment uploaded: " + upload.getFileName() + " (" + attachmentId + ")"); IOUtils.closeQuietly(attachmentStream); IOUtils.closeQuietly(fileOutputStream); upload.delete(); logger.debug("Upload resources cleaned"); }
for (String code : selection) { Attachment attachment = TextLogic.deleteAttachmentByCode(textConfiguration, code); if (attachment == null) { logger.warn("Ignoring non-existing attachment with code: {}", code);
public static Attachment deleteAttachmentByCode(TextConfiguration textConfiguration, String code) { Attachment attachment = findAttachmentById(textConfiguration, code); if (attachment == null) { return null; } else { textConfiguration.getAttachments().remove(attachment); return attachment; } } }
TextLogic.findAttachmentById(textConfiguration, id);