1 | /*
|
---|
2 | * Copyright 2000-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.jsp;
|
---|
19 |
|
---|
20 | import java.io.File;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * this class implements the name mangling rules of the jasper in tomcat4.1.x
|
---|
24 | * which is likely to remain for some time
|
---|
25 | * @see org.apache.jasper.JspCompilationContext
|
---|
26 | */
|
---|
27 | public class Jasper41Mangler implements JspMangler {
|
---|
28 |
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * map from a jsp file to a java filename; does not do packages
|
---|
32 | *
|
---|
33 | * @param jspFile file
|
---|
34 | * @return java filename
|
---|
35 | */
|
---|
36 | public String mapJspToJavaName(File jspFile) {
|
---|
37 | String jspUri = jspFile.getAbsolutePath();
|
---|
38 | int start = jspUri.lastIndexOf(File.separatorChar) + 1;
|
---|
39 | int end = jspUri.length();
|
---|
40 | StringBuffer modifiedClassName;
|
---|
41 | modifiedClassName = new StringBuffer(jspUri.length() - start);
|
---|
42 | if (!Character.isJavaIdentifierStart(jspUri.charAt(start))
|
---|
43 | || jspUri.charAt(start) == '_') {
|
---|
44 | // If the first char is not a start of Java identifier or is _
|
---|
45 | // prepend a '_'.
|
---|
46 | modifiedClassName.append('_');
|
---|
47 | }
|
---|
48 | for (int i = start; i < end; i++) {
|
---|
49 | char ch = jspUri.charAt(i);
|
---|
50 | if (Character.isJavaIdentifierPart(ch)) {
|
---|
51 | modifiedClassName.append(ch);
|
---|
52 | } else if (ch == '.') {
|
---|
53 | modifiedClassName.append('_');
|
---|
54 | } else {
|
---|
55 | modifiedClassName.append(mangleChar(ch));
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return modifiedClassName.toString();
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Mangle the specified character to create a legal Java class name.
|
---|
63 | */
|
---|
64 | private static final String mangleChar(char ch) {
|
---|
65 |
|
---|
66 | String s = Integer.toHexString(ch);
|
---|
67 | int nzeros = 5 - s.length();
|
---|
68 | char[] result = new char[6];
|
---|
69 | result[0] = '_';
|
---|
70 | for (int i = 1; i <= nzeros; i++) {
|
---|
71 | result[i] = '0';
|
---|
72 | }
|
---|
73 | for (int i = nzeros + 1, j = 0; i < 6; i++, j++) {
|
---|
74 | result[i] = s.charAt(j);
|
---|
75 | }
|
---|
76 | return new String(result);
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * taking in the substring representing the path relative to the source dir
|
---|
82 | * return a new string representing the destination path
|
---|
83 | * @todo
|
---|
84 | */
|
---|
85 | public String mapPath(String path) {
|
---|
86 | return null;
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|