public static void populate(HttpServletRequest request, HttpServletResponse response, ActionForm form, boolean requestHasPopulated)
throws ServletException
{
String key = null;
Map strutsProperties = null;
ExpressionEvaluator ee = ExpressionEvaluatorFactory.getInstance();
// a boolean so that we can avoid an instanceof below...
boolean isMultipart = false;
// if this returns null, it's not a mulitpart request
Map params = MultipartRequestUtils.handleMultipartRequest(request, form);
// make adjustments
if(params != null)
isMultipart = true;
else params = request.getParameterMap();
if(params == null)
{
if(_logger.isWarnEnabled()) _logger.warn("An error occurred checking a request for multipart status. No model values were updated.");
return;
}
/* explicitly build a variable resolver that is used to provide objects that may be updated to the expression engine */
VariableResolver variableResolver = ImplicitObjectUtil.getUpdateVariableResolver(form, request, response, true);
/* todo: are there any ordering issues with using an Iterator vs. an Enumeration here? */
Iterator iterator = params.keySet().iterator();
while (iterator.hasNext())
{
key = (String) iterator.next();
String expr = null;
// if there is an expression map, lookup the real expression from the name
expr = key;
if (_logger.isDebugEnabled())
_logger.debug("key: " + key + " value type: " + params.get(key).getClass().getName() + " value: " + params.get(key));
try
{
Object paramsValue = params.get(key);
if (ee.containsExpression(expr))
{
Object updateValue = null;
if (!isMultipart || paramsValue instanceof String[])
{
String[] values = (String[]) paramsValue;
// the only "contains" case that is accepted
if (expr.startsWith(WLW_TAG_HANDLER_PREFIX))
{
if (_logger.isDebugEnabled()) _logger.debug("Found an expression requiring a TAG HANDLER");
ExpressionUpdateNode node = doTagHandler(key, expr, values, request);
expr = node.expression;
values = node.values;
}
if (values != null && values.length == 1)
updateValue = values[0];
else
updateValue = values;
}
// handle funky types that Struts returns for a file upload request handler
else
{
updateValue = params.get(key);
}
try
{
// trap any bad expressions here
if (ee.isExpression(expr))
{
// common case, make this fast
if (!requestHasPopulated)
ee.update(expr, updateValue, variableResolver, true);
// must check the expression to make sure pageFlow. and globalApp. don't get executed more than once
else
{
Expression pe = ee.parseExpression(expr);
String contextName = pe.getContext();
if (!contextName.equals(PAGE_FLOW_CONTEXT) && !contextName.equals(GLOBAL_APP_CONTEXT))
ee.update(expr, updateValue, variableResolver, true);
}
}
}
// catch any errors, particularly expression parse failures
catch (ExpressionUpdateException e)