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 * @return Default URL mode that is used if no URL mode is specified 75 */ 76 public @NotNull UrlMode getDefaultUrlMode() { 77 return UrlModes.DEFAULT; 78 } 79 80 /** 81 * @return Supported integrator modes 82 */ 83 public @NotNull Collection<IntegratorMode> getIntegratorModes() { 84 // not supported by default 85 return Collections.emptyList(); 86 } 87 88 /** 89 * By default, URL handler users Sling Mapping to externalize all URLs, but removes and host name 90 * that may be configured in the Sling Mapping to prefer the host names defined in the URL handler 91 * {@link io.wcm.handler.url.SiteConfig}. By setting this flag to true, URL handler also uses 92 * the host names provided by Sling Mapping, and falls back to the default behavior if no are defined. 93 * @return true if URL handler should also respect host names defined in Sling Mapping 94 */ 95 public boolean isHostProvidedBySlingMapping() { 96 return false; 97 } 98 99 /** 100 * By default, vanity paths will not be taken into account when building URLs. 101 * Use the vanity mode to change this behaviour. 102 * @return the vanity mode to use when building urls 103 */ 104 public VanityMode getDefaultVanityMode() { 105 return VanityMode.NEVER; 106 } 107 108 }