/** * Matches namespace strings against a wildcard pattern matcher * * @Since 2.1 */ public class NamespaceMatcher extends AbstractMatcher<NamespaceMatch> { public NamespaceMatcher(PatternMatcher<?> patternMatcher, Set<String> namespaces) { super(patternMatcher); for (String name : namespaces) { if (!patternMatcher.isLiteral(name)) { addPattern(name, new NamespaceMatch(name, null), false); } } } @Override protected NamespaceMatch convert(String path, NamespaceMatch orig, Map<String, String> vars) { /*Map<String,String> origVars = (Map<String,String>)vars; Map<String,String> map = new HashMap<String,String>(); for (Map.Entry<String,String> entry : origVars.entrySet()) { if (entry.getKey().length() == 1) { map.put("ns"+entry.getKey(), entry.getValue()); } } */ return new NamespaceMatch(orig.getPattern(), vars); } }
/** * Gets the configuration information for an action name, or returns null if the * name is not recognized. * * @param name the name of the action * @param namespace the namespace for the action or null for the empty namespace, "" * @return the configuration information for action requested */ public ActionConfig getActionConfig(String namespace, String name) { ActionConfig config = findActionConfigInNamespace(namespace, name); // try wildcarded namespaces if (config == null) { NamespaceMatch match = namespaceMatcher.match(namespace); if (match != null) { config = findActionConfigInNamespace(match.getPattern(), name); // If config found, place all the matches found in the namespace processing in the action's parameters if (config != null) { config = new ActionConfig.Builder(config) .addParams(match.getVariables()) .build(); } } } // fail over to empty namespace if ((config == null) && (namespace != null) && (!"".equals(namespace.trim()))) { config = findActionConfigInNamespace("", name); } return config; }