FileDocCategorySizeDatePackage
ResourceTag.javaAPI DocGlassfish v2 API5447Sat May 05 19:17:12 BST 2007org.apache.taglibs.standard.examples.taglib

ResourceTag

public class ResourceTag extends javax.servlet.jsp.tagext.TagSupport

Tag handler for <resource>

author
Pierre Delisle
version
$Revision: 1.3 $ $Date: 2007/05/06 02:17:12 $

Fields Summary
private String
id
private String
resource
private Reader
reader
Constructors Summary
public ResourceTag()

        super();
        init();
    
Methods Summary
public intdoEndTag()

        try {
            reader.close();
        } catch (IOException ex) {}
        reader = null;
        return EVAL_PAGE;
    
public intdoStartTag()

        reader = getReaderFromResource(resource);
        exposeVariable(reader);
        return EVAL_BODY_INCLUDE;
    
private voidexposeVariable(java.io.Reader reader)

        if (id != null) {
            pageContext.setAttribute(id, reader);
        }
    
private java.io.ReadergetReaderFromResource(java.lang.String name)

        HttpServletRequest request =
        (HttpServletRequest)pageContext.getRequest();
        HttpServletResponse response =
        (HttpServletResponse)pageContext.getResponse();
        RequestDispatcher rd = null;
        
        // The response of the local URL becomes the reader that
        // we export. Need temporary storage.
        IOBean ioBean = new IOBean();
        Writer writer = ioBean.getWriter();
        ServletResponseWrapper responseWrapper =
        new ServletResponseWrapperForWriter(
        response, new PrintWriter(writer));
        rd = pageContext.getServletContext().getRequestDispatcher(name);
        try {
            rd.include(request, responseWrapper);
            return ioBean.getReader();
        } catch (Exception ex) {
            throw new JspException(ex);
        }
    
private voidinit()

        id = null;
        resource = null;
    
public voidrelease()
Releases any resources we may have (or inherit)

        super.release();
        init();
    
public voidsetId(java.lang.String id)
Tag's 'id' attribute

        this.id = id;
    
public voidsetResource(java.lang.String resource)
Tag's 'resource' attribute

        this.resource = resource;