1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 72 73 import com.jcorporate.expresso.core.controller.Block; 74 import com.jcorporate.expresso.core.controller.ControllerElement; 75 76 import javax.servlet.jsp.JspTagException ; 77 import javax.servlet.jsp.tagext.Tag ; 78 79 80 83 public class IfElementExists 84 extends ExpressoTagSupport { 85 private ControllerElement oneElement = null; 86 private java.lang.String name = null; 87 private java.lang.String type = null; 88 private boolean inverse = false; 89 private java.lang.String nameToUse = null; 90 91 public IfElementExists() { 92 super(); 93 } 94 95 public int doEndTag() 96 throws javax.servlet.jsp.JspTagException { 97 return EVAL_PAGE; 98 } 99 100 public int doStartTag() 101 throws javax.servlet.jsp.JspTagException { 102 getControllerResponse(); 103 nameToUse = name; 104 105 try { 106 Tag container = getContainer(); 107 108 if (container == null) { 109 if (getType().equalsIgnoreCase("transition")) { 110 oneElement = ctlrResp.getTransition(getName()); 111 } else if (getType().equalsIgnoreCase("block")) { 112 oneElement = ctlrResp.getBlock(getName()); 113 } else if (getType().equalsIgnoreCase("input")) { 114 oneElement = ctlrResp.getInput(getName()); 115 } else if (getType().equalsIgnoreCase("output")) { 116 oneElement = ctlrResp.getOutput(getName()); 117 } 118 } else { 119 if (container instanceof ElementIterator) { 120 oneElement = ((ElementIterator) container).getElement(); 121 nameToUse = oneElement.getName(); 122 } else if (container instanceof BlockTag) { 123 Block oneBlock = ((BlockTag) container).getBlock(); 124 125 if (oneBlock != null) { 126 oneElement = oneBlock.getContent(getName()); 127 } 128 } else { 129 throw new JspTagException ("Cannot handle container tag" + 130 container.getClass().getName()); 131 } 132 } 133 } catch (Exception e) { 134 throw new JspTagException ("IfElementExists Tag Error: " + 135 e.getMessage()); 136 } 137 138 boolean exists = true; 139 140 if (oneElement == null) { 141 exists = false; 142 } 143 if (inverse) { 144 exists = !exists; 145 } 146 if (exists) { 147 return EVAL_BODY_INCLUDE; 148 } else { 149 return SKIP_BODY; 150 } 151 } 152 153 public boolean getInverse() { 154 return this.inverse; 155 } 156 157 public java.lang.String getName() { 158 return nameToUse; 159 } 160 161 public java.lang.String getType() { 162 return type; 163 } 164 165 public void setInverse(boolean newInverse) { 166 this.inverse = newInverse; 167 } 168 169 public void setName(java.lang.String newName) { 170 name = newName; 171 } 172 173 public void setType(java.lang.String newType) { 174 type = newType; 175 } 176 } 177 178 | Popular Tags |