From 0a9499422771cde534f54c2bdd9509a048e64e3b Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Fri, 9 Dec 2022 11:10:14 +0100 Subject: [PATCH] with building anchor lazily, it's not longer required to set anchor url explicitly in AbstractInternalLinkInheritUrlParamLinkPostProcessor mark Link#setAnchor as deprecated --- src/main/java/io/wcm/handler/link/Link.java | 2 ++ ...ternalLinkInheritUrlParamLinkPostProcessor.java | 3 --- src/test/java/io/wcm/handler/link/LinkTest.java | 1 + ...alLinkInheritUrlParamLinkPostProcessorTest.java | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/wcm/handler/link/Link.java b/src/main/java/io/wcm/handler/link/Link.java index 9a67b56..0bee05e 100644 --- a/src/main/java/io/wcm/handler/link/Link.java +++ b/src/main/java/io/wcm/handler/link/Link.java @@ -141,7 +141,9 @@ public Map getAnchorAttributes() { /** * @param anchor Anchor element + * @deprecated Use {@link #setAnchorBuilder(Function)} to build anchor on-demand */ + @Deprecated public void setAnchor(Anchor anchor) { this.anchor = anchor; } diff --git a/src/main/java/io/wcm/handler/link/processor/AbstractInternalLinkInheritUrlParamLinkPostProcessor.java b/src/main/java/io/wcm/handler/link/processor/AbstractInternalLinkInheritUrlParamLinkPostProcessor.java index b92930c..28d2cff 100644 --- a/src/main/java/io/wcm/handler/link/processor/AbstractInternalLinkInheritUrlParamLinkPostProcessor.java +++ b/src/main/java/io/wcm/handler/link/processor/AbstractInternalLinkInheritUrlParamLinkPostProcessor.java @@ -75,9 +75,6 @@ protected AbstractInternalLinkInheritUrlParamLinkPostProcessor(Set inher .fragment(uri.getFragment()) .build(); link.setUrl(url); - if (link.getAnchor() != null) { - link.getAnchor().setAttribute("href", url); - } } catch (URISyntaxException ex) { log.warn("Skipping post-processing or URL: {}", url, ex); diff --git a/src/test/java/io/wcm/handler/link/LinkTest.java b/src/test/java/io/wcm/handler/link/LinkTest.java index 7797e83..21d2938 100644 --- a/src/test/java/io/wcm/handler/link/LinkTest.java +++ b/src/test/java/io/wcm/handler/link/LinkTest.java @@ -67,6 +67,7 @@ void testLinkReferenceInvalid() { } @Test + @SuppressWarnings("deprecation") void testAnchor() { assertNull(underTest.getAnchorAttributes()); assertNull(underTest.getMarkup()); diff --git a/src/test/java/io/wcm/handler/link/processor/InternalLinkInheritUrlParamLinkPostProcessorTest.java b/src/test/java/io/wcm/handler/link/processor/InternalLinkInheritUrlParamLinkPostProcessorTest.java index c8fd111..d52d356 100644 --- a/src/test/java/io/wcm/handler/link/processor/InternalLinkInheritUrlParamLinkPostProcessorTest.java +++ b/src/test/java/io/wcm/handler/link/processor/InternalLinkInheritUrlParamLinkPostProcessorTest.java @@ -60,7 +60,7 @@ void testInternalLinkWithDefaultParameterList() { Link link = new Link(new InternalLinkType(), null); link.setUrl("/sample.html"); - link.setAnchor(new Anchor().setHRef("/sample.html")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link); @@ -84,7 +84,7 @@ void testInternalLinkFragment() { Link link = new Link(new InternalLinkType(), null); link.setUrl("/sample.html#fragment1"); - link.setAnchor(new Anchor().setHRef("/sample.html#fragment1")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link); @@ -108,7 +108,7 @@ void testInternalLinkFullUrl() { Link link = new Link(new InternalLinkType(), null); link.setUrl("https://host1/sample.html#fragment1"); - link.setAnchor(new Anchor().setHRef("/sample.html#fragment1")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link); @@ -132,7 +132,7 @@ void testInternalLinkFullUrlWithPort() { Link link = new Link(new InternalLinkType(), null); link.setUrl("https://host1:8080/sample.html#fragment1"); - link.setAnchor(new Anchor().setHRef("/sample.html#fragment1")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link); @@ -156,7 +156,7 @@ void testInternalLinkWithCustomParameterList() { Link link = new Link(new InternalLinkType(), null); link.setUrl("/sample.html"); - link.setAnchor(new Anchor().setHRef("/sample.html")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link); @@ -180,7 +180,7 @@ void testExternalLinkWithDefaultParameterList() { Link link = new Link(new ExternalLinkType(), null); link.setUrl("/sample.html"); - link.setAnchor(new Anchor().setHRef("/sample.html")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link); @@ -199,7 +199,7 @@ void testInternalCrossContextLinkWithDefaultParameterList() { Link link = new Link(new InternalCrossContextLinkType(), null); link.setUrl("/sample.html"); - link.setAnchor(new Anchor().setHRef("/sample.html")); + link.setAnchorBuilder(l -> new Anchor().setHRef(l.getUrl())); // test without url parameters postProcessor.process(link);