1 16 package com.blandware.atleap.webapp.taglib.core.menu.context; 17 18 import com.blandware.atleap.webapp.taglib.core.util.ContextMenuItem; 19 import org.apache.struts.taglib.TagUtils; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspTagException ; 23 import javax.servlet.jsp.PageContext ; 24 import javax.servlet.jsp.tagext.JspFragment ; 25 import java.io.IOException ; 26 import java.io.StringWriter ; 27 28 66 public class ItemTag extends ItemContainerSupport implements ItemContainer { 67 68 71 protected Boolean enabled = Boolean.TRUE; 72 73 76 protected Boolean includeInContextMenu = Boolean.TRUE; 77 78 81 protected Boolean includeInPage = Boolean.TRUE; 82 83 86 protected ContextMenuItem item = null; 87 88 91 public ItemTag() { 92 } 93 94 103 public Boolean getEnabled() { 104 return enabled; 105 } 106 107 112 public void setEnabled(Boolean enabled) { 113 this.enabled = enabled; 114 } 115 116 125 public Boolean getIncludeInContextMenu() { 126 return includeInContextMenu; 127 } 128 129 134 public void setIncludeInContextMenu(Boolean includeInContextMenu) { 135 this.includeInContextMenu = includeInContextMenu; 136 } 137 138 147 public Boolean getIncludeInPage() { 148 return includeInPage; 149 } 150 151 156 public void setIncludeInPage(Boolean includeInPage) { 157 this.includeInPage = includeInPage; 158 } 159 160 161 166 public ContextMenuItem getItem() { 167 return item; 168 } 169 170 176 public void doTag() throws JspException , IOException { 177 178 ItemContainer container = (ItemContainer) findAncestorWithClass(this, ItemContainer.class); 180 181 if ( container == null ) { 182 throw new JspTagException ("This tag is only valid when nested within some ItemContainer"); 183 } 184 185 187 if ( enabled == null ) { 188 enabled = Boolean.FALSE; 189 } 190 191 if ( includeInContextMenu == null ) { 192 includeInContextMenu = Boolean.TRUE; 193 } 194 195 if ( includeInPage == null ) { 196 includeInPage = Boolean.TRUE; 197 } 198 199 Integer index = new Integer (0); 201 202 ItemSetTag itemSetTag = (ItemSetTag) findAncestorWithClass(this, ItemSetTag.class); 204 if ( itemSetTag != null ) { 205 index = itemSetTag.getIndex(); 206 } 207 208 ItemTag parentItemTag = (container instanceof ItemTag) ? (ItemTag) container : null; 210 211 item = new ContextMenuItem(); 214 215 if ( !includeInContextMenu.booleanValue() || (parentItemTag != null && !parentItemTag.getEnabled().booleanValue()) ) { 216 item.setHidden(Boolean.TRUE); 217 } 218 219 StringWriter writer = new StringWriter (); 223 JspFragment body = getJspBody(); 224 if ( body != null ) { 225 body.invoke(writer); 226 } 227 if ( includeInPage.booleanValue() ) { 228 TagUtils.getInstance().write((PageContext ) getJspContext(), writer.toString()); 229 } 230 231 if ( item != null ) { 233 item.setChildItems(menus); 234 } 235 236 239 container.storeItem(index, item); 240 241 } 242 243 251 public void storeItem(Integer index, ContextMenuItem item) { 252 menus.add(item); 253 } 254 } 255 | Popular Tags |