public static Attachment createAttachment(TextConfiguration textConfiguration, String id, String fileName, String contentType, long size) { Attachment attachment = new Attachment(id); attachment.setFilename(fileName); attachment.setContentType(contentType); attachment.setSize(size); textConfiguration.getAttachments().add(attachment); return attachment; }
public TextConfiguration createTextConfiguration() { return new TextConfiguration(); } }
public static Attachment findAttachmentById( TextConfiguration textConfiguration, String code) { for (Attachment current : textConfiguration.getAttachments()) { if (current.getId().equals(code)) { return current; } } return null; }
@Button(list = "manage-attachments", key = "ok", order = 1, type = Button.TYPE_PRIMARY) @RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT }) public Resolution saveAttachments() { if(downloadable == null) { downloadable = new String[0]; } if(textConfiguration == null) { textConfiguration = new TextConfiguration(); } for(Attachment attachment : textConfiguration.getAttachments()) { boolean contained = ArrayUtils.contains(downloadable, attachment.getId()); attachment.setDownloadable(contained); } saveConfiguration(textConfiguration); return cancel(); }
String attachmentId = attachment.getId(); final File file = RandomUtil.getCodeFile( pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachmentId); new StreamingResolution(attachment.getContentType(), is) .setLength(attachment.getSize()) .setFilename(attachment.getFilename()) .setAttachment(isAttachment) .setLastModified(file.lastModified());
public List<Attachment> getDownloadableAttachments() { List<Attachment> downloadableAttachments = new ArrayList<Attachment>(); for(Attachment attachment : getTextConfiguration().getAttachments()) { if(attachment.isDownloadable()) { downloadableAttachments.add(attachment); } } return downloadableAttachments; } }
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"); }
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; } } }
pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachment.getId()); if(!FileUtils.deleteQuietly(file)) { logger.warn("File wasn't deleted: {}", file.getAbsolutePath());
public static Attachment createAttachment(TextConfiguration textConfiguration, String id, String fileName, String contentType, long size) { Attachment attachment = new Attachment(id); attachment.setFilename(fileName); attachment.setContentType(contentType); attachment.setSize(size); textConfiguration.getAttachments().add(attachment); return attachment; }
public static Attachment findAttachmentById( TextConfiguration textConfiguration, String code) { for (Attachment current : textConfiguration.getAttachments()) { if (current.getId().equals(code)) { return current; } } return null; }
public TextConfiguration createTextConfiguration() { return new TextConfiguration(); } }
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; } } }