001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.util;
016:
017: import java.util.ArrayList;
018: import java.util.Iterator;
019: import java.util.List;
020: import javax.servlet.jsp.JspException;
021: import javax.servlet.jsp.PageContext;
022: import org.araneaframework.core.AraneaRuntimeException;
023: import org.araneaframework.uilib.util.NameUtil;
024:
025: /**
026: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
027: */
028: public class JspUpdateRegionUtil {
029: public static List parseUpdateRegionNames(String updateRegions)
030: throws JspException {
031: return JspUtil.parseMultiValuedAttribute(updateRegions);
032: }
033:
034: public static String getUpdateRegionLocalName(String regionName) {
035: return regionName;
036: }
037:
038: public static List getUpdateRegionNames(PageContext pageContext,
039: String updateRegions, String globalUpdateRegions)
040: throws JspException {
041: List result = JspUpdateRegionUtil.getUpdateRegionLocalNames(
042: pageContext, updateRegions);
043: result.addAll(JspUpdateRegionUtil.getUpdateRegionGlobalNames(
044: pageContext, globalUpdateRegions));
045:
046: return result;
047: }
048:
049: public static List getUpdateRegionLocalNames(
050: PageContext pageContext, String updateRegions)
051: throws JspException {
052: List result = new ArrayList();
053:
054: String contextWidgetId = JspWidgetUtil
055: .getContextWidgetFullId(pageContext);
056:
057: for (Iterator i = parseUpdateRegionNames(updateRegions)
058: .iterator(); i.hasNext();) {
059: String regionName = (String) i.next();
060:
061: result.add(NameUtil
062: .getFullName(contextWidgetId, regionName));
063: }
064:
065: return result;
066: }
067:
068: public static List getUpdateRegionGlobalNames(
069: PageContext pageContext, String globalUpdateRegions)
070: throws JspException {
071: List result = new ArrayList();
072:
073: for (Iterator i = parseUpdateRegionNames(globalUpdateRegions)
074: .iterator(); i.hasNext();) {
075: String regionName = (String) i.next();
076:
077: result.add(regionName);
078: }
079:
080: return result;
081: }
082:
083: public static String formatUpdateRegionsJS(List updateRegions) {
084: StringBuffer result = new StringBuffer();
085:
086: if (updateRegions != null) {
087: for (Iterator i = updateRegions.iterator(); i.hasNext();) {
088: String region = (String) i.next();
089: if (region.indexOf(',') != -1)
090: throw new AraneaRuntimeException(
091: "Updateregion name '" + region
092: + "' cannot contain ','");
093:
094: result.append(region);
095:
096: if (i.hasNext())
097: result.append(",");
098: }
099: }
100:
101: return result.toString();
102: }
103: }
|