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 DomainCriterionResolver extends StandardResolver implements
30: RuleCriterionResolver {
31:
32: /*
33: * (non-Javadoc)
34: *
35: * @see org.apache.jetspeed.profiler.rules.impl.StandardResolver#isControl(org.apache.jetspeed.profiler.rules.RuleCriterion)
36: */
37: public boolean isControl(RuleCriterion criterion) {
38: return false;
39: }
40:
41: /*
42: * (non-Javadoc)
43: *
44: * @see org.apache.jetspeed.profiler.rules.impl.StandardResolver#isNavigation(org.apache.jetspeed.profiler.rules.RuleCriterion)
45: */
46: public boolean isNavigation(RuleCriterion criterion) {
47: return true;
48: }
49:
50: public String resolve(RequestContext context,
51: RuleCriterion criterion) {
52: return getDomain(context.getRequest().getServerName());
53: }
54:
55: /**
56: * extracts the domain from the servername from RequestContext
57: *
58: * @param servername
59: * server name from request
60: * @return domain extracted from server name
61: */
62: public static String getDomain(String servername) {
63: String domain = null;
64:
65: if (servername != null) {
66: int idx = servername.indexOf(".");
67: if (idx != -1) {
68: domain = servername.substring(idx + 1, servername
69: .length());
70: } else {
71: // maybe there is no domain
72: // testing for IPv6 IP Address
73: idx = servername.indexOf(":");
74: if (idx != -1) {
75: // TODO resolving IP Address?
76: // no domain is available
77: domain = "";
78: } else {
79: // no domain is available
80: domain = "";
81: }
82: }
83: }
84: return domain;
85: }
86:
87: }
|