Skip to content

Commit

Permalink
with building anchor lazily, it's not longer required to set anchor u…
Browse files Browse the repository at this point in the history
…rl explicitly in AbstractInternalLinkInheritUrlParamLinkPostProcessor

mark Link#setAnchor as deprecated
  • Loading branch information
stefanseifert committed Dec 9, 2022
1 parent f96a0f1 commit 0a94994
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/wcm/handler/link/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public Map<String, String> getAnchorAttributes() {

/**
* @param anchor Anchor element
* @deprecated Use {@link #setAnchorBuilder(Function)} to build anchor on-demand
*/
@Deprecated
public void setAnchor(Anchor anchor) {
this.anchor = anchor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ protected AbstractInternalLinkInheritUrlParamLinkPostProcessor(Set<String> 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);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/io/wcm/handler/link/LinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void testLinkReferenceInvalid() {
}

@Test
@SuppressWarnings("deprecation")
void testAnchor() {
assertNull(underTest.getAnchorAttributes());
assertNull(underTest.getMarkup());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 0a94994

Please sign in to comment.