From 3b58c81968ae374822e6cf52dea9f6d998ce359d Mon Sep 17 00:00:00 2001 From: Thorsten Marx Date: Mon, 16 Sep 2024 14:25:33 +0200 Subject: [PATCH] remove legacy substitutor in favor of shortcode of system module --- cms-content/pom.xml | 4 ---- .../cms/content/DefaultContentRenderer.java | 1 - .../cms/content/pipeline/ContentPipeline.java | 19 ----------------- .../hosts/features/content/search/index.md | 2 -- cms-server/log4j2.xml | 4 ++-- .../libs/example-module-6.0.0-SNAPSHOT.jar | Bin 16705 -> 16704 bytes cms-server/pom.xml | 6 ++++++ .../filter/InitRequestContextFilter.java | 20 ++++++++++++------ .../filter/PooledRequestContextFilter.java | 11 +++++----- .../server/handler/cache/CacheHandler.java | 1 - .../handler/content/JettyContentHandler.java | 4 +++- cms-server/themes/test/templates/search.html | 1 + 12 files changed, 30 insertions(+), 43 deletions(-) diff --git a/cms-content/pom.xml b/cms-content/pom.xml index c8dbd1bc..87ba1cfb 100644 --- a/cms-content/pom.xml +++ b/cms-content/pom.xml @@ -27,10 +27,6 @@ lombok provided - - org.apache.commons - commons-text - com.github.slugify slugify diff --git a/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java b/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java index 1495c4f9..94be6b60 100644 --- a/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java +++ b/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java @@ -70,7 +70,6 @@ import java.util.function.Supplier; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.text.StringSubstitutor; /** * diff --git a/cms-content/src/main/java/com/condation/cms/content/pipeline/ContentPipeline.java b/cms-content/src/main/java/com/condation/cms/content/pipeline/ContentPipeline.java index 80c74bf5..494106bd 100644 --- a/cms-content/src/main/java/com/condation/cms/content/pipeline/ContentPipeline.java +++ b/cms-content/src/main/java/com/condation/cms/content/pipeline/ContentPipeline.java @@ -23,18 +23,14 @@ */ import com.condation.cms.api.feature.Feature; -import com.condation.cms.api.feature.features.AuthFeature; import com.condation.cms.api.hooks.FilterContext; import com.condation.cms.api.hooks.HookSystem; import com.condation.cms.api.hooks.Hooks; import com.condation.cms.api.request.RequestContext; import com.condation.cms.content.RenderContext; -import java.util.HashMap; -import java.util.Map; import java.util.function.Function; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; -import org.apache.commons.text.StringSubstitutor; /** * @@ -47,7 +43,6 @@ public class ContentPipeline { private final RequestContext requestContext; void init () { - hookSystem.registerFilter(Hooks.CONTENT_FILTER.hook(), this::substitute, 10); hookSystem.registerFilter(Hooks.CONTENT_FILTER.hook(), this::markdown, 20); hookSystem.registerFilter(Hooks.CONTENT_FILTER.hook(), this::shortCodes, 30); } @@ -56,20 +51,6 @@ public String process (String rawContent) { return hookSystem.filter(Hooks.CONTENT_FILTER.hook(), rawContent).value(); } - private String substitute (FilterContext context) { - Map map = new HashMap<>(); - - map.put("USERNAME", getFeatureValueOrDefault( - requestContext, - AuthFeature.class, - (feature) -> feature.username(), - "") - ); - - // replace variables - return StringSubstitutor.replace(context.value(), map); - } - private String markdown (FilterContext context) { return requestContext.get(RenderContext.class).markdownRenderer().render(context.value()); } diff --git a/cms-server/hosts/features/content/search/index.md b/cms-server/hosts/features/content/search/index.md index 369fa7cf..dde8342a 100644 --- a/cms-server/hosts/features/content/search/index.md +++ b/cms-server/hosts/features/content/search/index.md @@ -8,6 +8,4 @@ menu: ## Search -Hallo ${USERNAME} - Hello [[username /]] \ No newline at end of file diff --git a/cms-server/log4j2.xml b/cms-server/log4j2.xml index dc38e756..d99de29b 100644 --- a/cms-server/log4j2.xml +++ b/cms-server/log4j2.xml @@ -47,10 +47,10 @@ - + - + diff --git a/cms-server/modules/example-module/libs/example-module-6.0.0-SNAPSHOT.jar b/cms-server/modules/example-module/libs/example-module-6.0.0-SNAPSHOT.jar index a9400540e03a9b936fcbccadadc886672a55f146..ff1130c66f1a69fb7508ca9b489de9f79bce3e25 100644 GIT binary patch delta 1446 z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Gv)9(t6}P}u}M{e@A(io(|Xc;S408Vi*1CcRMl$@M4>&9(oj z1z{7!afq#FBC;flL#)=HVuFu1lzN>E1!0v>5(%l;QUOjxZWO{z^|Bd%hEcxY(>47= Vjc{-bqFN!WVljUxalKe3{{f(-VoCr2 diff --git a/cms-server/pom.xml b/cms-server/pom.xml index 64a4ecb7..524cf9b5 100644 --- a/cms-server/pom.xml +++ b/cms-server/pom.xml @@ -115,6 +115,12 @@ stormpot + + org.apache.commons + commons-text + test + + diff --git a/cms-server/src/main/java/com/condation/cms/server/filter/InitRequestContextFilter.java b/cms-server/src/main/java/com/condation/cms/server/filter/InitRequestContextFilter.java index f3dd5f6f..e46e572c 100644 --- a/cms-server/src/main/java/com/condation/cms/server/filter/InitRequestContextFilter.java +++ b/cms-server/src/main/java/com/condation/cms/server/filter/InitRequestContextFilter.java @@ -50,16 +50,22 @@ public InitRequestContextFilter(final RequestContextFactory requestContextFactor @Override public boolean handle(final Request httpRequest, final Response rspns, final Callback clbck) throws Exception { - var requestContext = (RequestContext)httpRequest.getAttribute(REQUEST_CONTEXT); + try { + var requestContext = (RequestContext) httpRequest.getAttribute(REQUEST_CONTEXT); - if (requestContext.has(AlreadyInitialized.class)) { - return false; + if (requestContext.has(AlreadyInitialized.class)) { + return false; + } + requestContextFactory.initContext(requestContext, httpRequest); + requestContext.add(AlreadyInitialized.class, new AlreadyInitialized()); + } catch (Exception e) { + e.printStackTrace(); } - requestContextFactory.initContext(requestContext, httpRequest); - requestContext.add(AlreadyInitialized.class, new AlreadyInitialized()); return false; } - - private record AlreadyInitialized() implements Feature{}; + + private record AlreadyInitialized() implements Feature { + } +; } diff --git a/cms-server/src/main/java/com/condation/cms/server/filter/PooledRequestContextFilter.java b/cms-server/src/main/java/com/condation/cms/server/filter/PooledRequestContextFilter.java index 6a55d863..b6df0dc9 100644 --- a/cms-server/src/main/java/com/condation/cms/server/filter/PooledRequestContextFilter.java +++ b/cms-server/src/main/java/com/condation/cms/server/filter/PooledRequestContextFilter.java @@ -21,8 +21,6 @@ * . * #L% */ - - import com.condation.cms.api.PerformanceProperties; import com.condation.cms.api.ServerContext; import com.condation.cms.api.annotations.Experimental; @@ -64,7 +62,7 @@ public class PooledRequestContextFilter extends Handler.Wrapper { Pool requestContextPool; private final PerformanceProperties properties; - + public PooledRequestContextFilter(final Handler handler, final RequestContextFactory requestContextFactory, final PerformanceProperties properties) { super(handler); @@ -75,7 +73,7 @@ public PooledRequestContextFilter(final Handler handler, final RequestContextFac .setSize(properties.pool_size()) .build(); } - + @Override public boolean handle(Request httpRequest, Response rspns, Callback clbck) throws Exception { var requestContextPoolable = requestContextPool.claim(new Timeout(Duration.ofSeconds(1))); @@ -95,7 +93,9 @@ public boolean handle(Request httpRequest, Response rspns, Callback clbck) throw httpRequest.setAttribute(REQUEST_CONTEXT, requestContext); return super.handle(httpRequest, rspns, clbck); - + } catch (Exception e) { + e.printStackTrace(); + return false; } finally { requestContext.features.remove(RequestFeature.class); requestContext.features.remove(IsPreviewFeature.class); @@ -104,7 +104,6 @@ public boolean handle(Request httpRequest, Response rspns, Callback clbck) throw } } - @RequiredArgsConstructor private static class RequestContextAllocator implements Allocator { diff --git a/cms-server/src/main/java/com/condation/cms/server/handler/cache/CacheHandler.java b/cms-server/src/main/java/com/condation/cms/server/handler/cache/CacheHandler.java index 32afa002..4950124e 100644 --- a/cms-server/src/main/java/com/condation/cms/server/handler/cache/CacheHandler.java +++ b/cms-server/src/main/java/com/condation/cms/server/handler/cache/CacheHandler.java @@ -91,7 +91,6 @@ public boolean handle(Request request, Response response, Callback callback) thr name, value); }); - Content.Sink.write(response, true, cached.body, callback); return true; diff --git a/cms-server/src/main/java/com/condation/cms/server/handler/content/JettyContentHandler.java b/cms-server/src/main/java/com/condation/cms/server/handler/content/JettyContentHandler.java index 7ca92a76..a1a37aa2 100644 --- a/cms-server/src/main/java/com/condation/cms/server/handler/content/JettyContentHandler.java +++ b/cms-server/src/main/java/com/condation/cms/server/handler/content/JettyContentHandler.java @@ -31,6 +31,7 @@ import com.condation.cms.request.RequestContextFactory; import com.condation.cms.server.filter.CreateRequestContextFilter; import com.google.inject.Inject; +import java.nio.charset.StandardCharsets; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -91,7 +92,8 @@ public boolean handle(Request request, Response response, Callback callback) thr } } catch (Exception e) { - log.error("", e); + e.printStackTrace(); + log.error("error handling content", e); response.setStatus(500); response.getHeaders().add(HttpHeader.CONTENT_TYPE, "text/html; charset=utf-8"); callback.succeeded(); diff --git a/cms-server/themes/test/templates/search.html b/cms-server/themes/test/templates/search.html index 8cc0b51e..070d226d 100644 --- a/cms-server/themes/test/templates/search.html +++ b/cms-server/themes/test/templates/search.html @@ -23,6 +23,7 @@
Hallo + Hello [(${shortCodes.call('username')})]