Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 193   Methods: 5
NCLOC: 79   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JspNameMangler.java 44.4% 51.4% 60% 50%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.jsp;
 55   
 import java.io.File;
 56   
 
 57   
 /**
 58   
  * This is a class derived from the Jasper code
 59   
  * (org.apache.jasper.compiler.CommandLineCompiler) to map from a JSP filename
 60   
  * to a valid Java classname.
 61   
  *
 62   
  * @author Steve Loughran
 63   
  * @author Danno Ferrin
 64   
  */
 65   
 public class JspNameMangler implements JspMangler {
 66   
 
 67   
     /**
 68   
      * this is the list of keywords which can not be used as classnames
 69   
      */
 70   
     public static String[] keywords = {
 71   
             "assert",
 72   
             "abstract", "boolean", "break", "byte",
 73   
             "case", "catch", "char", "class",
 74   
             "const", "continue", "default", "do",
 75   
             "double", "else", "extends", "final",
 76   
             "finally", "float", "for", "goto",
 77   
             "if", "implements", "import",
 78   
             "instanceof", "int", "interface",
 79   
             "long", "native", "new", "package",
 80   
             "private", "protected", "public",
 81   
             "return", "short", "static", "super",
 82   
             "switch", "synchronized", "this",
 83   
             "throw", "throws", "transient",
 84   
             "try", "void", "volatile", "while"
 85   
             };
 86   
 
 87   
 
 88   
     /**
 89   
      * map from a jsp file to a java filename; does not do packages
 90   
      *
 91   
      * @param jspFile file
 92   
      * @return java filename
 93   
      */
 94  1
     public String mapJspToJavaName(File jspFile) {
 95  1
         return mapJspToBaseName(jspFile) + ".java";
 96   
     }
 97   
 
 98   
 
 99   
     /**
 100   
      * map from a jsp file to a base name; does not deal with extensions
 101   
      *
 102   
      * @param jspFile jspFile file
 103   
      * @return exensionless potentially remapped name
 104   
      */
 105  1
     private String mapJspToBaseName(File jspFile) {
 106  1
         String className;
 107  1
         className = stripExtension(jspFile);
 108   
 
 109   
         // since we don't mangle extensions like the servlet does,
 110   
         // we need to check for keywords as class names
 111  1
         for (int i = 0; i < keywords.length; ++i) {
 112  48
             if (className.equals(keywords[i])) {
 113  0
                 className += "%";
 114  0
                 break;
 115   
             }
 116   
         }
 117   
 
 118   
         // Fix for invalid characters. If you think of more add to the list.
 119  1
         StringBuffer modifiedClassName = new StringBuffer(className.length());
 120   
         // first char is more restrictive than the rest
 121  1
         char firstChar = className.charAt(0);
 122  1
         if (Character.isJavaIdentifierStart(firstChar)) {
 123  1
             modifiedClassName.append(firstChar);
 124   
         } else {
 125  0
             modifiedClassName.append(mangleChar(firstChar));
 126   
         }
 127   
         // this is the rest
 128  1
         for (int i = 1; i < className.length(); i++) {
 129  5
             char subChar = className.charAt(i);
 130  5
             if (Character.isJavaIdentifierPart(subChar)) {
 131  5
                 modifiedClassName.append(subChar);
 132   
             } else {
 133  0
                 modifiedClassName.append(mangleChar(subChar));
 134   
             }
 135   
         }
 136  1
         return modifiedClassName.toString();
 137   
     }
 138   
 
 139   
 
 140   
     /**
 141   
      * get short filename from file
 142   
      *
 143   
      * @param jspFile file in
 144   
      * @return file without any jsp extension
 145   
      */
 146  1
     private String stripExtension(File jspFile) {
 147  1
         String className;
 148  1
         String filename = jspFile.getName();
 149  1
         if (filename.endsWith(".jsp")) {
 150  1
             className = filename.substring(0, filename.length() - 4);
 151   
         } else {
 152  0
             className = filename;
 153   
         }
 154  1
         return className;
 155   
     }
 156   
 
 157   
 
 158   
     /**
 159   
      * definition of the char escaping algorithm
 160   
      *
 161   
      * @param ch char to mangle
 162   
      * @return mangled string; 5 digit hex value
 163   
      */
 164  0
     private static final String mangleChar(char ch) {
 165   
 
 166  0
         if (ch == File.separatorChar) {
 167  0
             ch = '/';
 168   
         }
 169  0
         String s = Integer.toHexString(ch);
 170  0
         int nzeros = 5 - s.length();
 171  0
         char[] result = new char[6];
 172  0
         result[0] = '_';
 173  0
         for (int i = 1; i <= nzeros; ++i) {
 174  0
             result[i] = '0';
 175   
         }
 176  0
         int resultIndex = 0;
 177  0
         for (int i = nzeros + 1; i < 6; ++i) {
 178  0
             result[i] = s.charAt(resultIndex++);
 179   
         }
 180  0
         return new String(result);
 181   
     }
 182   
 
 183   
     /**
 184   
      * taking in the substring representing the path relative to the source dir
 185   
      * return a new string representing the destination path
 186   
      * not supported, as jasper in tomcat4.0 doesnt either
 187   
      */
 188  0
     public String mapPath(String path) {
 189  0
         return null;
 190   
     }
 191   
 }
 192   
 
 193