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: * Hostname Resolver
25: *
26: * @author <a href="mailto:stalherm@goodgulf.net">Frank Stalherm</a>
27: * @version $Id:$
28: */
29: public class HostnameCriterionResolver extends StandardResolver
30: implements RuleCriterionResolver {
31: boolean useDotPrefix = false;
32:
33: public HostnameCriterionResolver(boolean usePrefix) {
34: super ();
35: this .useDotPrefix = usePrefix;
36: }
37:
38: /*
39: * (non-Javadoc)
40: *
41: * @see org.apache.jetspeed.profiler.rules.impl.StandardResolver#isControl(org.apache.jetspeed.profiler.rules.RuleCriterion)
42: */
43: public boolean isControl(RuleCriterion criterion) {
44: return true;
45: }
46:
47: /*
48: * (non-Javadoc)
49: *
50: * @see org.apache.jetspeed.profiler.rules.impl.StandardResolver#isNavigation(org.apache.jetspeed.profiler.rules.RuleCriterion)
51: */
52: public boolean isNavigation(RuleCriterion criterion) {
53: return false;
54: }
55:
56: public String resolve(RequestContext context,
57: RuleCriterion criterion) {
58: String serverName = context.getRequest().getServerName();
59: if (useDotPrefix) {
60: int idx = serverName.indexOf(".");
61: if (idx != -1) {
62: // SUFFIX: hostname = servername.substring(idx + 1, servername.length());
63: serverName = serverName.substring(0, idx);
64: }
65: }
66: return serverName;
67: }
68:
69: }
|