diff --git a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java index 285ac5e19..20523d9f5 100644 --- a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java +++ b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java @@ -404,6 +404,31 @@ public String buildImageURL() { return safeBuildURL(IMAGE_FALLBACK_URI); } + /** + * Builds the URL for {@linkplain sirius.web.templates.pdf.TagliatellePDFContentHandler embedding the blob into a + * PDF}. This is done via a special {@link sirius.biz.web.BlobPdfReplaceHandler blob://} URI. + *
+ * If the image is not available, a {@linkplain #fallbackUri fallback} URI using the + * {@link sirius.web.templates.pdf.handlers.ResourcePdfReplaceHandler resource://} scheme is returned. + * + * @return a blob:// URI, or a resource:// URI pointing to a fallback image in case of errors + */ + public String buildUrlForEmbeddingIntoPdf() { + if (space == null || Strings.isEmpty(blobKey)) { + return "resource:/" + Optional.ofNullable(fallbackUri) + .filter(Strings::isFilled) + .map(string -> string.startsWith("assets/") ? '/' + string : string) + .filter(string -> string.startsWith("/assets/")) + .orElse(IMAGE_FALLBACK_URI); + } + + StringBuilder builder = new StringBuilder("blob://").append(space.getName()).append('/').append(blobKey); + if (Strings.isFilled(variant)) { + builder.append('/').append(variant); + } + return builder.toString(); + } + /** * Determines if a conversion for the given variant is expected. *