View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2014 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.handler.url;
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  import org.osgi.annotation.versioning.ProviderType;
29  
30  import com.day.cq.wcm.api.Page;
31  
32  import io.wcm.handler.url.spi.UrlHandlerConfig;
33  
34  /**
35   * An UrlMode define the externalization logic for URLs depending on context-specific configuration parameters
36   * defined in {@link SiteConfig}.
37   *
38   * <p>
39   * If you want to implement your own UrlMode you can create a singleton class extending this interface. See
40   * {@link UrlModes} class as an example.
41   * </p>
42   */
43  @ProviderType
44  public interface UrlMode {
45  
46    /**
47     * Gets the URL mode ID.
48     * @return Id uniquely identifying the URL mode
49     */
50    @NotNull
51    String getId();
52  
53    /**
54     * Get prefix (scheme, hostname and context path or integrator placeholder) for externalizing a content page link URL.
55     * @param adaptable Either request or resource which can be adapted to model implementations like
56     *          {@link UrlHandlerConfig}
57     * @param runModes Current sling run modes
58     * @param currentPage Current page (is null if not executed in request context)
59     * @param targetPage Target page to which internal link points to.
60     * @return Prefix or null
61     */
62    @Nullable
63    String getLinkUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
64        @Nullable Page currentPage, @Nullable Page targetPage);
65  
66    /**
67     * Get prefix (scheme, hostname and context path or integrator placeholder) for externalizing a resource URL.
68     * @param adaptable Either request or resource which can be adapted to model implementations like
69     *          {@link UrlHandlerConfig}
70     * @param runModes Current sling run modes
71     * @param currentPage Current page (is null if not executed in request context)
72     * @param targetResource Target resource to which the resource link points to
73     *          (may be null if it could not be resolved)
74     * @return Prefix or null
75     */
76    @Nullable
77    String getResourceUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
78        @Nullable Page currentPage, @Nullable Resource targetResource);
79  
80    /**
81     * Forces protocol and hostname to be stripped from URLs even is relying to hostnames provided by Sling Mapping.
82     * @return true if host name should always be stripped
83     */
84    default boolean isForceStripHostName() {
85      return false;
86    }
87  
88  }