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   * <p>
38   * If you want to implement your own UrlMode you can create a singleton class extending this interface. See
39   * {@link UrlModes} class as an example.
40   * </p>
41   */
42  @ProviderType
43  public interface UrlMode {
44  
45    /**
46     * @return Id uniquely identifying the URL mode
47     */
48    @NotNull
49    String getId();
50  
51    /**
52     * Get prefix (scheme, hostname and context path or integrator placeholder) for externalizing a content page link URL.
53     * @param adaptable Either request or resource which can be adapted to model implementations like
54     *          {@link UrlHandlerConfig}
55     * @param runModes Current sling run modes
56     * @param currentPage Current page (is null if not executed in request context)
57     * @param targetPage Target page to which internal link points to.
58     * @return Prefix or null
59     */
60    @Nullable
61    String getLinkUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
62        @Nullable Page currentPage, @Nullable Page targetPage);
63  
64    /**
65     * Get prefix (scheme, hostname and context path or integrator placeholder) for externalizing a resource URL.
66     * @param adaptable Either request or resource which can be adapted to model implementations like
67     *          {@link UrlHandlerConfig}
68     * @param runModes Current sling run modes
69     * @param currentPage Current page (is null if not executed in request context)
70     * @param targetResource Target resource to which the resource link points to
71     *          (may be null if it could not be resolved)
72     * @return Prefix or null
73     */
74    @Nullable
75    String getResourceUrlPrefix(@NotNull Adaptable adaptable, @NotNull Set<String> runModes,
76        @Nullable Page currentPage, @Nullable Resource targetResource);
77  
78  }