View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia.module.apt;
20  
21  import org.apache.maven.doxia.util.DoxiaUtils;
22  
23  /**
24   * A collection of utility methods for dealing with APT documents.
25   *
26   * @author ltheussl
27   * @since 1.1
28   */
29  public class AptUtils {
30  
31      /**
32       * Checks if the given string corresponds to an external URI,
33       * ie is not a link within the same document nor a link to another
34       * document within the same site. This forwards to
35       * {@link org.apache.maven.doxia.util.DoxiaUtils#isExternalLink(String)}.
36       *
37       * @param link The link to check.
38       * @return True if DoxiaUtils.isExternalLink(link) returns true.
39       * @see org.apache.maven.doxia.util.DoxiaUtils#isExternalLink(String)
40       * @see #isInternalLink(String)
41       * @see #isLocalLink(String)
42       */
43      public static boolean isExternalLink(String link) {
44          return DoxiaUtils.isExternalLink(link);
45      }
46  
47      /**
48       * Checks if the given string corresponds to an internal link,
49       * ie it is a link to an anchor within the same document.
50       *
51       * @param link The link to check.
52       * @return True if link is neither an {@link #isExternalLink(String) external}
53       * nor a {@link #isLocalLink(String) local} link.
54       * @see org.apache.maven.doxia.util.DoxiaUtils#isInternalLink(String)
55       * @see #isExternalLink(String)
56       * @see #isLocalLink(String)
57       */
58      public static boolean isInternalLink(String link) {
59          return (!isExternalLink(link) && !isLocalLink(link));
60      }
61  
62      /**
63       * Checks if the given string corresponds to a relative link to another document
64       * within the same site.
65       *
66       * @param link The link to check.
67       * @return True if the link starts with either "/", "./" or "../".
68       * @see org.apache.maven.doxia.util.DoxiaUtils#isLocalLink(String)
69       * @see #isExternalLink(String)
70       * @see #isInternalLink(String)
71       */
72      public static boolean isLocalLink(String link) {
73          return (link.startsWith("/") || link.startsWith("./") || link.startsWith("../"));
74      }
75  
76      private AptUtils() {
77          // utility class
78      }
79  }