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 java.util.Map;
25:
26: /**
27: * Matches a sitemap parameter against a wildcard expression.
28: *
29: * <p><b>Global and local configuration</b></p>
30: * <table border="1">
31: * <tr><td><code>parameter-name</code></td><td>Name of the sitemap parameter to
32: * match against</td></tr>
33: * </table>
34: *
35: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
36: * @version CVS $Id: WildcardParameterMatcher.java 433543 2006-08-22 06:22:54Z crossley $
37: */
38: public class WildcardParameterMatcher extends AbstractWildcardMatcher
39: implements Configurable {
40: private String defaultParam;
41:
42: public void configure(Configuration config)
43: throws ConfigurationException {
44: this .defaultParam = config.getChild("parameter-name").getValue(
45: null);
46: }
47:
48: protected String getMatchString(Map objectModel,
49: Parameters parameters) {
50:
51: String paramName = parameters.getParameter("parameter-name",
52: this .defaultParam);
53: if (paramName == null) {
54: getLogger().warn("No parameter name given. FAILING");
55: return null;
56: }
57:
58: String value = parameters.getParameter(paramName, null);
59: if (value == null) {
60: getLogger().debug("Parameter '" + paramName + "' not set.");
61: }
62:
63: return value;
64: }
65: }
|