From 40e7925ca10f60357ec6161685499e2f12de99fe Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 23 Oct 2022 08:00:31 +0200 Subject: refactor: Consolidate Qute extensions in a separate package. Change-Id: I03526ef4f5d99db202cbbf1045e52464e2d83a9a --- .../eu/mulk/mulkcms2/benki/posts/PostResource.java | 47 ------------------ .../eu/mulk/mulkcms2/benki/wiki/WikiResource.java | 23 --------- .../common/template/TemporalExtensions.java | 58 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 70 deletions(-) create mode 100644 src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java index 07a9f2f..d6fe538 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java @@ -78,17 +78,6 @@ import org.jsoup.Jsoup; public abstract class PostResource { - private static final DateTimeFormatter htmlDateTimeFormatter = - DateTimeFormatter.ISO_OFFSET_DATE_TIME; - - private static final DateTimeFormatter humanDateTimeFormatter = - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT); - - private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE; - - private static final DateTimeFormatter humanDateFormatter = - DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG); - private static final String hashcashDigestAlgorithm = "SHA-256"; private static final int pageKeyBytes = 32; @@ -496,42 +485,6 @@ public abstract class PostResource { return wireFeedOutput.outputString(feed); } - @TemplateExtension - @CheckForNull - static String humanDateTime(@CheckForNull TemporalAccessor x) { - if (x == null) { - return null; - } - return humanDateTimeFormatter.format(x); - } - - @TemplateExtension - @CheckForNull - static String htmlDateTime(@CheckForNull TemporalAccessor x) { - if (x == null) { - return null; - } - return htmlDateTimeFormatter.format(x); - } - - @TemplateExtension - @CheckForNull - static String humanDate(@CheckForNull TemporalAccessor x) { - if (x == null) { - return null; - } - return humanDateFormatter.format(x); - } - - @TemplateExtension - @CheckForNull - static String htmlDate(@CheckForNull TemporalAccessor x) { - if (x == null) { - return null; - } - return htmlDateFormatter.format(x); - } - private boolean showBookmarkForm() { switch (postFilter) { case ALL: diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java index edf9c72..4100dc2 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java @@ -37,11 +37,6 @@ import org.jsoup.safety.Safelist; @Path("/wiki") public class WikiResource { - private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; - - private static final DateTimeFormatter humanDateFormatter = - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT); - private static final JsonProvider jsonProvider = JsonProvider.provider(); @CheckedTemplate(basePath = "benki/wiki") @@ -158,22 +153,4 @@ public class WikiResource { return Templates.wikiPageRevisionList(page, pageName); } - - @TemplateExtension - @CheckForNull - static String humanDateTime(@CheckForNull TemporalAccessor x) { - if (x == null) { - return null; - } - return humanDateFormatter.format(x); - } - - @TemplateExtension - @CheckForNull - static String htmlDateTime(@CheckForNull TemporalAccessor x) { - if (x == null) { - return null; - } - return htmlDateFormatter.format(x); - } } diff --git a/src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java b/src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java new file mode 100644 index 0000000..35d6d32 --- /dev/null +++ b/src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java @@ -0,0 +1,58 @@ +package eu.mulk.mulkcms2.common.template; + +import io.quarkus.qute.TemplateExtension; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.time.temporal.TemporalAccessor; +import javax.annotation.CheckForNull; + +public class TemporalExtensions { + + private static final DateTimeFormatter htmlDateTimeFormatter = + DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + private static final DateTimeFormatter humanDateTimeFormatter = + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT); + + private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE; + + private static final DateTimeFormatter humanDateFormatter = + DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG); + + @TemplateExtension + @CheckForNull + static String humanDateTime(@CheckForNull TemporalAccessor x) { + if (x == null) { + return null; + } + return humanDateTimeFormatter.format(x); + } + + @TemplateExtension + @CheckForNull + static String htmlDateTime(@CheckForNull TemporalAccessor x) { + if (x == null) { + return null; + } + return htmlDateTimeFormatter.format(x); + } + + @TemplateExtension + @CheckForNull + static String humanDate(@CheckForNull TemporalAccessor x) { + if (x == null) { + return null; + } + return humanDateFormatter.format(x); + } + + @TemplateExtension + @CheckForNull + static String htmlDate(@CheckForNull TemporalAccessor x) { + if (x == null) { + return null; + } + return htmlDateFormatter.format(x); + } + +} -- cgit v1.2.3