1 7 package com.inversoft.verge.mvc.view.jsp; 8 9 10 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import javax.servlet.http.HttpServletRequest ; 15 import javax.servlet.http.HttpServletResponse ; 16 import javax.servlet.jsp.JspException ; 17 import javax.servlet.jsp.JspFactory ; 18 import javax.servlet.jsp.PageContext ; 19 import javax.servlet.jsp.tagext.Tag ; 20 import javax.servlet.jsp.tagext.TagSupport ; 21 22 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 23 24 import com.inversoft.verge.mvc.MVCConstants; 25 import com.inversoft.verge.mvc.MVCRequest; 26 import com.inversoft.verge.mvc.view.HtmlConstants; 27 import com.inversoft.verge.mvc.view.HtmlViewToolkit; 28 29 30 36 public class JspTools { 37 38 39 41 48 public static final boolean JSP_20; 49 50 53 public static final String RADIO_NAMES_KEY = "inversoftRadioNames"; 54 55 56 59 static { 60 String version = 61 JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion(); 62 double versionDbl = Double.parseDouble(version.substring(0, 3)); 63 JSP_20 = (versionDbl >= 2.0) ? true : false; 64 } 65 66 67 93 public static Object expand(String attrName, String expression, 94 Class expectedType, Tag tag, PageContext context) throws JspException { 95 96 Object ret = expression; 97 if (ret != null && !JSP_20) { 98 ret = ExpressionEvaluatorManager.evaluate(attrName, expression, 99 expectedType, tag, context); 100 } 101 102 return ret; 103 } 104 105 111 public static void appendId(StringBuffer buf, TagSupport tag) { 112 String id = tag.getId(); 113 if (id != null) { 114 HtmlViewToolkit.appendAttribute(buf, HtmlConstants.ID, id); 115 } 116 } 117 118 126 public static String getRadioName(String definition, PageContext context) { 127 Map map = (Map ) context.getAttribute(RADIO_NAMES_KEY); 128 if (map == null) { 129 return null; 130 } 131 132 return (String ) map.get(definition); 133 } 134 135 143 public static void setRadioName(String definition, String name, 144 PageContext context) { 145 Map map = (Map ) context.getAttribute(RADIO_NAMES_KEY); 146 if (map == null) { 147 map = new HashMap (); 148 context.setAttribute(RADIO_NAMES_KEY, map); 149 } 150 151 map.put(definition, name); 152 } 153 154 161 public static MVCRequest getMVCRequest(PageContext pageContext) { 162 MVCRequest mvcRequest = 164 (MVCRequest) pageContext.getAttribute(MVCConstants.MVC_REQUEST_KEY, 165 PageContext.REQUEST_SCOPE); 166 if (mvcRequest == null) { 167 mvcRequest = new MVCRequest((HttpServletRequest ) pageContext.getRequest(), 168 (HttpServletResponse ) pageContext.getResponse()); 169 pageContext.setAttribute(MVCConstants.MVC_REQUEST_KEY, mvcRequest, 170 PageContext.REQUEST_SCOPE); 171 } 172 173 return mvcRequest; 174 } 175 } | Popular Tags |