View Javadoc
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.caravan.hal.docs.impl.augmenter;
21  
22  import org.apache.commons.lang3.StringUtils;
23  
24  /**
25   * Curie and link relation title metadata extracted from service info metadata.
26   */
27  final class CurieUtil {
28  
29    /**
30     * HAL specific separator for CURI names and relation.
31     */
32    private static final String LINK_RELATION_SEPARATOR = ":";
33  
34    /**
35     * Doc URI template suffix for curie links
36     */
37    private static final String CURIE_DOC_TEMPLATE_SUFFIX = ":{rel}";
38  
39    /**
40     * HAL specific relation for CURI links.
41     */
42    static final String LINK_RELATION_CURIES = "curies";
43  
44  
45    private CurieUtil() {
46      // static methods only
47    }
48  
49    public static String getCurieName(String rel) {
50      if (StringUtils.contains(rel, LINK_RELATION_SEPARATOR)) {
51        return StringUtils.substringBefore(rel, LINK_RELATION_SEPARATOR);
52      }
53      return rel;
54    }
55  
56    public static String toDocTemplate(String docsPath, String curie) {
57      return docsPath + "/" + curie + CURIE_DOC_TEMPLATE_SUFFIX;
58    }
59  
60  }