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.integrator;
21  
22  import org.apache.commons.lang3.StringUtils;
23  import org.jetbrains.annotations.NotNull;
24  import org.osgi.annotation.versioning.ProviderType;
25  
26  /**
27   * Placeholders used in integrator template markup that has to be replaced by integrating applications.
28   */
29  @ProviderType
30  public final class IntegratorPlaceholder {
31  
32    private IntegratorPlaceholder() {
33      // constants only
34    }
35  
36    /**
37     * Placeholder for the main content markup of the external application.
38     */
39    public static final @NotNull String APP_INCLUDE_CONTENT = "###APP_INCLUDE_CONTENT###";
40  
41    /**
42     * Placeholder for markup of the external application that should be placed in the HTML HEAD element.
43     */
44    public static final @NotNull String APP_INCLUDE_HEADER = "###APP_INCLUDE_HEADER###";
45  
46    /**
47     * Placeholder for markup of the external application that should be placed before the end of the BODY element.
48     */
49    public static final @NotNull String APP_INCLUDE_FOOTER = "###APP_INCLUDE_FOOTER###";
50  
51    /**
52     * Placeholder for scheme and hostname in URLs pointing to content pages (non-secure mode, HTTP).
53     */
54    public static final @NotNull String URL_CONTENT = "###URL_CONTENT###";
55  
56    /**
57     * Placeholder for scheme and hostname in URLs pointing to content pages (secure mode, HTTPS).
58     */
59    public static final @NotNull String URL_CONTENT_SECURE = "###URL_CONTENT_SECURE###";
60  
61    /**
62     * Placeholder for scheme and hostname in URLs pointing to resources (e.g. CSS/JS/Image references or AJAX requests).
63     * Secure- or non-secure mode depends on the external application. If AJAX requests are blocked by the
64     * same origin policy the external application may decide to route these URLs through a proxy with its own
65     * scheme and hostname.
66     */
67    public static final @NotNull String URL_CONTENT_PROXY = "###URL_CONTENT_PROXY###";
68  
69  
70    /**
71     * Placeholder with HTML BEGIN and END comments
72     * @param placeholder Placeholder
73     * @return Tag with comments
74     */
75    public static @NotNull String getTagWithComments(@NotNull String placeholder) {
76      return "\n<!-- " + getPlaceholderName(placeholder) + " START -->\n"
77          + placeholder
78          + "\n<!-- " + getPlaceholderName(placeholder) + " END -->\n";
79    }
80  
81    /**
82     * Get placeholder name without surrounding ###
83     * @param placeholder Placeholder
84     * @return Placeholder name
85     */
86    private static @NotNull String getPlaceholderName(@NotNull String placeholder) {
87      return StringUtils.remove(placeholder, "###");
88    }
89  
90  }