001/**
002 * 
003 */
004package bradleyross.j2ee.tags;
005
006import java.io.IOException;
007import java.io.LineNumberReader;
008import javax.servlet.jsp.tagext.BodyTagSupport;
009// import javax.servlet.jsp.tagext.BodyContent;
010import javax.servlet.jsp.JspWriter;
011import javax.servlet.jsp.JspException;
012/**
013 * This is a demonstration action that converts the material between
014 * the start and end tags to escaped text and displays it on the output
015 * page.
016 * 
017 * <p>The Tag Library Descriptor defines this tag as TAGDEPENDENT, which 
018 *    means that the material in the body of the tag will not be
019 *    processed by the JSP preprocessor</p>
020 * @author Bradley Ross
021 *
022 */
023@SuppressWarnings("serial")
024public class ConvertToComment extends BodyTagSupport {
025        protected String className = new String();
026        /**
027         * Actions to be carried out when end tag is encountered.
028         * 
029         * <p>The method returns {@link #EVAL_PAGE} to indicate
030         *    that processing of the JSP page will continue.</p>
031         * 
032         * @see LineNumberReader
033         * @see JspWriter
034         */
035        @Override
036        public int doEndTag() throws JspException {
037                try {
038                        JspWriter out = pageContext.getOut();
039                        //  BodyContent content = getBodyContent();
040                        LineNumberReader reader = new LineNumberReader(getBodyContent().getReader());
041                        out.println("<!-- Start of converted material -->");
042                        while (true) {
043                                String line = reader.readLine();
044                                if (line == null) {break;}
045                                out.println(line.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;"));
046                                out.println("<br />");
047                        }
048                        out.println("<!-- End of converted comment -->");
049                        return EVAL_PAGE;
050                } catch (IOException e) {
051                        throw new JspException(e.getClass().getName() + e.getMessage(), e);
052                }
053        }
054        public String getClassName() {
055                return className;
056
057        }
058        public void setClassName(String value) {
059                className = value;
060        }
061
062}