private static String buildImageFileHref(Attachment attachment) { return "/attachment/" + attachment.getSlug() + "." + attachment.getExtension(); } }
public FileRepresentation(Attachment attachment, String href) { this.extension = attachment.getExtension(); this.href = href; }
public UUID apply(Attachment input) { return input.getId(); } }).toList();
public InputStream getImage(Attachment attachment, Rectangle rectangle) throws IOException { Path imageDirectory = getImageCacheDirectoryPath(attachment); String boxDirectory = getBoxDirectoryName(rectangle); String dimensionFileName = attachment.getSlug() + "." + attachment.getExtension(); File dimensionFile = imageDirectory.resolve(boxDirectory).resolve(dimensionFileName).toFile(); if (!dimensionFile.isFile()) { LoadedAttachment loadedAttachment = this.attachmentStore.get().findAndLoadById(attachment.getId()); Image image = loadedAttachment.getData().getObject(loadImage, Image.class); RenderedImage cropped = imageProcessor.cropImage(image, rectangle); dimensionFile.mkdirs(); ImageIO.write(cropped, attachment.getExtension(), dimensionFile); } return new java.io.FileInputStream(dimensionFile); }
/** * Constructor that allows to override the attachment URI and its file representation. * * Particularly useful for extending classes, such as {@link ImageRepresentation}. * * @param attachment the attachment to represent. * @param uri the URI of the resource represented by the attachment representation * @param file the file representation of the attachment representation */ public AttachmentRepresentation(Attachment attachment, String uri, FileRepresentation file) { super(uri, attachment.getSlug(), attachment.getTitle()); this.file = file; this.description = attachment.getDescription(); this.localizedVersions = attachment.getLocalizedVersions(); }
@Override public void detach(Attachment attachment) throws EntityDoesNotExistException { Attachment found = findAndLoadById(attachment.getId()); found.setParentId(null); } }
public Response downloadFile(String slug, String extension, ServletContext servletContext) { String fileName = slug + "." + extension; LoadedAttachment file = this.attachmentStore.get().findAndLoadBySlugAndExtension(slug, extension); if (file == null) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok(file.getData().getStream(), servletContext.getMimeType(fileName)) .header("Content-disposition", "inline; filename*=utf-8''" + fileName) .build(); }
private static String buildAttachmentApiHref(Attachment attachment) { return "/api/1.0/attachment/" + attachment.getSlug(); }
public static boolean isImage(Attachment attachment) { return isImage(attachment.getFilename()); }
public InputStream getImage(Attachment attachment, Dimension dimension) throws IOException { Path imageDirectory = getImageCacheDirectoryPath(attachment); String dimensionFileName = getDimensionFileName(attachment, dimension); File dimensionFile = imageDirectory.resolve(dimensionFileName).toFile(); if (!dimensionFile.isFile()) { LoadedAttachment loadedAttachment = this.attachmentStore.get().findAndLoadById(attachment.getId()); Image image = loadedAttachment.getData().getObject(loadImage, Image.class); RenderedImage scaled; scaled = imageProcessor.scaleImage(image, dimension); ImageIO.write(scaled, attachment.getExtension(), dimensionFile); } return new java.io.FileInputStream(dimensionFile); }
public AttachmentRepresentation(Attachment attachment) { super(buildAttachmentApiHref(attachment), attachment.getSlug(), attachment.getTitle()); this.file = buildFileRepresentation(attachment); this.description = attachment.getDescription(); this.localizedVersions = attachment.getLocalizedVersions(); }
public String getFilename() { return getSlug() + "." + getExtension(); }
@Override public List<Thumbnail> findAll(Attachment attachment) { return this.dao.findThumbnails(attachment.getId()); }
public static boolean isImage(Attachment attachment) { return IMAGE_EXTENSIONS.contains(attachment.getExtension().toLowerCase()); } }
private static String buildImageApiHref(Image image) { return "/api/images/" + image.getAttachment().getSlug(); }
public boolean apply(Image input) { return input.getAttachment().getFilename().equals(fileName); } });
private static String buildImageFileHref(Image image) { return "/images/" + image.getAttachment().getSlug() + "." + image.getAttachment().getExtension(); }
@Override public void detach(Attachment attachment) throws EntityDoesNotExistException { Integer updated = this.dao.detach(attachment.getId()); if (updated < 1) { throw new EntityDoesNotExistException(); } }
private String getDimensionFileName(Attachment attachment, Dimension dimension) { return String.valueOf(Math.round(dimension.getWidth())) + "x" + String.valueOf(Math.round(dimension.getHeight())) + "." + attachment.getExtension(); }
@Override public void delete(@Valid Attachment entity) throws EntityDoesNotExistException { Integer updatedRows = 0; this.dao.begin(); updatedRows += this.dao.deleteEntityEntityById(ATTACHMENT_TABLE_NAME, entity.getId()); updatedRows += this.dao.deleteEntityAndChildrenById(entity.getId()); this.dao.commit(); if (updatedRows <= 0) { throw new EntityDoesNotExistException("No rows was updated when trying to delete attachment"); } }