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.spi;
21  
22  import java.util.Collection;
23  import java.util.Collections;
24  
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.ConsumerType;
29  
30  import com.day.cq.wcm.api.Page;
31  
32  import io.wcm.handler.url.UrlMode;
33  import io.wcm.handler.url.UrlModes;
34  import io.wcm.handler.url.VanityMode;
35  import io.wcm.handler.url.integrator.IntegratorMode;
36  import io.wcm.sling.commons.caservice.ContextAwareService;
37  
38  /**
39   * {@link UrlHandlerConfig} OSGi services provide application-specific configuration for URL handling.
40   * Applications can set service properties or bundle headers as defined in {@link ContextAwareService} to apply this
41   * configuration only for resources that match the relevant resource paths.
42   */
43  @ConsumerType
44  public abstract class UrlHandlerConfig implements ContextAwareService {
45  
46    /**
47     * Returns the absolute path level where the root page of the site is located.
48     * @param contextResource Context resource that is assumed to be inside the site context.
49     * @return Root level or -1 if it could not be detected
50     */
51    public abstract int getSiteRootLevel(@Nullable Resource contextResource);
52  
53    /**
54     * Detects if a page has to be accessed in secure mode
55     * @param page Page Page
56     * @return true if secure mode is required
57     */
58    public boolean isSecure(@NotNull Page page) {
59      // not supported by default
60      return false;
61    }
62  
63    /**
64     * Detects if page is a integrator page and contains application redirect link information
65     * @param page Page
66     * @return true if Page is a integrator page
67     */
68    public boolean isIntegrator(@NotNull Page page) {
69      // not supported by default
70      return false;
71    }
72  
73    /**
74     * Gets the default URL mode.
75     * @return Default URL mode that is used if no URL mode is specified
76     */
77    public @NotNull UrlMode getDefaultUrlMode() {
78      return UrlModes.DEFAULT;
79    }
80  
81    /**
82     * Gets the supported integrator modes.
83     * @return Supported integrator modes
84     */
85    public @NotNull Collection<IntegratorMode> getIntegratorModes() {
86      // not supported by default
87      return Collections.emptyList();
88    }
89  
90    /**
91     * By default, URL handler users Sling Mapping to externalize all URLs, but removes and host name
92     * that may be configured in the Sling Mapping to prefer the host names defined in the URL handler
93     * {@link io.wcm.handler.url.SiteConfig}. By setting this flag to true, URL handler also uses
94     * the host names provided by Sling Mapping, and falls back to the default behavior if no are defined.
95     * @return true if URL handler should also respect host names defined in Sling Mapping
96     */
97    public boolean isHostProvidedBySlingMapping() {
98      return false;
99    }
100 
101   /**
102    * By default, vanity paths will not be taken into account when building URLs.
103    * Use the vanity mode to change this behaviour.
104    * @return the vanity mode to use when building urls
105    */
106   public VanityMode getDefaultVanityMode() {
107     return VanityMode.NEVER;
108   }
109 
110 }