Coverage Report - org.apache.maven.doxia.sink.StructureSink
 
Classes in this File Line Coverage Branch Coverage Complexity
StructureSink
0%
0/10
0%
0/3
2
 
 1  
 package org.apache.maven.doxia.sink;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 /** Utility methods for Sinks. */
 23  0
 public class StructureSink
 24  
 {
 25  
     /**
 26  
      * Checks if the given string corresponds to an external URI,
 27  
      * ie is not a link within the same document. 
 28  
      *
 29  
      * @param link The link to check.
 30  
      * @return True if the link (ignoring case) starts with either of the
 31  
      * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/",
 32  
      * "../" or "./". Note that Windows style separators "\" are not allowed
 33  
      * for URIs, see  http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
 34  
      */
 35  
     public static boolean isExternalLink( String link )
 36  
     {
 37  0
         String text = link.toLowerCase();
 38  
 
 39  0
         return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) == 0
 40  
             || text.indexOf( "ftp:/" ) == 0 || text.indexOf( "mailto:" ) == 0
 41  
             || text.indexOf( "file:/" ) == 0 || text.indexOf( "../" ) == 0
 42  
             || text.indexOf( "./" ) == 0 );
 43  
     }
 44  
 
 45  
     /**
 46  
      * Transforms the given text such that it can be used as a link.
 47  
      *
 48  
      * @param text The text to transform.
 49  
      * @return A text with escaped special characters.
 50  
      * @todo This is apt specific, need to clarify general use.
 51  
      */
 52  
     public static String linkToKey( String text )
 53  
     {
 54  0
         int length = text.length();
 55  0
         StringBuffer buffer = new StringBuffer( length );
 56  
 
 57  0
         for ( int i = 0; i < length; ++i )
 58  
         {
 59  0
             char c = text.charAt( i );
 60  0
             if ( Character.isLetterOrDigit( c ) )
 61  
             {
 62  0
                 buffer.append( Character.toLowerCase( c ) );
 63  
             }
 64  
         }
 65  
 
 66  0
         return buffer.toString();
 67  
     }
 68  
 }