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.cocoon.matching;
18:
19: import org.apache.avalon.framework.configuration.Configurable;
20: import org.apache.avalon.framework.configuration.Configuration;
21: import org.apache.avalon.framework.configuration.ConfigurationException;
22: import org.apache.avalon.framework.parameters.Parameters;
23:
24: import org.apache.cocoon.environment.ObjectModelHelper;
25:
26: import java.util.Map;
27:
28: /**
29: * Matches a session attribute against a wildcard expression.
30: *
31: * <p><b>Global and local configuration</b></p>
32: * <tableborder="1">
33: * <tr><td><code>attribute-name</code></td><td>String identifying the session attribute</td></tr>
34: * </table>
35: *
36: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
37: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
38: * @version CVS $Id: WildcardSessionAttributeMatcher.java 433543 2006-08-22 06:22:54Z crossley $
39: */
40: public class WildcardSessionAttributeMatcher extends
41: AbstractWildcardMatcher implements Configurable {
42: private String defaultParam;
43:
44: public void configure(Configuration config)
45: throws ConfigurationException {
46: this .defaultParam = config.getChild("attribute-name").getValue(
47: null);
48: if (getLogger().isDebugEnabled()) {
49: getLogger().debug(
50: "Default attribute-name is = '" + this .defaultParam
51: + "'");
52: }
53: }
54:
55: protected String getMatchString(Map objectModel,
56: Parameters parameters) {
57:
58: String paramName = parameters.getParameter("attribute-name",
59: this .defaultParam);
60: if (paramName == null) {
61: getLogger().warn("No attribute name given. FAILING");
62: return null;
63: }
64:
65: Object result = ObjectModelHelper.getRequest(objectModel)
66: .getSession().getAttribute(paramName);
67: if (result == null) {
68: getLogger().debug(
69: "Session attribute '" + paramName + "' not set.");
70: return null;
71: }
72:
73: return result.toString();
74: }
75: }
|