// PENDING: this code is optimized to be fast to write.
// It must be optimized to be fast to run.
// See git clone ssh://edburns@git.java.net/grizzly~git 1_9_36 for
// how grizzly does this.
ViewHandler viewHandler = context.getApplication().getViewHandler();
Set<String> urlPatterns = viewHandler.getProtectedViewsUnmodifiable();
// Implement section 12.1 of the Servlet spec.
boolean viewIdIsProtected = false;
for (String cur : urlPatterns) {
if (cur.equals(viewId)) {
viewIdIsProtected = true;
}
if (viewIdIsProtected) {
break;
}
}
if (viewIdIsProtected) {
StringBuilder builder = new StringBuilder(result);
// If the result already has a query string...
if (result.contains("?")) {
// ...assume it also has one or more parameters, and
// append an additional parameter.
builder.append("&");
} else {
// Otherwise, this is the first parameter in the result.
builder.append("?");
}
String rkId = viewHandler.calculateRenderKitId(context);
ResponseStateManager rsm = RenderKitUtils.getResponseStateManager(context, rkId);
String tokenValue = rsm.getCryptographicallyStrongTokenFromSession(context);
builder.append(ResponseStateManager.NON_POSTBACK_VIEW_TOKEN_PARAM).
append("=").append(tokenValue);
result = builder.toString();