1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 72 73 import com.jcorporate.expresso.core.controller.ControllerElement; 74 import com.jcorporate.expresso.core.controller.Input; 75 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 76 77 import javax.servlet.jsp.JspTagException ; 78 import javax.servlet.jsp.JspWriter ; 79 import javax.servlet.jsp.tagext.Tag ; 80 81 82 85 public class LabelTag 86 extends ExpressoTagSupport { 87 private ControllerElement oneElement = null; 88 private java.lang.String name = null; 89 private java.lang.String type = null; 90 private java.lang.String nameToUse = null; 91 92 public LabelTag() { 93 super(); 94 } 95 96 public int doStartTag() throws javax.servlet.jsp.JspException { 97 nameToUse = null; 98 oneElement = null; 99 return EVAL_BODY_INCLUDE; 100 } 101 102 103 public int doEndTag() 104 throws javax.servlet.jsp.JspTagException { 105 nameToUse = name; 106 getControllerResponse(); 107 108 try { 109 Tag container = getContainer(); 110 111 if (container == null) { 112 if (getType().equalsIgnoreCase("action")) { 113 oneElement = ctlrResp.getTransition(getName()); 114 } else if (getType().equalsIgnoreCase("block")) { 115 oneElement = ctlrResp.getBlock(getName()); 116 } else if (getType().equalsIgnoreCase("input")) { 117 oneElement = ctlrResp.getInput(getName()); 118 } else if (getType().equalsIgnoreCase("output")) { 119 oneElement = ctlrResp.getOutput(getName()); 120 } 121 } else { 122 if (container instanceof ElementIterator) { 123 oneElement = ((ElementIterator) container).getElement(); 124 nameToUse = oneElement.getName(); 125 } else if (container instanceof BlockTag) { 126 oneElement = ((BlockTag) container).getBlock().getContent(getName()); 127 } else { 128 throw new JspTagException ("IfElementExistsTag: cannot handle container tag" + 129 container.getClass().getName()); 130 } 131 } 132 if (oneElement != null) { 133 JspWriter writer = pageContext.getOut(); 134 String cssStyle = oneElement.getAttribute(Input.ATTRIBUTE_CSS_STYLE); 135 boolean printStyle = (cssStyle != null && cssStyle.length() > 0); 136 if (printStyle) { 137 FastStringBuffer fsb = FastStringBuffer.getInstance(); 138 try { 139 fsb.append("<div class=\""); 140 fsb.append(cssStyle); 141 fsb.append("\">"); 142 writer.print(fsb.toString()); 143 } finally { 144 fsb.release(); 145 } 146 147 } 148 writer.print(oneElement.getLabel()); 149 if (printStyle) { 150 writer.print("</div>"); 151 } 152 } else { 153 throw new JspTagException ("No element found"); 154 } 155 } catch (Exception e) { 156 throw new JspTagException ("Label tag Error: " + e.getMessage()); 157 } 158 159 return EVAL_PAGE; 160 } 161 162 public java.lang.String getName() { 163 return nameToUse; 164 } 165 166 public java.lang.String getType() { 167 return type; 168 } 169 170 public void setName(java.lang.String newName) { 171 name = newName; 172 } 173 174 public void setType(java.lang.String newType) { 175 type = newType; 176 } 177 } 178 179 | Popular Tags |