{
Assert.notNull(query, "URL pattern must not be null.");
return new Query() {
private ParameterStore store;
final ParameterizedPatternParser pattern = new RegexParameterizedPatternParser(query);
@Override
public boolean evaluateHttp(final HttpServletRewrite event, final EvaluationContext context)
{
String queryString = null;
if (event instanceof InboundRewrite)
{
queryString = event.getInboundAddress().getQuery();
}
else if (event instanceof HttpOutboundServletRewrite)
{
queryString = ((HttpOutboundServletRewrite) event).getOutboundAddress().getQuery();
}
if (pattern.parse(queryString == null ? "" : queryString).submit(event, context))
{
ParameterValueStore values = (ParameterValueStore) context.get(ParameterValueStore.class);
for (Entry<Parameter<?>, String> entry : pattern.parse(query).getParameters(context).entrySet()) {
values.submit(event, context, store.get(entry.getKey().getName()), entry.getValue());
}
return true;
}
return false;
}
@Override
public String toString()
{
return "Query.matches(\"" + query + "\")";
}
@Override
public Set<String> getRequiredParameterNames()
{
return pattern.getRequiredParameterNames();
}
@Override
public void setParameterStore(ParameterStore store)
{
pattern.setParameterStore(store);
this.store = store;
}
};
}