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

EscapeHtmlTag

public class EscapeHtmlTag extends javax.servlet.jsp.tagext.BodyTagSupport

Tag handler for <escapeHtml>

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

Fields Summary
private Object
reader
private Object
writer
Constructors Summary
public EscapeHtmlTag()

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

        Reader in;
        Writer out;
        
        if (reader == null) {
            String bcs = getBodyContent().getString().trim();
            if (bcs == null || bcs.equals("")) {
                throw new JspTagException("In <escapeHtml>, 'reader' " +
                "not specified and no non-whitespace content inside the tag.");
            }
            in = Util.castToReader(bcs);
        } else {
            in = Util.castToReader(reader);
        }
        
        if (writer == null) {
            out = pageContext.getOut();
        } else {
            out = Util.castToWriter(writer);
        }
        
        transform(in, out);
        return EVAL_PAGE;
    
private voidinit()

        reader = null;
        writer = null;
    
public voidrelease()
Releases any resources we may have (or inherit)

        super.release();
        init();
    
public voidsetReader(java.lang.Object reader)
Tag's 'reader' attribute

        this.reader = reader;
    
public voidsetWriter(java.lang.Object writer)
Tag's 'writer' attribute

        this.writer = writer;
    
public voidtransform(java.io.Reader reader, java.io.Writer writer)
Transform

        int c;
        try {
            writer.write("<pre>");
            while ((c = reader.read()) != -1) {
                if (c == '<") {
                    writer.write("<");
                } else if (c == '>") {
                    writer.write(">");
                } else {
                    writer.write(c);
                }
            }
            writer.write("</pre>");
        } catch (IOException ex) {
            throw new JspException("EscapeHtml: " +
            "error copying chars", ex);
        }