1 10 package org.mmbase.bridge.jsp.taglib; 11 12 import org.mmbase.bridge.jsp.taglib.util.Attribute; 13 import org.mmbase.util.Entry; 14 import javax.servlet.jsp.*; 15 import java.util.*; 16 import org.mmbase.util.logging.*; 17 18 24 25 public class ParamTag extends ContextReferrerTag implements ParamHandler { 26 private static final Logger log = Logging.getLoggerInstance(ParamTag.class); 27 28 protected List entries = null; 29 30 private Attribute name = Attribute.NULL; 31 private Attribute value = Attribute.NULL; 32 private Attribute referid = Attribute.NULL; 33 private ParamHandler paramHandler; 34 private boolean handled; 35 36 public void setName(String n) throws JspTagException { 37 name = getAttribute(n); 38 } 39 public void setValue(String v) throws JspTagException { 40 value = getAttribute(v); 41 } 42 45 public void setReferid(String r) throws JspTagException { 46 referid = getAttribute(r); 47 } 48 49 public void addParameter(String key, Object value) throws JspTagException { 50 if (entries == null) entries = new ArrayList(); 51 entries.add(new Entry(key, value)); 52 if (log.isDebugEnabled()) { 53 log.debug("entries " + entries); 54 } 55 } 56 57 public int doStartTag() throws JspException { 58 findWriter(false); paramHandler = (ParamHandler) findParentTag(ParamHandler.class, null); 60 handled = false; 61 return super.doStartTag(); 62 } 63 64 public int doAfterBody() throws JspException { 65 if (value == Attribute.NULL && referid == Attribute.NULL && entries == null) { 66 if (bodyContent != null) { 67 helper.setValueOnly(bodyContent.getString(), WriterHelper.IMPLICITLIST); paramHandler.addParameter(name.getString(this), helper.getValue()); 70 handled = true; 71 } 72 } 73 return super.doAfterBody(); 74 } 75 76 public int doEndTag() throws JspTagException { 77 if (! handled) { 78 if (value != Attribute.NULL) { 79 if (referid != Attribute.NULL || entries != null) throw new JspTagException("Must specify either 'value', 'referid' or sub-param-tags, not both"); 80 helper.setValueOnly(value.getString(this), WriterHelper.IMPLICITLIST); paramHandler.addParameter(name.getString(this), helper.getValue()); 82 83 } else if (referid != Attribute.NULL) { 84 if (entries != null) throw new JspTagException("Must specify either 'value', 'referid' or sub-param-tags, not both"); 85 paramHandler.addParameter(name.getString(this), getObject(referid.getString(this))); 86 } else if (entries != null) { 87 paramHandler.addParameter(name.getString(this), entries); 88 entries = null; 89 } else { 90 paramHandler.addParameter(name.getString(this), ""); 91 } 92 } 93 paramHandler = null; 94 return super.doEndTag(); 95 } 96 97 public void doFinally() { 98 paramHandler = null; 99 entries = null; 100 super.doFinally(); 101 } 102 } 103 | Popular Tags |