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.handler.url.spi.UrlHandlerConfig;
34 import io.wcm.sling.commons.adapter.AdaptTo;
35 import io.wcm.wcm.commons.util.RunMode;
36
37
38
39
40
41
42 @SuppressWarnings("java:S2160")
43 public final class FullUrlUrlMode extends AbstractUrlMode {
44
45 private final boolean forcePublish;
46
47
48
49
50 public FullUrlUrlMode(boolean forcePublish) {
51 this.forcePublish = forcePublish;
52 }
53
54 @Override
55 public @NotNull String getId() {
56 return "FULL_URL";
57 }
58
59 @SuppressWarnings("deprecation")
60 @Override
61 public String getLinkUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
62 @Nullable Page currentPage, @Nullable Page targetPage) {
63 UrlHandlerConfig urlHandlerConfig = AdaptTo.notNull(adaptable, UrlHandlerConfig.class);
64
65
66 IntegratorHandler integratorHandler = AdaptTo.notNull(adaptable, IntegratorHandler.class);
67 if (integratorHandler.isIntegratorTemplateMode()
68 && integratorHandler.getIntegratorMode().isUseUrlPlaceholders()) {
69 if (targetPage != null && urlHandlerConfig.isSecure(targetPage)) {
70 return IntegratorPlaceholder.URL_CONTENT_SECURE;
71 }
72 else {
73 return IntegratorPlaceholder.URL_CONTENT;
74 }
75 }
76
77 UrlConfig config = getUrlConfigForTarget(adaptable, targetPage);
78
79
80 if (!forcePublish && RunMode.isAuthor(runModes) && config.hasSiteUrlAuthor()) {
81 return config.getSiteUrlAuthor();
82 }
83
84
85 if (targetPage != null && urlHandlerConfig.isSecure(targetPage)) {
86 return config.getSiteUrlSecure();
87 }
88 else {
89 return config.getSiteUrl();
90 }
91 }
92
93 @SuppressWarnings("deprecation")
94 @Override
95 public String getResourceUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
96 @Nullable Page currentPage, @Nullable Resource targetResource) {
97
98
99 IntegratorHandler integratorHandler = AdaptTo.notNull(adaptable, IntegratorHandler.class);
100 if (integratorHandler.isIntegratorTemplateMode()
101 && integratorHandler.getIntegratorMode().isUseUrlPlaceholders()) {
102 return IntegratorPlaceholder.URL_CONTENT_PROXY;
103 }
104
105 UrlConfig config = getUrlConfigForTarget(adaptable, targetResource);
106
107
108 if (!forcePublish && RunMode.isAuthor(runModes) && config.hasSiteUrlAuthor()) {
109 return config.getSiteUrlAuthor();
110 }
111
112
113 UrlHandlerConfig urlHandlerConfig = AdaptTo.notNull(adaptable, UrlHandlerConfig.class);
114 if ((currentPage != null && urlHandlerConfig.isSecure(currentPage))
115 || integratorHandler.isIntegratorTemplateSecureMode()) {
116 return config.getSiteUrlSecure();
117 }
118 else {
119 return config.getSiteUrl();
120 }
121 }
122
123 }