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.PortalReservedParameters;
20: import org.apache.jetspeed.om.page.Page;
21: import org.apache.jetspeed.profiler.rules.RuleCriterion;
22: import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
23: import org.apache.jetspeed.request.RequestContext;
24:
25: /**
26: * PathSessionResolver
27: *
28: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
29: * @version $Id: PathSessionResolver.java 516448 2007-03-09 16:25:47Z ate $
30: */
31: public class PathSessionResolver implements RuleCriterionResolver {
32: /* (non-Javadoc)
33: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.rules.RuleCriterion)
34: */
35: public String resolve(RequestContext context,
36: RuleCriterion criterion) {
37: String path = null;
38: Page page = context.getPage();
39:
40: if (page != null) {
41: path = page.getId();
42: } else {
43: path = context.getPath();
44: if (path != null)
45: path = mapPath(context, path);
46: }
47:
48: if ((path == null) || path.equals("/")) {
49: String key = this .getClass() + "." + criterion.getName();
50: path = (String) context.getSessionAttribute(key);
51: if (path == null) {
52: path = criterion.getValue();
53: }
54: }
55: return path;
56: }
57:
58: private String mapPath(RequestContext context, String originalPath) {
59: String path = originalPath;
60: if (path.endsWith(".psml")) {
61: return originalPath;
62: }
63: for (int ix = 0; ix < REGEX_MAP.length; ix++) {
64: if (path.matches(REGEX_MAP[ix][0])) {
65: path = REGEX_MAP[ix][1];
66: context.setPath(path);
67: context.setAttribute(
68: PortalReservedParameters.PATH_ATTRIBUTE,
69: originalPath);
70: break;
71: }
72: }
73: return path;
74: }
75:
76: // TODO: configure this information externally and live
77: static String[][] REGEX_MAP = { { ".*\\.(...|....)",
78: "/Public/content.psml" }
79: // {".*\\.html", "/Public/content.psml"},
80: // {".*\\.pdf", "/Public/content.psml"},
81: // {"/_content.*", "/Public/content.psml"}
82: // {"/data/*", "/Public/content2.psml"},
83: };
84:
85: /* (non-Javadoc)
86: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl()
87: */
88: public boolean isControl(RuleCriterion criterion) {
89: return false;
90: }
91:
92: public boolean isNavigation(RuleCriterion criterion) {
93: return false;
94: }
95:
96: }
|