1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.profiler.rules.impl;
18
19 import java.util.Iterator;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.jetspeed.profiler.ProfileLocator;
24 import org.apache.jetspeed.profiler.Profiler;
25 import org.apache.jetspeed.profiler.rules.ProfileResolvers;
26 import org.apache.jetspeed.profiler.rules.ProfilingRule;
27 import org.apache.jetspeed.profiler.rules.RuleCriterion;
28 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
29 import org.apache.jetspeed.request.RequestContext;
30
31 /***
32 * StandardProfilingRule applies the standard Jetspeed-1 profiling rules.
33 * The result is an ordered list of Profile Locator name/value pairs.
34 *
35 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
36 * @version $Id: StandardProfilingRule.java 516448 2007-03-09 16:25:47Z ate $
37 */
38 public class StandardProfilingRule
39 extends AbstractProfilingRule
40 implements ProfilingRule
41 {
42 protected final static Log log = LogFactory.getLog(StandardProfilingRule.class);
43 private static final long serialVersionUID = 1;
44
45 public StandardProfilingRule()
46 {
47 this.setClassname(this.getClass().getName());
48 }
49
50 public StandardProfilingRule(ProfileResolvers resolvers)
51 {
52 super(resolvers);
53 this.setClassname(this.getClass().getName());
54 }
55
56
57
58
59 public ProfileLocator apply(RequestContext context, Profiler service)
60 {
61 StringBuffer key = new StringBuffer();
62 int count = 0;
63
64
65 Iterator criteria = this.getRuleCriteria().iterator();
66 while (criteria.hasNext())
67 {
68 RuleCriterion criterion = (RuleCriterion)criteria.next();
69 if (criterion.getType() == null)
70 {
71 log.warn("Invalid criterion provided - type null on rule " + this);
72 }
73 RuleCriterionResolver resolver = getResolver(criterion.getType());
74 if (resolver == null)
75 {
76 resolver = getDefaultResolver();
77 }
78 String value = resolver.resolve(context, criterion);
79 key.append(criterion.getName());
80 key.append(ProfileLocator.PATH_SEPARATOR);
81 key.append(value);
82 if (criteria.hasNext())
83 {
84 key.append(ProfileLocator.PATH_SEPARATOR);
85 }
86 count++;
87 }
88
89
90
91 String requestPath = context.getPath();
92 String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString();
93 ProfileLocator locator = getLocatorFromCache(locatorKey);
94 if (locator != null)
95 {
96 return locator;
97 }
98
99
100 locator = service.createLocator(context);
101 criteria = this.getRuleCriteria().iterator();
102 while (criteria.hasNext())
103 {
104 RuleCriterion criterion = (RuleCriterion)criteria.next();
105 if (criterion.getType() == null)
106 {
107 log.warn("Invalid criterion provided - type null on rule " + this);
108 }
109 RuleCriterionResolver resolver = getResolver(criterion.getType());
110 if (resolver != null)
111 {
112 String value = resolver.resolve(context, criterion);
113 boolean isControl = resolver.isControl(criterion);
114 boolean isNavigation = resolver.isNavigation(criterion);
115 locator.add(criterion, isControl, isNavigation, value);
116 }
117 }
118
119 addLocatorToCache(locatorKey, locator);
120 return locator;
121 }
122
123 }
124
125