KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > jsp > Jasper41Mangler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs.optional.jsp;
20
21 import java.io.File JavaDoc;
22
23 /**
24  * this class implements the name mangling rules of the jasper in tomcat4.1.x
25  * which is likely to remain for some time
26  * @see "org.apache.jasper.JspCompilationContext"
27  */

28 public class Jasper41Mangler implements JspMangler {
29
30
31     /**
32      * map from a jsp file to a java filename; does not do packages
33      *
34      * @param jspFile file
35      * @return java filename
36      */

37     public String JavaDoc mapJspToJavaName(File JavaDoc jspFile) {
38         String JavaDoc jspUri = jspFile.getAbsolutePath();
39         int start = jspUri.lastIndexOf(File.separatorChar) + 1;
40         int end = jspUri.length();
41         StringBuffer JavaDoc modifiedClassName;
42         modifiedClassName = new StringBuffer JavaDoc(jspUri.length() - start);
43         if (!Character.isJavaIdentifierStart(jspUri.charAt(start))
44             || jspUri.charAt(start) == '_') {
45             // If the first char is not a start of Java identifier or is _
46
// prepend a '_'.
47
modifiedClassName.append('_');
48         }
49         for (int i = start; i < end; i++) {
50             char ch = jspUri.charAt(i);
51             if (Character.isJavaIdentifierPart(ch)) {
52                 modifiedClassName.append(ch);
53             } else if (ch == '.') {
54                 modifiedClassName.append('_');
55             } else {
56                 modifiedClassName.append(mangleChar(ch));
57             }
58         }
59         return modifiedClassName.toString();
60     }
61
62     /**
63      * Mangle the specified character to create a legal Java class name.
64      */

65     private static String JavaDoc mangleChar(char ch) {
66
67         String JavaDoc s = Integer.toHexString(ch);
68         int nzeros = 5 - s.length();
69         char[] result = new char[6];
70         result[0] = '_';
71         for (int i = 1; i <= nzeros; i++) {
72             result[i] = '0';
73         }
74         for (int i = nzeros + 1, j = 0; i < 6; i++, j++) {
75             result[i] = s.charAt(j);
76         }
77         return new String JavaDoc(result);
78     }
79
80
81     /**
82      * taking in the substring representing the path relative to the source dir
83      * return a new string representing the destination path
84      * @param path not used.
85      * @return null as this is not implemented.
86      * @todo
87      */

88     public String JavaDoc mapPath(String JavaDoc path) {
89         return null;
90     }
91
92 }
93
Popular Tags