public static void populate()

in ti/phase2/jars/core/src/java/org/apache/ti/pageflow/internal/ProcessPopulate.java [147:263]


    public static void populate(Object form, boolean requestHasPopulated) {
        String key = null;
        Map strutsProperties = null;
        ExpressionEvaluator ee = ExpressionEvaluatorFactory.getInstance();
        PageFlowActionContext actionContext = PageFlowActionContext.get();        

        // a boolean so that we can avoid an instanceof below...
        boolean isMultipart = false;

        // if this returns null, it's not a mulitpart request
        // TODO: re-add multipart request support
        //Map params = MultipartRequestUtils.handleMultipartRequest(request, form);
        Map params = null;

        // make adjustments
        if (params != null)
            isMultipart = true;
        else
            params = actionContext.getParameters();

        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, 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);

                            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. doesn't get executed more than once
                            else {
                                Expression pe = ee.parseExpression(expr);
                                String contextName = pe.getContext();
                                if (!contextName.equals(PAGE_FLOW_CONTEXT))
                                    ee.update(expr, updateValue, variableResolver, true);
                            }
                        }
                    }
                            // catch any errors, particularly expression parse failures
                    catch (ExpressionUpdateException e) {
                        String s = Bundle.getString("ExprUpdateError", new Object[]{expr, e});

                        // this is the hairy NetUI Warning that gets printed to the console
                        System.err.println(s);
                        if (_logger.isErrorEnabled()) _logger.error(s);

                        // add binding errors via PageFlowUtils
                        InternalUtils.addBindingUpdateError(expr, s, e);
                    }
                } else {
                    if (_logger.isDebugEnabled()) _logger.debug("HTTP request parameter key \"" + key + "\" is not an expression, handle with Struts");

                    if (strutsProperties == null)
                        strutsProperties = new HashMap();

                    strutsProperties.put(key, paramsValue);
                }
            }
                    // catch any unexpected exception
            catch (Exception e) {
                String s = Bundle.getString("ProcessPopulate_exprUpdateError", new Object[]{expr, e});
                //e.printStackTrace();

                System.err.println(s);

                if (_logger.isWarnEnabled()) _logger.warn(s, e);

                // add binding errors via PageFlowUtils
                InternalUtils.addBindingUpdateError(expr, s, e);
            }
        }

        //handleStrutsProperties(strutsProperties, form);
    }