1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.profiler.impl; |
18 |
|
|
19 |
|
import java.util.Iterator; |
20 |
|
import java.util.LinkedList; |
21 |
|
import java.util.List; |
22 |
|
import java.util.ListIterator; |
23 |
|
import java.util.StringTokenizer; |
24 |
|
|
25 |
|
import org.apache.jetspeed.profiler.ProfileLocator; |
26 |
|
import org.apache.jetspeed.profiler.ProfileLocatorProperty; |
27 |
|
import org.apache.jetspeed.profiler.Profiler; |
28 |
|
import org.apache.jetspeed.profiler.rules.RuleCriterion; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
0 |
public class JetspeedProfileLocator implements ProfileLocatorControl |
37 |
|
{ |
38 |
0 |
private LinkedList elements = new LinkedList(); |
39 |
|
private String requestPath; |
40 |
|
|
41 |
|
public List getElements() |
42 |
|
{ |
43 |
0 |
return elements; |
44 |
|
} |
45 |
|
|
46 |
|
public void init(Profiler profiler, String requestPath) |
47 |
|
{ |
48 |
0 |
if (requestPath != null) |
49 |
0 |
if (requestPath.indexOf("/") != -1) |
50 |
0 |
this.requestPath = requestPath; |
51 |
|
else |
52 |
0 |
this.requestPath = "/" + requestPath; |
53 |
|
else |
54 |
0 |
this.requestPath = "/"; |
55 |
0 |
} |
56 |
|
|
57 |
|
public Iterator iterator() |
58 |
|
{ |
59 |
0 |
return new ProfileFallbackIterator(this); |
60 |
|
} |
61 |
|
|
62 |
|
public String getValue(String name) |
63 |
|
{ |
64 |
0 |
Iterator iter = elements.iterator(); |
65 |
0 |
while (iter.hasNext()) |
66 |
|
{ |
67 |
0 |
ProfileLocatorPropertyImpl element = (ProfileLocatorPropertyImpl)iter.next(); |
68 |
0 |
String elementName = element.getName(); |
69 |
0 |
if (elementName != null && elementName.equals(name)) |
70 |
|
{ |
71 |
0 |
return element.getValue(); |
72 |
|
} |
73 |
0 |
} |
74 |
0 |
return null; |
75 |
|
} |
76 |
|
|
77 |
|
public boolean isControl(String name) |
78 |
|
{ |
79 |
0 |
Iterator iter = elements.iterator(); |
80 |
0 |
while (iter.hasNext()) |
81 |
|
{ |
82 |
0 |
ProfileLocatorPropertyImpl element = (ProfileLocatorPropertyImpl)iter.next(); |
83 |
0 |
String elementName = element.getName(); |
84 |
0 |
if (elementName != null && elementName.equals(name)) |
85 |
|
{ |
86 |
0 |
return element.isControl(); |
87 |
|
} |
88 |
0 |
} |
89 |
0 |
return false; |
90 |
|
} |
91 |
|
|
92 |
|
public boolean isNavigation(String name) |
93 |
|
{ |
94 |
0 |
Iterator iter = elements.iterator(); |
95 |
0 |
while (iter.hasNext()) |
96 |
|
{ |
97 |
0 |
ProfileLocatorPropertyImpl element = (ProfileLocatorPropertyImpl)iter.next(); |
98 |
0 |
String elementName = element.getName(); |
99 |
0 |
if (elementName != null && elementName.equals(name)) |
100 |
|
{ |
101 |
0 |
return element.isNavigation(); |
102 |
|
} |
103 |
0 |
} |
104 |
0 |
return false; |
105 |
|
} |
106 |
|
|
107 |
|
public void add(RuleCriterion criterion, boolean isControl, class="keyword">boolean isNavigation, String value) |
108 |
|
{ |
109 |
0 |
elements.add(new ProfileLocatorPropertyImpl(criterion, isControl, isNavigation, value)); |
110 |
0 |
} |
111 |
|
|
112 |
|
public void add(String name, boolean isControl, class="keyword">boolean isNavigation, String value) |
113 |
|
{ |
114 |
0 |
elements.add(new ProfileLocatorPropertyImpl(name, isControl, isNavigation, value)); |
115 |
0 |
} |
116 |
|
|
117 |
|
public void add(String name, String value) |
118 |
|
{ |
119 |
0 |
add(name, true, false, value); |
120 |
0 |
} |
121 |
|
|
122 |
|
public void createFromLocatorPath(String path) |
123 |
|
{ |
124 |
0 |
elements.clear(); |
125 |
0 |
StringTokenizer tokenizer = new StringTokenizer(path, ProfileLocator.PATH_SEPARATOR); |
126 |
0 |
while (tokenizer.hasMoreTokens()) |
127 |
|
{ |
128 |
0 |
String name = tokenizer.nextToken(); |
129 |
0 |
if (tokenizer.hasMoreTokens()) |
130 |
|
{ |
131 |
0 |
String value = tokenizer.nextToken(); |
132 |
0 |
this.add(name, true, false, value); |
133 |
|
} |
134 |
0 |
} |
135 |
0 |
} |
136 |
|
|
137 |
|
public String getLocatorPath() |
138 |
|
{ |
139 |
0 |
StringBuffer key = new StringBuffer(); |
140 |
0 |
ListIterator it = elements.listIterator(); |
141 |
0 |
while (it.hasNext()) |
142 |
|
{ |
143 |
0 |
ProfileLocatorPropertyImpl element = (ProfileLocatorPropertyImpl)it.next(); |
144 |
0 |
key.append(element.getName()); |
145 |
0 |
key.append(ProfileLocator.PATH_SEPARATOR); |
146 |
0 |
key.append(element.getValue()); |
147 |
0 |
if (it.hasNext()) |
148 |
|
{ |
149 |
0 |
key.append(ProfileLocator.PATH_SEPARATOR); |
150 |
|
} |
151 |
0 |
} |
152 |
0 |
return key.toString(); |
153 |
|
} |
154 |
|
|
155 |
|
public String getLocatorPath(ProfileLocatorProperty [] properties) |
156 |
|
{ |
157 |
0 |
StringBuffer key = new StringBuffer(); |
158 |
0 |
if (properties != null) |
159 |
0 |
for (int i = 0; (i < properties.length); i++) |
160 |
|
{ |
161 |
0 |
if (i > 0) |
162 |
0 |
key.append(ProfileLocator.PATH_SEPARATOR); |
163 |
0 |
key.append(properties[i].getName()); |
164 |
0 |
key.append(ProfileLocator.PATH_SEPARATOR); |
165 |
0 |
key.append(properties[i].getValue()); |
166 |
|
} |
167 |
0 |
return key.toString(); |
168 |
|
} |
169 |
|
|
170 |
|
public String toString() |
171 |
|
{ |
172 |
0 |
return getRequestPath() + ProfileLocator.PATH_SEPARATOR + getLocatorPath(); |
173 |
|
} |
174 |
|
|
175 |
|
public String getRequestPath() |
176 |
|
{ |
177 |
0 |
return requestPath; |
178 |
|
} |
179 |
|
} |