1 17 18 package com.finalist.jag.taglib.util; 19 20 import com.finalist.jag.*; 21 import com.finalist.jag.skelet.*; 22 23 import java.util.*; 24 25 26 33 public class RequestUtil { 34 35 46 public static String lookupString(PageContext pageContext, String name, 47 String property) 48 { 49 Object object = pageContext.getAttribute(name); 50 51 if (object == null) { 52 object = pageContext.getSessionContext().getAttribute(name); 53 } 54 55 String returnValue = null; 56 57 if ((object != null) && (object instanceof ModuleData)) 58 { 59 ModuleData moduleData = (ModuleData) object; 60 if (moduleData.isValueCollection()) 61 { 62 Collection col = (Collection) moduleData.getValue(); 63 Iterator iterator = col.iterator(); 64 65 while (iterator.hasNext()) 66 { 67 moduleData = (ModuleData) iterator.next(); 68 if (moduleData != null && moduleData.getName().equals(property) 69 && moduleData.isValueString()) 70 { 71 returnValue = (String ) moduleData.getValue(); 72 break; 73 } 74 } 75 } 76 } 77 else if ((object != null) && (object instanceof String )) 78 { 79 returnValue = (String ) object; 80 } 81 else 82 { 83 String colProperty = ""; 84 String colName = ""; 85 StringTokenizer tokens = new StringTokenizer(name, "."); 86 while(tokens.hasMoreTokens()) 87 { 88 String token = tokens.nextToken(); 89 if(!tokens.hasMoreTokens()) 90 { 91 colProperty = token; 92 } 93 else 94 { 95 if(colName.length() > 0) colName += "."; 96 colName += token; 97 } 98 } 99 Collection collection = lookupCollection(pageContext,colName,colProperty); 100 if(collection != null) 101 { 102 Iterator iterator = collection.iterator(); 103 if(iterator.hasNext()) 104 { 105 object = iterator.next(); 106 String hashcode = ""+object.hashCode(); 107 pageContext.setAttribute(hashcode, object); 108 returnValue = lookupString(pageContext, hashcode, property); 109 pageContext.removeAttribute(hashcode); 110 } 111 } 112 } 113 return returnValue; 114 } 115 116 127 public static Collection lookupCollection(PageContext pageContext, 128 String name, String property) 129 { 130 SessionContext session = pageContext.getSessionContext(); 131 Object object = pageContext.getAttribute(name); 132 133 if (object == null) { 134 object = session.getAttribute(name); 135 } 136 137 Collection returnValue = null; 138 139 if ((object != null) && (object instanceof Collection)) 140 { 141 returnValue = (Collection) object; 142 } 143 else 144 { 145 Collection dataModules = null; 146 ArrayList tmpList = new ArrayList(); 147 148 if ((object != null) && (object instanceof ModuleData)) 149 { 150 ModuleData dataModule = (ModuleData) object; 151 152 if (dataModule.isValueCollection()) { 153 dataModules = (Collection) dataModule.getValue(); 154 } 155 } 156 else 157 { 158 SkeletDataObj skelet = session.getSkelet(); 159 StringTokenizer tokens = new StringTokenizer(name, "."); 160 161 dataModules = (Collection) skelet.getValue(); 162 163 if (name.indexOf(skelet.getName()) == 0) { 164 tokens.nextToken(); 165 } 166 167 while (tokens.hasMoreTokens()) 168 { 169 String label = tokens.nextToken(); 170 Iterator iterator = dataModules.iterator(); 171 172 while (iterator.hasNext()) 173 { 174 ModuleData moduleData = (ModuleData) iterator.next(); 175 176 if (moduleData.isValueCollection() 177 && moduleData.getName().equals(label)) 178 { 179 if (tokens.hasMoreTokens()) 180 { 181 dataModules =(Collection) moduleData.getValue(); 182 break; 183 } 184 } 185 } 186 dataModules = null; 187 break; 188 } 189 } 190 191 if (dataModules != null) 192 { 193 Iterator iterator = dataModules.iterator(); 194 while ((property != null) && iterator.hasNext()) 195 { 196 ModuleData moduleData = (ModuleData) iterator.next(); 197 198 if (moduleData != null && moduleData.isValueCollection() 199 && moduleData.getName().equals(property)) { 200 tmpList.add(moduleData); 201 } 202 } 203 returnValue = tmpList; 204 } 205 } 206 return returnValue; 207 } 208 } 209 | Popular Tags |