1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.handler.url.impl.modes;
21
22 import java.util.Set;
23
24 import org.apache.sling.api.adapter.Adaptable;
25 import org.apache.sling.api.resource.Resource;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28
29 import com.day.cq.wcm.api.Page;
30
31 import io.wcm.handler.url.integrator.IntegratorHandler;
32 import io.wcm.handler.url.integrator.IntegratorPlaceholder;
33 import io.wcm.sling.commons.adapter.AdaptTo;
34 import io.wcm.wcm.commons.util.RunMode;
35
36
37
38
39 @SuppressWarnings("java:S2160")
40 public final class FullUrlForceNonSecureUrlMode extends AbstractUrlMode {
41
42 private final boolean forcePublish;
43
44
45
46
47 public FullUrlForceNonSecureUrlMode(boolean forcePublish) {
48 this.forcePublish = forcePublish;
49 }
50
51 @Override
52 public @NotNull String getId() {
53 return "FULL_URL_FORCENONSECURE";
54 }
55
56 @SuppressWarnings("deprecation")
57 @Override
58 public String getLinkUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
59 @Nullable Page currentPage, @Nullable Page targetPage) {
60
61
62 IntegratorHandler integratorHandler = AdaptTo.notNull(adaptable, IntegratorHandler.class);
63 if (integratorHandler.isIntegratorTemplateMode()
64 && integratorHandler.getIntegratorMode().isUseUrlPlaceholders()) {
65 return IntegratorPlaceholder.URL_CONTENT;
66 }
67
68 UrlConfig config = getUrlConfigForTarget(adaptable, targetPage);
69
70
71 if (!forcePublish && RunMode.isAuthor(runModes) && config.hasSiteUrlAuthor()) {
72 return config.getSiteUrlAuthor();
73 }
74
75
76 return config.getSiteUrl();
77 }
78
79 @SuppressWarnings("deprecation")
80 @Override
81 public String getResourceUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
82 @Nullable Page currentPage, @Nullable Resource targetResource) {
83
84
85 IntegratorHandler integratorHandler = AdaptTo.notNull(adaptable, IntegratorHandler.class);
86 if (integratorHandler.isIntegratorTemplateMode()
87 && integratorHandler.getIntegratorMode().isUseUrlPlaceholders()) {
88 return IntegratorPlaceholder.URL_CONTENT_PROXY;
89 }
90
91 UrlConfig config = getUrlConfigForTarget(adaptable, targetResource);
92
93
94 if (!forcePublish && RunMode.isAuthor(runModes) && config.hasSiteUrlAuthor()) {
95 return config.getSiteUrlAuthor();
96 }
97
98
99 return config.getSiteUrl();
100 }
101
102 }