package com.acme.tag; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; /** * A simple Case Tag * @author Magnus Rydin */ public class CaseTag extends SwitchTag { public CaseTag() { super(); } public int doStartTag() throws JspTagException { //The Switch Tag should be our parent Tag SwitchTag parent=(SwitchTag)findAncestorWithClass(this,SwitchTag.class); //If Switch was not our parent, throw Exception if(parent==null) { throw new JspTagException("Case Tag without Switch Tag"); } try { //check if values match if(parent.getValue().equals(getValue())) { return EVAL_BODY_INCLUDE; } else { return SKIP_BODY; } } catch(NullPointerException e) { //check if both values are null if(parent.getValue()==null && getValue()==null) { return EVAL_BODY_INCLUDE; } else { return SKIP_BODY; } } } }