1 17 18 package org.ajaxanywhere; 19 20 import javax.servlet.ServletRequest ; 21 import javax.servlet.http.HttpServletRequest ; 22 import java.util.Map ; 23 import java.util.Set ; 24 import java.util.StringTokenizer ; 25 26 30 public class AAUtils { 31 32 public static boolean isAjaxRequest(ServletRequest req) { 33 HttpServletRequest request = (HttpServletRequest ) req; 34 return "true".equals(request.getParameter(AAConstants.AJAX_URL_INDETIFIER)); 35 } 36 37 public static boolean isAjaxRequest(Map requestParameterMap) { 38 return "true".equals(requestParameterMap.get(AAConstants.AJAX_URL_INDETIFIER)); 39 } 40 41 47 public static void addZonesToRefreh(ServletRequest request, String commaSeparatedZonesList) { 48 addZonesToRefresh(request, commaSeparatedZonesList); 49 } 50 public static void addZonesToRefresh(ServletRequest request, String commaSeparatedZonesList) { 51 Set res = getZonesToRefresh(request); 52 if (res == null) 53 return; 54 StringTokenizer st = new StringTokenizer (commaSeparatedZonesList, ",;", false); 55 while (st.hasMoreTokens()) res.add(st.nextToken()); 56 } 57 58 63 public static Set getZonesToRefreh(ServletRequest request) { 64 return getZonesToRefresh(request); 65 } 66 67 public static Set getZonesToRefresh(ServletRequest request) { 68 return (Set ) request.getAttribute(AAConstants.REFRESH_ZONES_KEY); 69 } 70 71 public static Set getZonesToRefresh(Map requestMap) { 72 return (Set ) requestMap.get(AAConstants.REFRESH_ZONES_KEY); 73 } 74 75 76 static void setZonesToRefresh(ServletRequest request, Set zones) { 77 request.setAttribute(AAConstants.REFRESH_ZONES_KEY, zones); 78 } 79 80 public static void getRefreshZonesFromURL(ServletRequest request) { 81 String [] zones = request.getParameterValues(AAConstants.ZONES_URL_KEY); 82 if (zones != null) { 83 for (int i1 = 0; zones != null && i1 < zones.length; i1++) { 84 String zone1 = zones[i1]; 85 addZonesToRefresh(request, zone1); 86 } 87 } 88 } 89 90 static String getZoneContent(String zone, BufferResponseWrapper bufferResponseWrapper) { 91 String res = bufferResponseWrapper.findSubstring(getZoneStartDelimiter(zone), getZoneEndDelimiter(zone)); 92 return res; 93 } 94 95 public static String getZoneStartDelimiter(String zone) { 96 return "<div style=\"display:inline;\" id=\"" + AAConstants.ZONE_HTML_ID_PREFIX+ 97 zone.replaceAll("\"", """) + "\">"; 98 } 99 100 public static String getZoneEndDelimiter(String zone) { 101 return AAConstants.END_OF_ZONE_PREFIX+zone+AAConstants.END_OF_ZONE_SUFFIX; 102 } 103 104 } 105 | Popular Tags |