1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package net.sf.infrared.aspects.jsp; |
23 |
|
|
24 |
|
import java.io.File; |
25 |
|
import java.util.Properties; |
26 |
|
import java.util.regex.Matcher; |
27 |
|
import java.util.regex.Pattern; |
28 |
|
|
29 |
|
import net.sf.infrared.aspects.AbstractExecutionContext; |
30 |
|
|
31 |
|
public class JspContext extends AbstractExecutionContext { |
32 |
1 |
private static Properties cache = new Properties(); |
33 |
|
|
34 |
|
private static final String JASPER_PREFIX = "org.apache.jsp."; |
35 |
|
|
36 |
|
private static final String WEBLOGIC_PREFIX = "jsp_servlet._"; |
37 |
|
|
38 |
|
private String jspName; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public JspContext(String jspClassName) { |
45 |
1 |
super("Jsp"); |
46 |
1 |
if (jspClassName.startsWith(JASPER_PREFIX)) { |
47 |
0 |
jspName = JspContext.getJasperJspName(jspClassName); |
48 |
1 |
} else if (jspClassName.startsWith(WEBLOGIC_PREFIX)) { |
49 |
0 |
jspName = JspContext.getWeblogicJspName(jspClassName); |
50 |
|
} else { |
51 |
1 |
jspName = jspClassName; |
52 |
|
} |
53 |
1 |
} |
54 |
|
|
55 |
|
public JspContext(Class jspClass) { |
56 |
0 |
this(jspClass.getName()); |
57 |
0 |
} |
58 |
|
|
59 |
|
public JspContext(String name, String layer) { |
60 |
1 |
super(layer); |
61 |
|
|
62 |
1 |
this.jspName = name; |
63 |
|
|
64 |
1 |
} |
65 |
|
|
66 |
|
public String getName() { |
67 |
0 |
if (jspName == null) { |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
} |
72 |
0 |
return jspName; |
73 |
|
} |
74 |
|
|
75 |
|
public String toString() { |
76 |
0 |
return "Jsp " + getName(); |
77 |
|
} |
78 |
|
|
79 |
|
public boolean equals(Object o) { |
80 |
1 |
if (o == null) { |
81 |
0 |
return false; |
82 |
|
} |
83 |
|
|
84 |
1 |
if (o == this) { |
85 |
0 |
return true; |
86 |
|
} |
87 |
|
|
88 |
1 |
if (! (o instanceof JspContext) ) { |
89 |
0 |
return false; |
90 |
|
} |
91 |
|
|
92 |
1 |
JspContext other = (JspContext) o; |
93 |
|
|
94 |
1 |
return other.jspName.equals( this.jspName ); |
95 |
|
} |
96 |
|
|
97 |
|
public int hashCode() { |
98 |
0 |
return 7 * jspName.hashCode(); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
static String getJasperJspName(String jspClassName) { |
105 |
5 |
String jspName = (String) cache.get(jspClassName); |
106 |
5 |
if (jspName != null) { |
107 |
0 |
return jspName; |
108 |
|
} |
109 |
5 |
jspName = jspClassName.substring(JASPER_PREFIX.length()); |
110 |
|
|
111 |
|
|
112 |
5 |
jspName = jspName.replace('.', '/'); |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
5 |
Pattern pattern = Pattern.compile("_[a-f0-9]{4}"); |
117 |
5 |
Matcher matcher = pattern.matcher(jspName); |
118 |
5 |
int findFrom = 0; |
119 |
12 |
while (matcher.find(findFrom)) { |
120 |
7 |
findFrom = matcher.start() + 1; |
121 |
7 |
String mangledSpecialChar = matcher.group(); |
122 |
7 |
mangledSpecialChar = mangledSpecialChar.substring(1, mangledSpecialChar.length()); |
123 |
7 |
String unmangedSpecialChar = JspContext.getUnmangedSpecialChar(mangledSpecialChar); |
124 |
7 |
jspName = jspName.replaceAll("_" + mangledSpecialChar, unmangedSpecialChar); |
125 |
7 |
matcher = pattern.matcher(jspName); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
5 |
jspName = jspName.substring(0, jspName.length() - 4); |
130 |
5 |
jspName = jspName + ".jsp"; |
131 |
5 |
cache.put(jspClassName, jspName); |
132 |
5 |
return jspName; |
133 |
|
} |
134 |
|
|
135 |
|
static String getWeblogicJspName(String jspClassName) { |
136 |
3 |
String jspName = (String) cache.get(jspClassName); |
137 |
3 |
if (jspName != null) { |
138 |
0 |
return jspName; |
139 |
|
} |
140 |
|
|
141 |
3 |
jspName = jspClassName.substring(WEBLOGIC_PREFIX.length()); |
142 |
|
|
143 |
|
|
144 |
3 |
jspName = jspName.replaceAll("\\._", "/"); |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
3 |
Pattern pattern = Pattern.compile("_[0-9]+_"); |
149 |
3 |
Matcher matcher = pattern.matcher(jspName); |
150 |
7 |
while (matcher.find()) { |
151 |
4 |
String specialCharMangle = matcher.group(); |
152 |
4 |
specialCharMangle = specialCharMangle.substring(1, specialCharMangle.length() - 1); |
153 |
4 |
int ch = Integer.parseInt(specialCharMangle); |
154 |
4 |
jspName = jspName.replaceAll("_" + specialCharMangle + "_", String.valueOf((char) ch)); |
155 |
4 |
matcher = pattern.matcher(jspName); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
3 |
jspName = jspName.replaceAll("/_", "/"); |
160 |
3 |
jspName = jspName.replaceAll("^_", ""); |
161 |
3 |
jspName = jspName + ".jsp"; |
162 |
|
|
163 |
3 |
cache.put(jspClassName, jspName); |
164 |
3 |
return jspName; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
static String getUnmangedSpecialChar(String mangled) { |
170 |
7 |
char ch = mangled.class="keyword">charAt(0); |
171 |
7 |
int hex0 = Character.digit(ch, 16); |
172 |
7 |
ch = mangled.charAt(1); |
173 |
7 |
int hex1 = Character.digit(ch, 16); |
174 |
7 |
ch = mangled.charAt(2); |
175 |
7 |
int hex2 = Character.digit(ch, 16); |
176 |
7 |
ch = mangled.charAt(3); |
177 |
7 |
int hex3 = Character.digit(ch, 16); |
178 |
7 |
int sum = (4096 * hex0) + (256 * hex1) + (16 * hex2) + hex3; |
179 |
|
|
180 |
7 |
return new String(class="keyword">new char[] {(char) sum}); |
181 |
|
} |
182 |
|
} |