Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
limitations under the License.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.parent_toplevel</artifactId>
<version>2.7.0</version>
<relativePath/>
<version>2.8.0-SNAPSHOT</version>
<relativePath />
</parent>

<groupId>io.wcm</groupId>
Expand All @@ -41,8 +40,8 @@
<scm>
<connection>scm:git:https://github.com/wcm-io/io.wcm.handler.link.git</connection>
<developerConnection>scm:git:https://github.com/wcm-io/io.wcm.handler.link.git</developerConnection>
<url>https://github.com/wcm-io/io.wcm.handler.link</url>
<tag>HEAD</tag>
<url>https://github.com/wcm-io/io.wcm.handler.link</url>
</scm>

<properties>
Expand Down Expand Up @@ -196,9 +195,8 @@
cq=http://www.day.com/jcr/cq/1.0,\
granite=http://www.adobe.com/jcr/granite/1.0,\
sling=http://sling.apache.org/jcr/sling/1.0

<!-- For build compatibility with Java 11 -->
Import-Package: \
<!-- For build compatibility with Java 11 -->\
javax.annotation;version="[0.0,2)",\
*
</bnd>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wcm/handler/link/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ public void addRedirectPage(@NotNull Page redirectPage) {
* Check if link is valid.
* @return true if link is valid and was resolved successfully
*/
@SuppressWarnings({ "null", "java:S2589" }) // extra null checks for backward compatibility
@SuppressWarnings({
"null", "java:S2589"
}) // extra null checks for backward compatibility
public boolean isValid() {
return getLinkType() != null
&& getUrl() != null
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/io/wcm/handler/link/LinkArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ public boolean isDisableSuffixSelector() {
* @param map Property map. Is merged with properties already set.
* @return this
*/
@SuppressWarnings({ "null", "unused" })
@SuppressWarnings({
"null", "unused"
})
public @NotNull LinkArgs properties(@NotNull Map<String, Object> map) {
if (map == null) {
throw new IllegalArgumentException("Map argument must not be null.");
Expand All @@ -283,7 +285,9 @@ public boolean isDisableSuffixSelector() {
* @param value Property value
* @return this
*/
@SuppressWarnings({ "null", "unused" })
@SuppressWarnings({
"null", "unused"
})
public @NotNull LinkArgs property(@NotNull String key, @Nullable Object value) {
if (key == null) {
throw new IllegalArgumentException("Key argument must not be null.");
Expand Down Expand Up @@ -367,7 +371,9 @@ public String toString() {
* @return the cloned {@link LinkArgs}
*/
@Override
@SuppressWarnings({ "java:S2975", "java:S1182", "checkstyle:SuperCloneCheck" }) // ignore clone warnings
@SuppressWarnings({
"java:S2975", "java:S1182", "checkstyle:SuperCloneCheck"
}) // ignore clone warnings
public LinkArgs clone() { //NOPMD
LinkArgs clone = new LinkArgs();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wcm/handler/link/LinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface LinkBuilder {
* @return Link builder
*/
@NotNull
LinkBuilder suffix (@Nullable String suffix);
LinkBuilder suffix(@Nullable String suffix);

/**
* Set query parameters string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public LinkComponentPropertyResolver(@NotNull Resource resource,
@NotNull ComponentPropertyResolverFactory componentPropertyResolverFactory) {
// resolve media component properties 1. from policies and 2. from component definition
resolver = componentPropertyResolverFactory.get(resource, true)
.contentPolicyResolution(ComponentPropertyResolution.RESOLVE)
.componentPropertiesResolution(ComponentPropertyResolution.RESOLVE_INHERIT);
.contentPolicyResolution(ComponentPropertyResolution.RESOLVE)
.componentPropertiesResolution(ComponentPropertyResolution.RESOLVE_INHERIT);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wcm/handler/link/SyntheticLinkResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public SyntheticLinkResource(@NotNull ResourceResolver resourceResolver,
}

@Override
@SuppressWarnings({ "unchecked", "null" })
@SuppressWarnings({
"unchecked", "null"
})
public <Type> Type adaptTo(Class<Type> type) {
if (type == ValueMap.class) {
return (Type)this.properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class ImageMapLinkResolverImpl implements ImageMapLinkResolver<Link> {
LinkHandler linkHandler = context.adaptTo(LinkHandler.class);
if (linkHandler != null) {
return linkHandler.get(linkUrl)
.windowTarget(linkWindowTarget)
.build();
.windowTarget(linkWindowTarget)
.build();
}
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wcm/handler/link/impl/LinkBuilderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ private static String getWindowTargetFromResource(@NotNull Resource resource, @N
}

@Override
@SuppressWarnings({ "null", "unused" })
@SuppressWarnings({
"null", "unused"
})
public @NotNull LinkBuilder args(@NotNull LinkArgs value) {
if (value == null) {
throw new IllegalArgumentException("LinkArgs is null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class LinkHandlerAdapterFactory implements AdapterFactory {
@Reference
private ComponentPropertyResolverFactory componentPropertyResolverFactory;

@SuppressWarnings({ "unchecked", "null" })
@SuppressWarnings({
"unchecked", "null"
})
@Override
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (type == LinkHandlerConfig.class) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/wcm/handler/link/impl/LinkHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public final class LinkHandlerImpl implements LinkHandler {
"java:S112", // runtime exception
"java:S1192" // redundant string literals
})
@SuppressFBWarnings({ "STYLE" })
@SuppressFBWarnings({
"STYLE"
})
Link processRequest(@NotNull LinkRequest linkRequest) {

// detect link type - first accepting wins
Expand Down Expand Up @@ -181,7 +183,8 @@ Link processRequest(@NotNull LinkRequest linkRequest) {
LinkProcessor processor = AdaptTo.notNull(adaptable, processorClass);
link = processor.process(link);
if (link == null) {
throw new RuntimeException("LinkPostProcessor '" + processor + "' returned null, page '" + (currentPage != null ? currentPage.getPath() : "-") + "'.");
throw new RuntimeException(
"LinkPostProcessor '" + processor + "' returned null, page '" + (currentPage != null ? currentPage.getPath() : "-") + "'.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ protected AbstractInternalLinkInheritUrlParamLinkPostProcessor(Set<String> inher
path = uri.getScheme() + "://" + uri.getHost() + (uri.getPort() == -1 ? "" : (":" + uri.getPort())) + path;
}
url = urlHandler.get(path)
.queryString(uri.getRawQuery(), this.inheritUrlParameterNames)
.fragment(uri.getFragment())
.build();
.queryString(uri.getRawQuery(), this.inheritUrlParameterNames)
.fragment(uri.getFragment())
.build();
link.setUrl(url);
}
catch (URISyntaxException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public final class DefaultInternalLinkInheritUrlParamLinkPostProcessor extends A
*/
public static final Set<String> DEFAULT_INHERIT_URL_PARAMETER_NAMES = Set.of(
"debugClientLibs",
"wcmmode"
);
"wcmmode");

/**
* Initialize inherited URL parameter names.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wcm/handler/link/type/ExternalLinkType.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public boolean hasRichTextPlugin() {
}

@Override
@SuppressWarnings({ "unused", "null" })
@SuppressWarnings({
"unused", "null"
})
public boolean accepts(@NotNull String linkRef) {
// test for null because earlier versions of this method did not have the @NotNull annotation
if (linkRef == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public final class InternalCrossContextLinkType extends LinkType {
public static final @NotNull String ID = "internalCrossContext";

private final @NotNull InternalLinkResolverOptions resolverOptions = new InternalLinkResolverOptions()
.primaryLinkRefProperty(getPrimaryLinkRefProperty())
.rewritePathToContext(false)
.useTargetContext(true);
.primaryLinkRefProperty(getPrimaryLinkRefProperty())
.rewritePathToContext(false)
.useTargetContext(true);

@Self
private InternalLinkResolver internalLinkResolver;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/wcm/handler/link/type/InternalLinkType.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public final class InternalLinkType extends LinkType {
public static final @NotNull String ID = "internal";

private final @NotNull InternalLinkResolverOptions resolverOptions = new InternalLinkResolverOptions()
.primaryLinkRefProperty(getPrimaryLinkRefProperty())
.rewritePathToContext(true)
.useTargetContext(false);
.primaryLinkRefProperty(getPrimaryLinkRefProperty())
.rewritePathToContext(true)
.useTargetContext(false);

@Self
private InternalLinkResolver internalLinkResolver;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/wcm/handler/link/type/MediaLinkType.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public boolean accepts(@NotNull String linkRef) {
boolean isDownload = props.get(LinkNameConstants.PN_LINK_MEDIA_DOWNLOAD, false);

MediaArgs mediaArgs = new MediaArgs()
// only allow linking to "download" media formats
.download(true)
// content disposition header for download links
.contentDispositionAttachment(isDownload)
// disable web-optimized image delivery to get asset in original resolution
.webOptimizedImageDeliveryDisabled(true)
.urlMode(linkRequest.getLinkArgs().getUrlMode());
// only allow linking to "download" media formats
.download(true)
// content disposition header for download links
.contentDispositionAttachment(isDownload)
// disable web-optimized image delivery to get asset in original resolution
.webOptimizedImageDeliveryDisabled(true)
.urlMode(linkRequest.getLinkArgs().getUrlMode());

// resolve media library reference
Media media = mediaHandler.get(mediaRef, mediaArgs).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ public boolean acceptPage(@Nullable Page page, @NotNull InternalLinkResolverOpti

// build link url
linkUrl = resolvingUrlHandler.get(targetPage)
.selectors(selectors)
.extension(fileExtension)
.suffix(suffix)
.queryString(queryString)
.fragment(fragment)
.urlMode(linkArgs.getUrlMode())
.vanityMode(linkArgs.getVanityMode())
.disableSuffixSelector(linkArgs.isDisableSuffixSelector())
.buildExternalLinkUrl(targetPage);
.selectors(selectors)
.extension(fileExtension)
.suffix(suffix)
.queryString(queryString)
.fragment(fragment)
.urlMode(linkArgs.getUrlMode())
.vanityMode(linkArgs.getVanityMode())
.disableSuffixSelector(linkArgs.isDisableSuffixSelector())
.buildExternalLinkUrl(targetPage);
}

// mark link as invalid if a reference was set that could not be resolved
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wcm/handler/link/ui/ResourceLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
/**
* Generic resource-based link model.
*/
@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
@Model(adaptables = {
SlingHttpServletRequest.class, Resource.class
})
public class ResourceLink {

@Self
Expand Down
58 changes: 30 additions & 28 deletions src/test/java/io/wcm/handler/link/LinkArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class LinkArgsTest {
@Test
void testProperties() {
LinkArgs linkArgs = new LinkArgs()
.urlMode(UrlModes.FULL_URL)
.dummyLink(true)
.dummyLinkUrl("/test/url")
.selectors("sel1")
.extension("ext1")
.suffix("suffix1")
.queryString("query1")
.fragment("fragment1")
.windowTarget("_parent")
.disableSuffixSelector(true)
.linkTargetUrlFallbackProperty("property1");
.urlMode(UrlModes.FULL_URL)
.dummyLink(true)
.dummyLinkUrl("/test/url")
.selectors("sel1")
.extension("ext1")
.suffix("suffix1")
.queryString("query1")
.fragment("fragment1")
.windowTarget("_parent")
.disableSuffixSelector(true)
.linkTargetUrlFallbackProperty("property1");

assertEquals(UrlModes.FULL_URL, linkArgs.getUrlMode());
assertTrue(linkArgs.isDummyLink());
Expand All @@ -58,17 +58,19 @@ void testProperties() {
assertEquals("fragment1", linkArgs.getFragment());
assertEquals("_parent", linkArgs.getWindowTarget());
assertTrue(linkArgs.isDisableSuffixSelector());
assertArrayEquals(new String[] { "property1" }, linkArgs.getLinkTargetUrlFallbackProperty());
assertArrayEquals(new String[] {
"property1"
}, linkArgs.getLinkTargetUrlFallbackProperty());
}

@Test
void testGetProperties() {
Map<String, Object> props = Map.of("prop1", "value1");

LinkArgs linkArgs = new LinkArgs()
.property("prop3", "value3")
.properties(props)
.property("prop2", "value2");
.property("prop3", "value3")
.properties(props)
.property("prop2", "value2");

assertEquals(3, linkArgs.getProperties().size());
assertEquals("value1", linkArgs.getProperties().get("prop1", String.class));
Expand All @@ -81,19 +83,19 @@ void testClone() {
Map<String, Object> props = Map.of("prop1", "value1", "prop2", "value2");

LinkArgs linkArgs = new LinkArgs()
.urlMode(UrlModes.FULL_URL)
.dummyLink(true)
.dummyLinkUrl("/test/url")
.selectors("sel1")
.extension("ext1")
.suffix("suffix1")
.queryString("query1")
.fragment("fragment1")
.windowTarget("_blank")
.linkTargetUrlFallbackProperty("property1")
.linkTargetWindowTargetFallbackProperty("property2")
.disableSuffixSelector(true)
.properties(props);
.urlMode(UrlModes.FULL_URL)
.dummyLink(true)
.dummyLinkUrl("/test/url")
.selectors("sel1")
.extension("ext1")
.suffix("suffix1")
.queryString("query1")
.fragment("fragment1")
.windowTarget("_blank")
.linkTargetUrlFallbackProperty("property1")
.linkTargetWindowTargetFallbackProperty("property2")
.disableSuffixSelector(true)
.properties(props);

LinkArgs clone = linkArgs.clone();
assertNotSame(linkArgs, clone);
Expand Down
Loading