%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.profiler.rules.impl.PathSessionResolver |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * 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 | 0 | public class PathSessionResolver implements RuleCriterionResolver |
32 | { |
|
33 | /* (non-Javadoc) |
|
34 | * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.rules.RuleCriterion) |
|
35 | */ |
|
36 | public String resolve(RequestContext context, RuleCriterion criterion) |
|
37 | { |
|
38 | 0 | String path = null; |
39 | 0 | Page page = context.getPage(); |
40 | ||
41 | 0 | if (page != null) |
42 | { |
|
43 | 0 | path = page.getId(); |
44 | } |
|
45 | else |
|
46 | { |
|
47 | 0 | path = context.getPath(); |
48 | 0 | if (path != null) |
49 | 0 | path = mapPath(context, path); |
50 | } |
|
51 | ||
52 | 0 | if ((path == null) || path.equals("/")) |
53 | { |
|
54 | 0 | String key = this.getClass() + "." + criterion.getName(); |
55 | 0 | path = (String)context.getSessionAttribute(key); |
56 | 0 | if (path == null) |
57 | { |
|
58 | 0 | path = criterion.getValue(); |
59 | } |
|
60 | } |
|
61 | 0 | return path; |
62 | } |
|
63 | ||
64 | private String mapPath(RequestContext context, String originalPath) |
|
65 | { |
|
66 | 0 | String path = originalPath; |
67 | 0 | if (path.endsWith(".psml")) |
68 | { |
|
69 | 0 | return originalPath; |
70 | } |
|
71 | 0 | for (int ix=0; ix < REGEX_MAP.length; ix++) |
72 | { |
|
73 | 0 | if (path.matches(REGEX_MAP[ix][0])) |
74 | { |
|
75 | 0 | path = REGEX_MAP[ix][1]; |
76 | 0 | context.setPath(path); |
77 | 0 | context.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE, originalPath); |
78 | 0 | break; |
79 | } |
|
80 | } |
|
81 | 0 | return path; |
82 | } |
|
83 | ||
84 | // TODO: configure this information externally and live |
|
85 | 0 | static String[][] REGEX_MAP = |
86 | { |
|
87 | {".*\\.(...|....)", "/Public/content.psml"} |
|
88 | // {".*\\.html", "/Public/content.psml"}, |
|
89 | // {".*\\.pdf", "/Public/content.psml"}, |
|
90 | // {"/_content.*", "/Public/content.psml"} |
|
91 | // {"/data/*", "/Public/content2.psml"}, |
|
92 | }; |
|
93 | ||
94 | ||
95 | /* (non-Javadoc) |
|
96 | * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl() |
|
97 | */ |
|
98 | public boolean isControl(RuleCriterion criterion) |
|
99 | { |
|
100 | 0 | return false; |
101 | } |
|
102 | ||
103 | public boolean isNavigation(RuleCriterion criterion) |
|
104 | { |
|
105 | 0 | return false; |
106 | } |
|
107 | ||
108 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |