FileDocCategorySizeDatePackage
TagModel.javaAPI DocExample5670Mon Jul 23 13:26:42 BST 2007org.apache.struts2.views.freemarker.tags

TagModel

public abstract class TagModel extends Object implements freemarker.template.TemplateTransformModel

Fields Summary
private static final Log
LOG
protected com.opensymphony.xwork2.util.ValueStack
stack
protected HttpServletRequest
req
protected HttpServletResponse
res
Constructors Summary
public TagModel(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest req, HttpServletResponse res)


           
        this.stack = stack;
        this.req = req;
        this.res = res;
    
Methods Summary
protected booleancomplexType(java.lang.Object value)

        return value instanceof freemarker.ext.beans.BeanModel
                || value instanceof SimpleNumber
                || value instanceof SimpleSequence;
    
protected java.util.MapconvertParams(java.util.Map params)

        HashMap map = new HashMap(params.size());
        for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object value = entry.getValue();
            if (value != null && !complexType(value)) {
                map.put(entry.getKey(), value.toString());
            }
        }
        return map;
    
protected abstract org.apache.struts2.components.ComponentgetBean()

protected java.util.MapgetComplexParams(java.util.Map params)

        HashMap map = new HashMap(params.size());
        for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object value = entry.getValue();
            if (value != null && complexType(value)) {
                if (value instanceof freemarker.ext.beans.BeanModel) {
                    map.put(entry.getKey(), ((freemarker.ext.beans.BeanModel) value).getWrappedObject());
                } else if (value instanceof SimpleNumber) {
                    map.put(entry.getKey(), ((SimpleNumber) value).getAsNumber());
                } else if (value instanceof SimpleSequence) {
                    try {
                        map.put(entry.getKey(), ((SimpleSequence) value).toList());
                    } catch (TemplateModelException e) {
                        LOG.error("There was a problem converting a SimpleSequence to a list", e);
                    }
                }
            }
        }
        return map;
    
public java.io.WritergetWriter(java.io.Writer writer, java.util.Map params)

        Component bean = getBean();
        Container container = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getContainer();
        container.inject(bean);

        Map unwrappedParameters = unwrapParameters(params);
        bean.copyParams(unwrappedParameters);

        return new CallbackWriter(bean, writer);
    
protected java.util.MapunwrapParameters(java.util.Map params)

        Map map = new HashMap(params.size());
        DefaultObjectWrapper objectWrapper = new DefaultObjectWrapper();
        for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();

            Object value = entry.getValue();

            if (value != null) {
                // the value should ALWAYS be a decendant of TemplateModel
                if (value instanceof TemplateModel) {
                    try {
                        map.put(entry.getKey(), objectWrapper
                            .unwrap((TemplateModel) value));
                    } catch (TemplateModelException e) {
                        LOG.error("failed to unwrap [" + value
                            + "] it will be ignored", e);
                    }
                }
                // if it doesn't, we'll do it the old way by just returning the toString() representation
                else {
                    map.put(entry.getKey(), value.toString());
                }
            }
        }
        return map;