On Mon, 2002-10-14 at 17:19, Bobby Mitchell wrote:
> I want to be able to match cocoon-action-* and use the value {1}. Is 
> this possible? Which matcher?
> 

Someone else just asked me this last week, so I wrote one (see
attachment). It's tested with C2.03. You'll need to compile this and put
it an jar and put that in WEB-INF/lib (let me know if you need more help
on this).

It is of course possible that there are multiple request parameter names
that match, but this matcher will take the first one that it encounters.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
[EMAIL PROTECTED]
import org.apache.cocoon.matching.AbstractPreparableMatcher;
import org.apache.cocoon.matching.helpers.WildcardHelper;
import org.apache.cocoon.sitemap.PatternException;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.avalon.framework.parameters.Parameters;

import java.util.Map;
import java.util.Enumeration;
import java.util.HashMap;

/**
 * Matcher that matches on the names of request parameters. The first parameter which
 * matches is used.
 */
public class RequestParameterNameMatcher extends AbstractPreparableMatcher implements ThreadSafe
{
    public Object preparePattern(String pattern) throws PatternException
    {
        return WildcardHelper.compilePattern(pattern);
    }

    public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters)
    {
        int[] pattern = (int[])preparedPattern;
        Request request = ObjectModelHelper.getRequest(objectModel);
        Enumeration parameterNamesEnum = request.getParameterNames();

        HashMap map = new HashMap();

        while (parameterNamesEnum.hasMoreElements())
        {
            String name = (String)parameterNamesEnum.nextElement();
            if (WildcardHelper.match(map, name, pattern))
                return map;
        }
        return null;
    }
}

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to