1 /* 2 * #%L 3 * wcm.io 4 * %% 5 * Copyright (C) 2015 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.link.type.helpers; 21 22 import org.apache.sling.api.resource.Resource; 23 import org.jetbrains.annotations.NotNull; 24 25 import io.wcm.handler.link.LinkNameConstants; 26 import io.wcm.handler.url.UrlHandler; 27 28 /** 29 * Options to influence the link resolving process from {@link InternalLinkResolver}. 30 */ 31 public final class InternalLinkResolverOptions { 32 33 private String primaryLinkRefProperty = LinkNameConstants.PN_LINK_CONTENT_REF; 34 private boolean rewritePathToContext = true; 35 private boolean useTargetContext; 36 37 /** 38 * Primary ink reference property. 39 * @return Name of the property in which the primary link reference is stored 40 */ 41 public String getPrimaryLinkRefProperty() { 42 return this.primaryLinkRefProperty; 43 } 44 45 /** 46 * Primary ink reference property. 47 * @param value Name of the property in which the primary link reference is stored 48 * @return this 49 */ 50 public @NotNull InternalLinkResolverOptions primaryLinkRefProperty(String value) { 51 this.primaryLinkRefProperty = value; 52 return this; 53 } 54 55 /** 56 * Rewrite path to context. 57 * @return If set to true it is ensured that all links target only pages inside the same inner-most configuration 58 * scope, which is usually the same site/language. All link paths referencing pages outside this content 59 * subtree are rewritten via {@link UrlHandler#rewritePathToContext(Resource)} with the root path of the 60 * inner-most configuration scope/site and then resolved. 61 */ 62 public boolean isRewritePathToContext() { 63 return this.rewritePathToContext; 64 } 65 66 /** 67 * Rewrite path to context. 68 * @param value If set to true it is ensured that all links target only pages inside the same inner-most configuration 69 * scope, which is usually the same site/language. All link paths referencing pages outside this content 70 * subtree are rewritten via {@link UrlHandler#rewritePathToContext(Resource)} with the root path of the 71 * inner-most configuration scope/site and then resolved. 72 * @return this 73 */ 74 public @NotNull InternalLinkResolverOptions rewritePathToContext(boolean value) { 75 this.rewritePathToContext = value; 76 return this; 77 } 78 79 80 /** 81 * User target context for URL building. 82 * @return If set to true an {@link io.wcm.handler.url.UrlHandler} with configuration from the configuration scope 83 * (e.g. site/language) from the target page is used to build the link URL to the internal page, and not the 84 * URL handler of the current resource's configuration scope (site/language). This makes only sense if 85 * additional the flag "rewritePathToContext" is set to false. 86 */ 87 public boolean isUseTargetContext() { 88 return this.useTargetContext; 89 } 90 91 /** 92 * User target context for URL building. 93 * @param value If set to true an {@link io.wcm.handler.url.UrlHandler} with configuration from the configuration 94 * scope 95 * (e.g. site/language) from the target page is used to build the link URL to the internal page, and not the 96 * URL handler of the current resource's configuration scope (site/language). This makes only sense if 97 * additional the flag "rewritePathToContext" is set to false. 98 * @return this 99 */ 100 public @NotNull InternalLinkResolverOptions useTargetContext(boolean value) { 101 this.useTargetContext = value; 102 return this; 103 } 104 105 }