1 10 package org.mmbase.bridge.jsp.taglib; 11 import javax.servlet.jsp.JspTagException ; 12 import java.util.Collection ; 13 import javax.servlet.jsp.PageContext ; 14 import javax.servlet.http.*; 15 import org.mmbase.bridge.jsp.taglib.functions.Functions; 16 import org.mmbase.bridge.jsp.taglib.util.*; 17 18 24 25 public class RemoveTag extends ContextReferrerTag { 26 27 private Attribute value = Attribute.NULL; 28 private Attribute from = Attribute.NULL; 29 30 33 public void setValue(String v) throws JspTagException { 34 value = getAttribute(v); 35 } 36 37 40 public void setFrom(String f) throws JspTagException { 41 from = getAttribute(f); 42 } 43 44 47 protected void remove(ContextContainer cc, String referid) throws JspTagException { 48 if (value.getString(this).equals("")) { 49 cc.unRegister(referid); 50 } else { 51 Collection col = (Collection ) cc.get(referid); 52 Functions.remove(col, value.getValue(this)); 53 } 54 } 55 56 public int doEndTag() throws JspTagException { 57 super.doEndTag(); 58 String fromString = from.getString(this); 59 if (! "".equals(fromString)) { 60 boolean useCollection = ! value.getString(this).equals(""); 61 Collection col = null; 62 int from = ContextContainer.stringToLocation(fromString); 63 switch(from) { 64 case ContextContainer.LOCATION_PARENT: 65 if (useCollection) { 66 col = (Collection ) getContextProvider().getContextContainer().getParent().get(getReferid()); 67 break; 68 } else { 69 remove(getContextProvider().getContextContainer().getParent(), getReferid()); 70 return EVAL_PAGE; 71 } 72 case ContextContainer.LOCATION_PAGE: 73 if (useCollection) { 74 col = (Collection ) pageContext.getAttribute(getReferid()); 75 break; 76 } else { 77 pageContext.removeAttribute(getReferid()); 78 return EVAL_PAGE; 79 } 80 case ContextContainer.LOCATION_REQUEST: 81 if (useCollection) { 82 col = (Collection ) pageContext.getAttribute(getReferid(), PageContext.REQUEST_SCOPE); 83 break; 84 } else { 85 pageContext.removeAttribute(getReferid(), PageContext.REQUEST_SCOPE); 86 return EVAL_PAGE; 87 } 88 case ContextContainer.LOCATION_APPLICATION: 89 if (useCollection) { 90 col = (Collection ) pageContext.getAttribute(getReferid(), PageContext.APPLICATION_SCOPE); 91 break; 92 } else { 93 pageContext.removeAttribute(getReferid(), PageContext.APPLICATION_SCOPE); 94 return EVAL_PAGE; 95 } 96 case ContextContainer.LOCATION_SESSION: 97 HttpSession session = ((HttpServletRequest) pageContext.getRequest()).getSession(false); 98 if (session != null) { 99 if (useCollection) { 100 col = (Collection ) session.getAttribute(getReferid()); 101 break; 102 } else { 103 session.removeAttribute(getReferid()); 104 } 105 } 106 return EVAL_PAGE; 107 case ContextContainer.LOCATION_THIS: 108 break; 109 default: { 110 throw new JspTagException ("Unknown value for 'from' attribute " + fromString); 111 } 112 } 113 if (col != null) { 114 Functions.remove(col, value.getValue(this)); 115 return EVAL_PAGE; 116 } 117 } 118 119 remove(getContextProvider().getContextContainer(), getReferid()); 120 return EVAL_PAGE; 121 } 122 123 } 124 | Popular Tags |