001package bradleyross.j2ee.tags;
002import javax.servlet.jsp.JspException;
003import javax.servlet.jsp.PageContext;
004import javax.servlet.jsp.JspWriter;
005import javax.servlet.jsp.tagext.TagSupport;
006import javax.servlet.jsp.tagext.TagExtraInfo;
007import java.util.Enumeration;
008/**
009 * The goal is to produce a tag class that
010 * can be used in a variety of circumstances.
011 * <p>I was hoping that the tag class could
012 *    determine the tag name and act accordingly.  However,
013 *    it appears that this can only be used for one tag name.
014 *    In this case, it serves as a replacement for the
015 *    html tag.</p>
016 * @see TagExtraInfo
017 * @author Bradley Ross
018 *
019 */
020public class DefaultTag extends TagSupport 
021{
022        /**
023         * Inserted to satisfy Serializable interface.
024         */
025        private static final long serialVersionUID = 1L;
026
027        public void setPageContext(PageContext context)
028        {
029
030                super.setPageContext(context);
031        }
032        protected String source = null;
033        public void setSource (String value)
034        {source = value; }
035        public String getSource()
036        { return source;}
037        public int doStartTag() throws JspException
038        {       
039                try
040                {
041                        JspWriter out = pageContext.getOut();
042                        out.print("<html><!-- tag for html -->");
043                        out.print("<!-- Identifier: " + id + " -->");
044                        out.print("<!-- source is " + source + " -->");
045                        Enumeration<?> list =   getValues();
046                        if (list != null)
047                        {
048                                for (Enumeration<?> items = list;
049                                items.hasMoreElements(); )
050                                {
051                                        String value = (String) items.nextElement();
052                                        out.println("<!-- " + value + " -->");
053                                }
054                        }
055                        else
056                        { out.println("<!-- No values -->"); }
057                }
058                catch (java.io.IOException e)
059                {
060                        throw new JspException("doStartTag: " + e.getClass().getName() + " " + e.getMessage());
061                }
062                return EVAL_BODY_INCLUDE;
063        }
064        public int doEndTag() throws JspException
065        {
066                try
067                {
068                        JspWriter out = pageContext.getOut();
069                        out.print("</html><!-- end tag for html -->");
070                }
071                catch (java.io.IOException e)
072                {
073                        throw new JspException("doEndTag: " + e.getClass().getName() + " " + e.getMessage());
074                }
075                return EVAL_PAGE;
076        }
077}