01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.profiler.rules.impl;
18:
19: import org.apache.jetspeed.profiler.rules.RuleCriterion;
20: import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
21: import org.apache.jetspeed.request.RequestContext;
22:
23: /**
24: * IPCriterionResolver
25: *
26: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
27: * @author <a href="mailto:philip.donaghy@gmail.com">Philip Mark Donaghy</a>
28: * @version $Id: IPCriterionResolver.java 351839 2005-12-02 21:20:57Z taylor $
29: */
30: public class IPCriterionResolver extends StandardResolver implements
31: RuleCriterionResolver {
32:
33: /*
34: * (non-Javadoc)
35: *
36: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext,
37: * org.apache.jetspeed.profiler.rules.RuleCriterion)
38: */
39: public String resolve(RequestContext context,
40: RuleCriterion criterion) {
41: // look for override
42: String value = super .resolve(context, criterion);
43: if (value != null) {
44: return value.toLowerCase();
45: }
46:
47: // Note IP addresses can vary depending on the client
48: // Konqueror 3.4.2 returns IPv6 e.g. 0:0:0:0:0:0:0:1
49: // Firefox 1.0.7 returns IPv4 e.g. 127.0.0.1
50: // This is the value used to resolve pages in the _ip directory
51: // TODO create an option to convert all IPv4 addresses to IPv6
52: return context.getRequest().getRemoteAddr();
53: }
54:
55: /*
56: * (non-Javadoc)
57: *
58: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl()
59: */
60: public boolean isControl(RuleCriterion criterion) {
61: return true;
62: }
63:
64: }
|