1 18 package org.apache.beehive.netui.databinding.datagrid.runtime.util; 19 20 import java.net.URISyntaxException ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 import java.util.Locale ; 24 import javax.servlet.jsp.JspContext ; 25 import javax.servlet.jsp.PageContext ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils; 30 import org.apache.beehive.netui.pageflow.internal.InternalUtils; 31 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils; 32 import org.apache.beehive.netui.util.Bundle; 33 34 39 public final class JspUtil { 40 41 42 private JspUtil() { 43 } 44 45 51 public static final HttpServletRequest getRequest(JspContext jspContext) { 52 PageContext pageContext = getPageContext(jspContext); 53 return (HttpServletRequest )pageContext.getRequest(); 54 } 55 56 62 public static final PageContext getPageContext(JspContext jspContext) { 63 if(!(jspContext instanceof PageContext )) 64 throw new IllegalStateException (Bundle.getErrorString("DataGridUtil_IllegalJspContext", new Object []{(jspContext != null ? jspContext.getClass().getName() : "null")})); 65 else 66 return (PageContext )jspContext; 67 } 68 69 83 public static final String createURL(String href, String action, String location, String scope, Map params, JspContext jspContext) 84 throws URISyntaxException { 85 PageContext pageContext = getPageContext(jspContext); 86 87 88 if(scope != null) { 89 if(params == null) 90 params = new HashMap (); 91 92 params.put(ScopedServletUtils.SCOPE_ID_PARAM, scope); 93 } 94 95 String uri = null; 96 if(action != null) 97 uri = PageFlowTagUtils.rewriteActionURL(pageContext, action, params, location); 98 else if(href != null) 99 uri = PageFlowTagUtils.rewriteHrefURL(pageContext, href, params, location); 100 else 101 return ((HttpServletRequest )pageContext.getRequest()).getPathTranslated(); 102 103 assert uri != null; 104 105 HttpServletResponse response = (HttpServletResponse )pageContext.getResponse(); 106 return response.encodeURL(uri); 107 } 108 109 114 public static final Locale getLocale(JspContext jspContext) { 115 return InternalUtils.lookupLocale(jspContext); 116 } 117 } 118 | Popular Tags |