Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package freemarker.ext.jsp;
 
 import java.io.Writer;
 import java.util.Map;
 
 import  javax.servlet.jsp.JspContext;
 import  javax.servlet.jsp.JspException;
import  javax.servlet.jsp.tagext.JspFragment;
import  javax.servlet.jsp.tagext.JspTag;
import  javax.servlet.jsp.tagext.SimpleTag;
import  javax.servlet.jsp.tagext.Tag;

Author(s):
Attila Szegedi
Version:
$Id: $
    protected SimpleTagDirectiveModel(Class tagClassthrows IntrospectionException {
        super(tagClass);
        if(!SimpleTag.class.isAssignableFrom(tagClass)) {
            throw new IllegalArgumentException(tagClass.getName() + 
                    " does not implement either the " + Tag.class.getName() + 
                    " interface or the " + SimpleTag.class.getName() + 
                    " interface.");
        }
    }
    public void execute(Environment envMap argsTemplateModel[] outArgs
            final TemplateDirectiveBody body
    throws TemplateExceptionIOException {
        try {
            SimpleTag tag = (SimpleTag)getTagInstance();
            final FreeMarkerPageContext pageContext = PageContextFactory.getCurrentPageContext();
            pageContext.pushWriter(new JspWriterAdapter(env.getOut()));
            try {
                tag.setJspContext(pageContext);
                JspTag parentTag = (JspTag)pageContext.peekTopTag(JspTag.class);
                if(parentTag != null) {
                    tag.setParent(parentTag);
                }
                setupTag(tagargspageContext.getObjectWrapper());
                if(body != null) {
                    tag.setJspBody(new JspFragment() {
                        public JspContext getJspContext() {
                            return pageContext;
                        }
                        
                        public void invoke(Writer outthrows JspException, IOException {
                            try {
                                body.render(out == null ? pageContext.getOut() : out);
                            }
                            catch(TemplateException e) {
                                throw new JspException(e);
                            }
                        }
                    });
                    pageContext.pushTopTag(tag);
                    try {
                        tag.doTag();
                    }
                    finally {
                        pageContext.popTopTag();
                    }
                }
                else {
                    tag.doTag();
                }
            }
            finally {
                pageContext.popWriter();
            }
        }
        catch(TemplateException e) {
            throw e;
        }
        catch(RuntimeException e) {
            throw e;
        }
        catch(Exception e) {
            throw new TemplateModelException(e);
        }
    }
New to GrepCode? Check out our FAQ X