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
40 @SuppressWarnings("java:S2160")
41 public final class FullUrlForceSecureUrlMode extends AbstractUrlMode {
42
43 private final boolean forcePublish;
44
45
46
47
48 public FullUrlForceSecureUrlMode(boolean forcePublish) {
49 this.forcePublish = forcePublish;
50 }
51
52 @Override
53 public @NotNull String getId() {
54 return "FULL_URL_FORCESECURE";
55 }
56
57 @SuppressWarnings("deprecation")
58 @Override
59 public String getLinkUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
60 @Nullable Page currentPage, @Nullable Page targetPage) {
61
62
63 IntegratorHandler integratorHandler = AdaptTo.notNull(adaptable, IntegratorHandler.class);
64 if (integratorHandler.isIntegratorTemplateMode()
65 && integratorHandler.getIntegratorMode().isUseUrlPlaceholders()) {
66 return IntegratorPlaceholder.URL_CONTENT_SECURE;
67 }
68
69 UrlConfig config = getUrlConfigForTarget(adaptable, targetPage);
70
71
72 if (!forcePublish && RunMode.isAuthor(runModes) && config.hasSiteUrlAuthor()) {
73 return config.getSiteUrlAuthor();
74 }
75
76
77 return config.getSiteUrlSecure();
78 }
79
80 @SuppressWarnings("deprecation")
81 @Override
82 public String getResourceUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
83 @Nullable Page currentPage, @Nullable Resource targetResource) {
84
85
86 IntegratorHandler integratorHandler = AdaptTo.notNull(adaptable, IntegratorHandler.class);
87 if (integratorHandler.isIntegratorTemplateMode()
88 && integratorHandler.getIntegratorMode().isUseUrlPlaceholders()) {
89 return IntegratorPlaceholder.URL_CONTENT_PROXY;
90 }
91
92 UrlConfig config = getUrlConfigForTarget(adaptable, targetResource);
93
94
95 if (!forcePublish && RunMode.isAuthor(runModes) && config.hasSiteUrlAuthor()) {
96 return config.getSiteUrlAuthor();
97 }
98
99
100 return config.getSiteUrlSecure();
101 }
102
103 }