From 7ab0ad6fc6ce7cc08db7267e8461f9bc377d5021 Mon Sep 17 00:00:00 2001 From: Jakob Vogel Date: Mon, 5 Aug 2024 20:12:30 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Adds=20method=20for=20formatting=20a=20`blo?= =?UTF-8?q?b://`=20URI=20=F0=9F=AA=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …as is required for embedding images from storage into a PDF. OX-10782 --- .../java/sirius/biz/storage/layer2/URLBuilder.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java index 285ac5e19..7d33fe331 100644 --- a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java +++ b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java @@ -404,6 +404,20 @@ 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. + * + * @return a blob:// URI + */ + public String buildUrlForEmbeddingInPdf() { + 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. * From 7a619f036c253520bbf5f38928b3b3cdd2ea5260 Mon Sep 17 00:00:00 2001 From: Jakob Vogel Date: Mon, 5 Aug 2024 20:53:17 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Adds=20fallback=20mechanism=20=F0=9F=AA=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …in case the blob URL can not be constructed. OX-10782 --- src/main/java/sirius/biz/storage/layer2/URLBuilder.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java index 7d33fe331..81af9d848 100644 --- a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java +++ b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java @@ -407,10 +407,17 @@ public String buildImageURL() { /** * 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 #IMAGE_FALLBACK_URI fallback} URI using the + * {@link sirius.web.templates.pdf.handlers.ResourcePdfReplaceHandler resource://} scheme is returned. * - * @return a blob:// URI + * @return a blob:// URI, or a resource:// URI pointing to a fallback image in case of errors */ public String buildUrlForEmbeddingInPdf() { + if (space == null || Strings.isEmpty(blobKey)) { + return "resource:/" + IMAGE_FALLBACK_URI; + } + StringBuilder builder = new StringBuilder("blob://").append(space.getName()).append('/').append(blobKey); if (Strings.isFilled(variant)) { builder.append('/').append(variant); From 3287f10e1a09cd808347a879b65e2082cd2781f6 Mon Sep 17 00:00:00 2001 From: Jakob Vogel Date: Mon, 5 Aug 2024 20:59:33 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Fixes=20typo=20=F0=9F=8F=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OX-10782 --- src/main/java/sirius/biz/storage/layer2/URLBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java index 81af9d848..7b384ee07 100644 --- a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java +++ b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java @@ -413,7 +413,7 @@ public String buildImageURL() { * * @return a blob:// URI, or a resource:// URI pointing to a fallback image in case of errors */ - public String buildUrlForEmbeddingInPdf() { + public String buildUrlForEmbeddingIntoPdf() { if (space == null || Strings.isEmpty(blobKey)) { return "resource:/" + IMAGE_FALLBACK_URI; } From cf48e2472929aaf62b31dec3072e129d9d69f09c Mon Sep 17 00:00:00 2001 From: Jakob Vogel Date: Mon, 5 Aug 2024 21:29:47 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Prefers=20the=20fallback=20URI=20member=20?= =?UTF-8?q?=F0=9F=A5=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …before falling back to the generic one. OX-10782 --- src/main/java/sirius/biz/storage/layer2/URLBuilder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java index 7b384ee07..20523d9f5 100644 --- a/src/main/java/sirius/biz/storage/layer2/URLBuilder.java +++ b/src/main/java/sirius/biz/storage/layer2/URLBuilder.java @@ -408,14 +408,18 @@ public String buildImageURL() { * 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 #IMAGE_FALLBACK_URI fallback} URI using the + * 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:/" + IMAGE_FALLBACK_URI; + 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);