package com.google.sitebricks.routing;

import com.google.sitebricks.ActionDescriptor;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * An Action that is configured using the at().perform() scheme. See
 * {@link com.google.sitebricks.SitebricksModule} for details.
 *
 * @author dhanji@gmail.com (Dhanji R. Prasanna)
 */
public class SpiAction implements Action {
  private final Action action;
  private final Map<String, String> selectParams;
  private final Map<String,String> selectHeaders;

  public SpiAction(Action action, ActionDescriptor actionDescriptor) {
    this.action = action;
    selectParams = actionDescriptor.getSelectParams();
    selectHeaders = actionDescriptor.getSelectHeaders();
  }

  @Override
  public boolean shouldCall(HttpServletRequest request) {
    boolean should = true;
    if (null != selectParams) {
      for (Map.Entry<String, String> select : selectParams.entrySet()) {
        if (!select.getValue().equals(request.getParameter(select.getKey()))) {
          should = false;
        }
      }
    }

    if (null != selectHeaders) {
      for (Map.Entry<String, String> header : selectHeaders.entrySet()) {
        if (!header.getValue().equals(request.getHeader(header.getKey()))) {
          should = false;
        }
      }
    }
    return should;
  }

  @Override
  public Object call(Object page, Map<String, String> map) {
    return action.call(page, map);
  }
}

@@ -823,16 +823,10 @@
 ould
- = true
 ;
+%0A
 %0A   
@@ -1288,24 +1288,260 @@
     %7D%0A    %7D%0A
+%0A    // (JFA) Might be a good idea to pass the value of should as a request attribute%0A    // so an action can see if what was the value before getting invoked and take a decision based on it.%0A    should = action.shouldCall(request);  %0A%0A
     return s

Make sure the Action.shouldCall is always invoked and be override the previous value. This is quite useful for implementing customizable content negotiation.