KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ajaxanywhere > AAUtils


1 /*
2 Copyright 2005 Vitaliy Shevchuk (shevit@users.sourceforge.net)
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15
16 */

17
18 package org.ajaxanywhere;
19
20 import javax.servlet.ServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 /**
27  * Date: 24 juil. 2005
28  * Time: 14:32:12
29  */

30 public class AAUtils {
31
32     public static boolean isAjaxRequest(ServletRequest JavaDoc req) {
33         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) req;
34         return "true".equals(request.getParameter(AAConstants.AJAX_URL_INDETIFIER));
35     }
36
37     public static boolean isAjaxRequest(Map JavaDoc requestParameterMap) {
38         return "true".equals(requestParameterMap.get(AAConstants.AJAX_URL_INDETIFIER));
39     }
40
41     /**
42      * @deprecated use addZonesToRefresh instead
43      * @see AAUtils#addZonesToRefresh(javax.servlet.ServletRequest, String)
44      * @param request
45      * @param commaSeparatedZonesList
46      */

47     public static void addZonesToRefreh(ServletRequest JavaDoc request, String JavaDoc commaSeparatedZonesList) {
48         addZonesToRefresh(request, commaSeparatedZonesList);
49     }
50     public static void addZonesToRefresh(ServletRequest JavaDoc request, String JavaDoc commaSeparatedZonesList) {
51         Set JavaDoc res = getZonesToRefresh(request);
52         if (res == null)
53             return;
54         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commaSeparatedZonesList, ",;", false);
55         while (st.hasMoreTokens()) res.add(st.nextToken());
56     }
57
58     /**
59      * @deprecated use getZonesToRefresh instead
60      * @see AAUtils#getZonesToRefresh(javax.servlet.ServletRequest)
61      * @param request
62      */

63     public static Set JavaDoc getZonesToRefreh(ServletRequest JavaDoc request) {
64         return getZonesToRefresh(request);
65     }
66
67     public static Set JavaDoc getZonesToRefresh(ServletRequest JavaDoc request) {
68         return (Set JavaDoc) request.getAttribute(AAConstants.REFRESH_ZONES_KEY);
69     }
70
71     public static Set JavaDoc getZonesToRefresh(Map JavaDoc requestMap) {
72         return (Set JavaDoc) requestMap.get(AAConstants.REFRESH_ZONES_KEY);
73     }
74
75
76     static void setZonesToRefresh(ServletRequest JavaDoc request, Set JavaDoc zones) {
77         request.setAttribute(AAConstants.REFRESH_ZONES_KEY, zones);
78     }
79
80     public static void getRefreshZonesFromURL(ServletRequest JavaDoc request) {
81         String JavaDoc[] zones = request.getParameterValues(AAConstants.ZONES_URL_KEY);
82         if (zones != null) {
83             for (int i1 = 0; zones != null && i1 < zones.length; i1++) {
84                 String JavaDoc zone1 = zones[i1];
85                 addZonesToRefresh(request, zone1);
86             }
87         }
88     }
89
90     static String JavaDoc getZoneContent(String JavaDoc zone, BufferResponseWrapper bufferResponseWrapper) {
91         String JavaDoc res = bufferResponseWrapper.findSubstring(getZoneStartDelimiter(zone), getZoneEndDelimiter(zone));
92         return res;
93     }
94
95     public static String JavaDoc getZoneStartDelimiter(String JavaDoc zone) {
96         return "<div style=\"display:inline;\" id=\"" + AAConstants.ZONE_HTML_ID_PREFIX+
97                 zone.replaceAll("\"", "&quot;") + "\">";
98     }
99     
100     public static String JavaDoc getZoneEndDelimiter(String JavaDoc zone) {
101         return AAConstants.END_OF_ZONE_PREFIX+zone+AAConstants.END_OF_ZONE_SUFFIX;
102     }
103
104 }
105
Popular Tags