1 16 package org.apache.cocoon.matching; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 import org.apache.avalon.framework.thread.ThreadSafe; 20 import org.apache.cocoon.matching.helpers.WildcardHelper; 21 import org.apache.cocoon.sitemap.PatternException; 22 import org.apache.cocoon.sitemap.SitemapParameters; 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 33 34 public abstract class AbstractWildcardMatcher extends AbstractPreparableMatcher implements ThreadSafe { 35 36 39 public Object preparePattern(String pattern) { 40 return pattern == null ? null : WildcardHelper.compilePattern(pattern); 42 } 43 44 47 public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) throws PatternException { 48 49 if(preparedPattern == null) { 50 throw new PatternException("A pattern is needed at " + 51 SitemapParameters.getStatementLocation(parameters)); 52 } 53 54 String match = getMatchString(objectModel, parameters); 55 56 if (match == null) { 57 return null; 58 } 59 60 HashMap map = new HashMap (); 61 62 if (WildcardHelper.match(map, match, (int[])preparedPattern)) { 63 return map; 64 } else { 65 return null; 66 } 67 } 68 69 73 protected abstract String getMatchString(Map objectModel, Parameters parameters); 74 } 75 | Popular Tags |