001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.doxia.module.apt; 020 021import org.apache.maven.doxia.util.DoxiaUtils; 022 023/** 024 * A collection of utility methods for dealing with APT documents. 025 * 026 * @author ltheussl 027 * @since 1.1 028 */ 029public class AptUtils { 030 031 /** 032 * Checks if the given string corresponds to an external URI, 033 * ie is not a link within the same document nor a link to another 034 * document within the same site. This forwards to 035 * {@link org.apache.maven.doxia.util.DoxiaUtils#isExternalLink(String)}. 036 * 037 * @param link The link to check. 038 * @return True if DoxiaUtils.isExternalLink(link) returns true. 039 * @see org.apache.maven.doxia.util.DoxiaUtils#isExternalLink(String) 040 * @see #isInternalLink(String) 041 * @see #isLocalLink(String) 042 */ 043 public static boolean isExternalLink(String link) { 044 return DoxiaUtils.isExternalLink(link); 045 } 046 047 /** 048 * Checks if the given string corresponds to an internal link, 049 * ie it is a link to an anchor within the same document. 050 * 051 * @param link The link to check. 052 * @return True if link is neither an {@link #isExternalLink(String) external} 053 * nor a {@link #isLocalLink(String) local} link. 054 * @see org.apache.maven.doxia.util.DoxiaUtils#isInternalLink(String) 055 * @see #isExternalLink(String) 056 * @see #isLocalLink(String) 057 */ 058 public static boolean isInternalLink(String link) { 059 return (!isExternalLink(link) && !isLocalLink(link)); 060 } 061 062 /** 063 * Checks if the given string corresponds to a relative link to another document 064 * within the same site. 065 * 066 * @param link The link to check. 067 * @return True if the link starts with either "/", "./" or "../". 068 * @see org.apache.maven.doxia.util.DoxiaUtils#isLocalLink(String) 069 * @see #isExternalLink(String) 070 * @see #isInternalLink(String) 071 */ 072 public static boolean isLocalLink(String link) { 073 return (link.startsWith("/") || link.startsWith("./") || link.startsWith("../")); 074 } 075 076 private AptUtils() { 077 // utility class 078 } 079}