1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.support; |
35 |
|
|
36 |
|
import java.util.Enumeration; |
37 |
|
import java.util.NoSuchElementException; |
38 |
|
|
39 |
|
import javax.servlet.http.HttpServletRequest; |
40 |
|
import javax.servlet.http.HttpServletRequestWrapper; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@since |
46 |
|
|
|
|
| 95.7% |
Uncovered Elements: 4 (94) |
Complexity: 30 |
Complexity Density: 0.61 |
|
47 |
|
public class SpecialAttributeRequestWrapper extends HttpServletRequestWrapper { |
48 |
|
|
49 |
|
private String commonPrefix; |
50 |
|
private String[] names; |
51 |
|
private Object[] values; |
52 |
|
private boolean enabled = true; |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
30 |
public SpecialAttributeRequestWrapper(HttpServletRequest request) {... |
55 |
30 |
super(request); |
56 |
|
} |
57 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
58 |
|
public boolean isEnabled() {... |
59 |
|
return enabled; |
60 |
|
} |
61 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
62 |
|
public void setEnabled(boolean enabled) {... |
63 |
|
this.enabled = enabled; |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
66 |
27 |
protected void setOverriddenAttributes(String commonPrefix, String[] names, Object[] values) {... |
67 |
27 |
this.commonPrefix = commonPrefix; |
68 |
27 |
this.names = names; |
69 |
27 |
this.values = values; |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 5 |
Complexity Density: 1 |
|
72 |
55 |
@Override... |
73 |
|
public Object getAttribute(String name) { |
74 |
55 |
if (enabled && name.startsWith(commonPrefix)) { |
75 |
94 |
for (int i = 0; i < names.length; i++) { |
76 |
92 |
if (names[i].equals(name)) { |
77 |
36 |
return values[i]; |
78 |
|
} |
79 |
|
} |
80 |
|
} |
81 |
19 |
return super.getAttribute(name); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
84 |
9 |
public Enumeration getAttributeNames() {... |
85 |
|
|
86 |
9 |
if (!enabled) { |
87 |
1 |
return super.getAttributeNames(); |
88 |
|
} |
89 |
|
|
90 |
8 |
return new Enumeration() { |
91 |
|
|
92 |
|
private int pos = 0; |
93 |
|
private String next = null; |
94 |
|
private Enumeration parentEnumeration = SpecialAttributeRequestWrapper.super.getAttributeNames(); |
95 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
96 |
8 |
@Override... |
97 |
|
public boolean hasMoreElements() { |
98 |
8 |
if (next != null) { |
99 |
0 |
return true; |
100 |
|
} |
101 |
9 |
while (pos < names.length) { |
102 |
4 |
if (values[pos] != null) { |
103 |
3 |
next = names[pos++]; |
104 |
3 |
return true; |
105 |
|
} |
106 |
1 |
pos++; |
107 |
|
} |
108 |
6 |
while (parentEnumeration.hasMoreElements()) { |
109 |
2 |
String name = (String) parentEnumeration.nextElement(); |
110 |
2 |
if (!isAttributeOverridden(name)) { |
111 |
1 |
next = name; |
112 |
1 |
return true; |
113 |
|
} |
114 |
|
} |
115 |
4 |
return false; |
116 |
|
} |
117 |
|
|
|
|
| 95.7% |
Uncovered Elements: 1 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
118 |
13 |
@Override... |
119 |
|
public String nextElement() { |
120 |
13 |
if (next != null) { |
121 |
4 |
String value = next; |
122 |
4 |
next = null; |
123 |
4 |
return value; |
124 |
|
} |
125 |
10 |
while (pos < names.length) { |
126 |
4 |
if (values[pos] != null) { |
127 |
3 |
return names[pos++]; |
128 |
|
} |
129 |
1 |
pos++; |
130 |
|
} |
131 |
6 |
while (parentEnumeration.hasMoreElements()) { |
132 |
3 |
String name = (String) parentEnumeration.nextElement(); |
133 |
3 |
if (!isAttributeOverridden(name)) { |
134 |
3 |
return name; |
135 |
|
} |
136 |
|
} |
137 |
3 |
throw new NoSuchElementException(); |
138 |
|
} |
139 |
|
}; |
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
142 |
2 |
@Override... |
143 |
|
public void setAttribute(String name, Object o) { |
144 |
2 |
if (enabled && isAttributeOverridden(name)) { |
145 |
1 |
return; |
146 |
|
} |
147 |
1 |
super.setAttribute(name, o); |
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
150 |
2 |
@Override... |
151 |
|
public void removeAttribute(String name) { |
152 |
2 |
if (enabled && isAttributeOverridden(name)) { |
153 |
1 |
return; |
154 |
|
} |
155 |
1 |
super.removeAttribute(name); |
156 |
|
} |
157 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
158 |
9 |
private boolean isAttributeOverridden(String name) {... |
159 |
9 |
if (name.startsWith(commonPrefix)) { |
160 |
9 |
for (String overriddenName : names) { |
161 |
4 |
if (name.equals(overriddenName)) { |
162 |
3 |
return true; |
163 |
|
} |
164 |
|
} |
165 |
|
} |
166 |
6 |
return false; |
167 |
|
} |
168 |
|
} |