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.impl.modes;
21  
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.sling.api.adapter.Adaptable;
24  
25  import io.wcm.handler.url.SiteConfig;
26  
27  /**
28   * Helper class for accessing site URL configuration in URL mode implementation.
29   */
30  class UrlConfig {
31  
32    private final String siteUrl;
33    private final String siteUrlSecure;
34    private final String siteUrlAuthor;
35  
36    UrlConfig(Adaptable adaptable) {
37      SiteConfig config = adaptable.adaptTo(SiteConfig.class);
38      if (config != null) {
39        this.siteUrl = config.siteUrl();
40        this.siteUrlSecure = StringUtils.defaultString(config.siteUrlSecure(), this.siteUrl);
41        this.siteUrlAuthor = config.siteUrlAuthor();
42      }
43      else {
44        this.siteUrl = null;
45        this.siteUrlSecure = null;
46        this.siteUrlAuthor = null;
47      }
48    }
49  
50    /**
51     * @return Site URL
52     */
53    public String getSiteUrl() {
54      return this.siteUrl;
55    }
56  
57    /**
58     * @return Site URL secure (fallback to Site URL)
59     */
60    public String getSiteUrlSecure() {
61      return this.siteUrlSecure;
62    }
63  
64    /**
65     * @return Site URL author
66     */
67    public String getSiteUrlAuthor() {
68      return this.siteUrlAuthor;
69    }
70  
71    /**
72     * @return true if at least Site URL is set
73     */
74    public boolean isValid() {
75      return StringUtils.isNotEmpty(this.siteUrl);
76    }
77  
78    /**
79     * @return true if site URL for author is set
80     */
81    public boolean hasSiteUrlAuthor() {
82      return StringUtils.isNotEmpty(this.siteUrlAuthor);
83    }
84  
85  }