| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.kuali.rice.krad.uif.util; |
| 12 | |
|
| 13 | |
import java.beans.PropertyDescriptor; |
| 14 | |
import java.io.Serializable; |
| 15 | |
import java.util.ArrayList; |
| 16 | |
import java.util.Collections; |
| 17 | |
import java.util.HashSet; |
| 18 | |
import java.util.List; |
| 19 | |
import java.util.ListIterator; |
| 20 | |
import java.util.Map; |
| 21 | |
import java.util.Set; |
| 22 | |
|
| 23 | |
import org.apache.commons.lang.StringUtils; |
| 24 | |
import org.kuali.rice.core.util.type.TypeUtils; |
| 25 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 26 | |
import org.kuali.rice.krad.uif.container.CollectionGroup; |
| 27 | |
import org.kuali.rice.krad.uif.container.Container; |
| 28 | |
import org.kuali.rice.krad.uif.core.Component; |
| 29 | |
import org.kuali.rice.krad.uif.core.DataBinding; |
| 30 | |
import org.kuali.rice.krad.uif.core.Ordered; |
| 31 | |
import org.kuali.rice.krad.uif.field.AttributeField; |
| 32 | |
import org.kuali.rice.krad.uif.field.Field; |
| 33 | |
import org.kuali.rice.krad.uif.field.GroupField; |
| 34 | |
import org.kuali.rice.krad.uif.layout.LayoutManager; |
| 35 | |
import org.kuali.rice.krad.util.ObjectUtils; |
| 36 | |
import org.springframework.beans.BeanUtils; |
| 37 | |
import org.springframework.core.OrderComparator; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | 0 | public class ComponentUtils { |
| 46 | |
|
| 47 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ComponentUtils.class); |
| 48 | |
|
| 49 | |
|
| 50 | |
public static <T extends Component> T copy(T component) { |
| 51 | 0 | return copy(component, null); |
| 52 | |
} |
| 53 | |
|
| 54 | |
public static <T extends Component> T copy(T component, String idSuffix) { |
| 55 | 0 | T copy = copyObject(component); |
| 56 | |
|
| 57 | 0 | if (StringUtils.isNotBlank(idSuffix)) { |
| 58 | 0 | updateIdsWithSuffixNested(copy, idSuffix); |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | return copy; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public static <T extends Object> T copyObject(T object) { |
| 65 | 0 | if (object == null) { |
| 66 | 0 | return null; |
| 67 | |
} |
| 68 | |
|
| 69 | 0 | T copy = null; |
| 70 | |
try { |
| 71 | 0 | copy = CloneUtils.deepClone(object); |
| 72 | |
} |
| 73 | 0 | catch (Exception e) { |
| 74 | 0 | throw new RuntimeException(e); |
| 75 | 0 | } |
| 76 | |
|
| 77 | 0 | return copy; |
| 78 | |
} |
| 79 | |
|
| 80 | |
protected static Object getCopyPropertyValue(Set<String> propertiesForReferenceCopy, String propertyName, |
| 81 | |
Object propertyValue) { |
| 82 | 0 | if (propertyValue == null) { |
| 83 | 0 | return null; |
| 84 | |
} |
| 85 | |
|
| 86 | 0 | Object copyValue = propertyValue; |
| 87 | |
|
| 88 | 0 | Class<?> valuePropertyType = propertyValue.getClass(); |
| 89 | 0 | if (propertiesForReferenceCopy.contains(propertyName) || TypeUtils.isSimpleType(valuePropertyType) |
| 90 | |
|| TypeUtils.isClassClass(valuePropertyType)) { |
| 91 | 0 | return copyValue; |
| 92 | |
} |
| 93 | |
|
| 94 | 0 | if (Component.class.isAssignableFrom(valuePropertyType) |
| 95 | |
|| LayoutManager.class.isAssignableFrom(valuePropertyType)) { |
| 96 | 0 | copyValue = copyObject(propertyValue); |
| 97 | |
} |
| 98 | |
else { |
| 99 | 0 | copyValue = ObjectUtils.deepCopy((Serializable) propertyValue); |
| 100 | |
} |
| 101 | |
|
| 102 | 0 | return copyValue; |
| 103 | |
} |
| 104 | |
|
| 105 | |
@SuppressWarnings("unchecked") |
| 106 | |
protected static <T extends Object> T getNewInstance(T object) { |
| 107 | 0 | T copy = null; |
| 108 | |
try { |
| 109 | 0 | copy = (T) object.getClass().newInstance(); |
| 110 | |
} |
| 111 | 0 | catch (Exception e) { |
| 112 | 0 | throw new RuntimeException("Unable to create new instance of class: " + object.getClass()); |
| 113 | 0 | } |
| 114 | |
|
| 115 | 0 | return copy; |
| 116 | |
} |
| 117 | |
|
| 118 | |
public static <T extends Field> List<T> copyFieldList(List<T> fields, String addBindingPrefix, String idSuffix) { |
| 119 | 0 | List<T> copiedFieldList = copyFieldList(fields, idSuffix); |
| 120 | |
|
| 121 | 0 | prefixBindingPath(copiedFieldList, addBindingPrefix); |
| 122 | |
|
| 123 | 0 | return copiedFieldList; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public static <T extends Field> List<T> copyFieldList(List<T> fields, String idSuffix) { |
| 127 | 0 | List<T> copiedFieldList = new ArrayList<T>(); |
| 128 | |
|
| 129 | 0 | for (T field : fields) { |
| 130 | 0 | T copiedField = copy(field, idSuffix); |
| 131 | 0 | copiedFieldList.add(copiedField); |
| 132 | 0 | } |
| 133 | |
|
| 134 | 0 | return copiedFieldList; |
| 135 | |
} |
| 136 | |
|
| 137 | |
public static <T extends Component> T copyComponent(T component, String addBindingPrefix, String idSuffix) { |
| 138 | 0 | T copy = copy(component, idSuffix); |
| 139 | |
|
| 140 | 0 | prefixBindingPathNested(copy, addBindingPrefix); |
| 141 | |
|
| 142 | 0 | return copy; |
| 143 | |
} |
| 144 | |
|
| 145 | |
public static <T extends Component> List<T> copyComponentList(List<T> components, String idSuffix) { |
| 146 | 0 | List<T> copiedComponentList = new ArrayList<T>(); |
| 147 | |
|
| 148 | 0 | for (T field : components) { |
| 149 | 0 | T copiedComponent = copy(field, idSuffix); |
| 150 | 0 | copiedComponentList.add(copiedComponent); |
| 151 | 0 | } |
| 152 | |
|
| 153 | 0 | return copiedComponentList; |
| 154 | |
} |
| 155 | |
|
| 156 | |
@SuppressWarnings("unchecked") |
| 157 | |
public static <T extends Component> List<T> getComponentsOfType(List<? extends Component> items, |
| 158 | |
Class<T> componentType) { |
| 159 | 0 | List<T> typeComponents = new ArrayList<T>(); |
| 160 | |
|
| 161 | 0 | for (Component component : items) { |
| 162 | 0 | if (componentType.isAssignableFrom(component.getClass())) { |
| 163 | 0 | typeComponents.add((T) component); |
| 164 | |
} |
| 165 | |
} |
| 166 | |
|
| 167 | 0 | return typeComponents; |
| 168 | |
} |
| 169 | |
|
| 170 | |
public static <T extends Component> List<T> getComponentsOfTypeDeep(List<? extends Component> items, |
| 171 | |
Class<T> componentType) { |
| 172 | 0 | List<T> typeComponents = new ArrayList<T>(); |
| 173 | |
|
| 174 | 0 | for (Component component : items) { |
| 175 | 0 | typeComponents.addAll(getComponentsOfTypeDeep(component, componentType)); |
| 176 | |
} |
| 177 | |
|
| 178 | 0 | return typeComponents; |
| 179 | |
} |
| 180 | |
|
| 181 | |
@SuppressWarnings("unchecked") |
| 182 | |
public static <T extends Component> List<T> getComponentsOfTypeDeep(Component component, Class<T> componentType) { |
| 183 | 0 | List<T> typeComponents = new ArrayList<T>(); |
| 184 | |
|
| 185 | 0 | if (component == null) { |
| 186 | 0 | return typeComponents; |
| 187 | |
} |
| 188 | |
|
| 189 | 0 | if (componentType.isAssignableFrom(component.getClass())) { |
| 190 | 0 | typeComponents.add((T) component); |
| 191 | |
} |
| 192 | |
|
| 193 | 0 | for (Component nested : component.getNestedComponents()) { |
| 194 | 0 | typeComponents.addAll(getComponentsOfTypeDeep(nested, componentType)); |
| 195 | |
} |
| 196 | |
|
| 197 | 0 | return typeComponents; |
| 198 | |
} |
| 199 | |
|
| 200 | |
public static void prefixBindingPath(List<? extends Field> fields, String addBindingPrefix) { |
| 201 | 0 | for (Field field : fields) { |
| 202 | 0 | if (field instanceof DataBinding) { |
| 203 | 0 | prefixBindingPath((DataBinding) field, addBindingPrefix); |
| 204 | |
} |
| 205 | 0 | else if (field instanceof GroupField) { |
| 206 | 0 | List<Field> groupFields = getComponentsOfType(((GroupField) field).getItems(), Field.class); |
| 207 | 0 | prefixBindingPath(groupFields, addBindingPrefix); |
| 208 | 0 | } |
| 209 | |
} |
| 210 | 0 | } |
| 211 | |
|
| 212 | |
public static void prefixBindingPathNested(Component component, String addBindingPrefix) { |
| 213 | 0 | if (component instanceof DataBinding) { |
| 214 | 0 | if (LOG.isDebugEnabled()) { |
| 215 | 0 | LOG.info("setting nested binding prefix '"+ addBindingPrefix +"' on " + component); |
| 216 | |
} |
| 217 | 0 | prefixBindingPath((DataBinding) component, addBindingPrefix); |
| 218 | |
} |
| 219 | |
|
| 220 | 0 | for (Component nested : component.getNestedComponents()) { |
| 221 | 0 | if (nested != null) { |
| 222 | 0 | prefixBindingPathNested(nested, addBindingPrefix); |
| 223 | |
} |
| 224 | |
} |
| 225 | 0 | } |
| 226 | |
|
| 227 | |
public static void prefixBindingPath(DataBinding field, String addBindingPrefix) { |
| 228 | 0 | String bindingPrefix = addBindingPrefix; |
| 229 | 0 | if (StringUtils.isNotBlank(field.getBindingInfo().getBindByNamePrefix())) { |
| 230 | 0 | bindingPrefix += "." + field.getBindingInfo().getBindByNamePrefix(); |
| 231 | |
} |
| 232 | 0 | field.getBindingInfo().setBindByNamePrefix(bindingPrefix); |
| 233 | |
|
| 234 | 0 | if (field instanceof AttributeField){ |
| 235 | 0 | AttributeField attrfield = (AttributeField)field; |
| 236 | 0 | if (StringUtils.isNotBlank(attrfield.getAdditionalDisplayPropertyName())){ |
| 237 | 0 | attrfield.getAdditionalDisplayPropertyBindingInfo().setBindByNamePrefix(bindingPrefix); |
| 238 | |
} |
| 239 | 0 | if (StringUtils.isNotBlank(attrfield.getAlternateDisplayPropertyName())){ |
| 240 | 0 | attrfield.getAlternateDisplayPropertyBindingInfo().setBindByNamePrefix(bindingPrefix); |
| 241 | |
} |
| 242 | |
} |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
public static void updateIdsWithSuffixNested(List<? extends Component> components, String idSuffix) { |
| 246 | 0 | for (Component component : components) { |
| 247 | 0 | updateIdsWithSuffixNested(component, idSuffix); |
| 248 | |
} |
| 249 | 0 | } |
| 250 | |
|
| 251 | |
public static void updateIdsWithSuffixNested(Component component, String idSuffix) { |
| 252 | 0 | updateIdsWithSuffix(component, idSuffix); |
| 253 | |
|
| 254 | 0 | if (Container.class.isAssignableFrom(component.getClass())) { |
| 255 | 0 | LayoutManager layoutManager = ((Container) component).getLayoutManager(); |
| 256 | 0 | layoutManager.setId(layoutManager.getId() + idSuffix); |
| 257 | |
} |
| 258 | |
|
| 259 | 0 | for (Component nested : component.getNestedComponents()) { |
| 260 | 0 | if (nested != null) { |
| 261 | 0 | updateIdsWithSuffixNested(nested, idSuffix); |
| 262 | |
} |
| 263 | |
} |
| 264 | 0 | } |
| 265 | |
|
| 266 | |
public static void updateIdsWithSuffix(Component component, String idSuffix) { |
| 267 | |
|
| 268 | 0 | component.setId(component.getId() + idSuffix); |
| 269 | 0 | } |
| 270 | |
|
| 271 | |
public static void setComponentsPropertyDeep(List<? extends Component> components, String propertyPath, |
| 272 | |
Object propertyValue) { |
| 273 | 0 | for (Component component : components) { |
| 274 | 0 | setComponentPropertyDeep(component, propertyPath, propertyValue); |
| 275 | |
} |
| 276 | 0 | } |
| 277 | |
|
| 278 | |
public static void setComponentPropertyDeep(Component component, String propertyPath, Object propertyValue) { |
| 279 | 0 | ObjectPropertyUtils.setPropertyValue(component, propertyPath, propertyValue, true); |
| 280 | |
|
| 281 | 0 | for (Component nested : component.getNestedComponents()) { |
| 282 | 0 | if (nested != null) { |
| 283 | 0 | setComponentPropertyDeep(nested, propertyPath, propertyValue); |
| 284 | |
} |
| 285 | |
} |
| 286 | 0 | } |
| 287 | |
|
| 288 | |
public static List<String> getComponentPropertyNames(Class<? extends Component> componentClass) { |
| 289 | 0 | List<String> componentProperties = new ArrayList<String>(); |
| 290 | |
|
| 291 | 0 | PropertyDescriptor[] properties = BeanUtils.getPropertyDescriptors(componentClass); |
| 292 | 0 | for (int i = 0; i < properties.length; i++) { |
| 293 | 0 | PropertyDescriptor descriptor = properties[i]; |
| 294 | 0 | if (descriptor.getReadMethod() != null) { |
| 295 | 0 | componentProperties.add(descriptor.getName()); |
| 296 | |
} |
| 297 | |
} |
| 298 | |
|
| 299 | 0 | return componentProperties; |
| 300 | |
} |
| 301 | |
|
| 302 | |
public static void pushObjectToContext(List<? extends Component> components, String contextName, Object contextValue) { |
| 303 | 0 | for (Component component : components) { |
| 304 | 0 | pushObjectToContext(component, contextName, contextValue); |
| 305 | |
} |
| 306 | 0 | } |
| 307 | |
|
| 308 | |
public static void pushObjectToContext(Component component, String contextName, Object contextValue) { |
| 309 | 0 | if (component == null) { |
| 310 | 0 | return; |
| 311 | |
} |
| 312 | |
|
| 313 | 0 | component.pushObjectToContext(contextName, contextValue); |
| 314 | |
|
| 315 | |
|
| 316 | 0 | if (Container.class.isAssignableFrom(component.getClass())) { |
| 317 | 0 | LayoutManager layoutManager = ((Container) component).getLayoutManager(); |
| 318 | 0 | if (layoutManager != null) { |
| 319 | 0 | layoutManager.pushObjectToContext(contextName, contextValue); |
| 320 | |
|
| 321 | 0 | for (Component nestedComponent : layoutManager.getNestedComponents()) { |
| 322 | 0 | pushObjectToContext(nestedComponent, contextName, contextValue); |
| 323 | |
} |
| 324 | |
} |
| 325 | |
} |
| 326 | |
|
| 327 | 0 | for (Component nestedComponent : component.getNestedComponents()) { |
| 328 | 0 | pushObjectToContext(nestedComponent, contextName, contextValue); |
| 329 | |
} |
| 330 | 0 | } |
| 331 | |
|
| 332 | |
public static void updateContextsForLine(List<? extends Component> components, Object collectionLine, |
| 333 | |
int lineIndex) { |
| 334 | 0 | for (Component component : components) { |
| 335 | 0 | updateContextForLine(component, collectionLine, lineIndex); |
| 336 | |
} |
| 337 | 0 | } |
| 338 | |
|
| 339 | |
public static void updateContextForLine(Component component, Object collectionLine, int lineIndex) { |
| 340 | 0 | pushObjectToContext(component, UifConstants.ContextVariableNames.LINE, collectionLine); |
| 341 | 0 | pushObjectToContext(component, UifConstants.ContextVariableNames.INDEX, new Integer(lineIndex)); |
| 342 | |
|
| 343 | 0 | boolean isAddLine = (lineIndex == -1); |
| 344 | 0 | pushObjectToContext(component, UifConstants.ContextVariableNames.IS_ADD_LINE, isAddLine); |
| 345 | 0 | } |
| 346 | |
|
| 347 | |
public static void processIds(Component component, Map<String, Integer> seenIds) { |
| 348 | 0 | String componentId = component.getId(); |
| 349 | 0 | Integer seenCount = new Integer(0); |
| 350 | 0 | if (StringUtils.isNotBlank(componentId)) { |
| 351 | 0 | if (seenIds.containsKey(componentId)) { |
| 352 | 0 | seenCount = seenIds.get(componentId); |
| 353 | 0 | seenCount += 1; |
| 354 | |
|
| 355 | 0 | component.setId(componentId + "_" + seenCount); |
| 356 | |
} |
| 357 | |
|
| 358 | 0 | seenIds.put(componentId, seenCount); |
| 359 | |
} |
| 360 | |
|
| 361 | 0 | if (Container.class.isAssignableFrom(component.getClass())) { |
| 362 | 0 | LayoutManager layoutManager = ((Container) component).getLayoutManager(); |
| 363 | 0 | if ((layoutManager != null) && StringUtils.isNotBlank(layoutManager.getId())) { |
| 364 | 0 | seenCount = new Integer(0); |
| 365 | 0 | if (seenIds.containsKey(layoutManager.getId())) { |
| 366 | 0 | seenCount = seenIds.get(layoutManager.getId()); |
| 367 | 0 | seenCount += 1; |
| 368 | |
|
| 369 | 0 | layoutManager.setId(layoutManager.getId() + "_" + seenCount); |
| 370 | |
} |
| 371 | |
|
| 372 | 0 | seenIds.put(layoutManager.getId(), seenCount); |
| 373 | |
} |
| 374 | |
} |
| 375 | |
|
| 376 | 0 | for (Component nested : component.getNestedComponents()) { |
| 377 | 0 | if (nested != null) { |
| 378 | 0 | processIds(nested, seenIds); |
| 379 | |
} |
| 380 | |
} |
| 381 | 0 | } |
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
public static List<? extends Ordered> sort(List<? extends Ordered> items, int defaultOrderSequence) { |
| 402 | 0 | List<Ordered> orderedItems = new ArrayList<Ordered>(); |
| 403 | |
|
| 404 | |
|
| 405 | 0 | Set<Integer> foundOrders = new HashSet<Integer>(); |
| 406 | |
|
| 407 | |
|
| 408 | 0 | Collections.reverse(items); |
| 409 | 0 | for (Ordered component : items) { |
| 410 | 0 | int order = component.getOrder(); |
| 411 | |
|
| 412 | |
|
| 413 | 0 | if (order == 0) { |
| 414 | 0 | orderedItems.add(component); |
| 415 | |
} |
| 416 | |
|
| 417 | 0 | else if (!foundOrders.contains(new Integer(order))) { |
| 418 | 0 | orderedItems.add(component); |
| 419 | 0 | foundOrders.add(new Integer(order)); |
| 420 | |
} |
| 421 | 0 | } |
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | 0 | Collections.reverse(items); |
| 426 | 0 | for (Ordered component : items) { |
| 427 | 0 | int order = component.getOrder(); |
| 428 | |
|
| 429 | |
|
| 430 | 0 | if (order == 0) { |
| 431 | 0 | defaultOrderSequence++; |
| 432 | 0 | while (foundOrders.contains(new Integer(defaultOrderSequence))) { |
| 433 | 0 | defaultOrderSequence++; |
| 434 | |
} |
| 435 | 0 | component.setOrder(defaultOrderSequence); |
| 436 | |
} |
| 437 | 0 | } |
| 438 | |
|
| 439 | |
|
| 440 | 0 | Collections.sort(orderedItems, new OrderComparator()); |
| 441 | |
|
| 442 | 0 | return orderedItems; |
| 443 | |
} |
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
public static String parseExpression(String exp, List<String> controlNames){ |
| 464 | |
|
| 465 | 0 | exp = StringUtils.replace(exp, "!=", " != "); |
| 466 | 0 | exp = StringUtils.replace(exp, "==", " == "); |
| 467 | 0 | exp = StringUtils.replace(exp, ">", " > "); |
| 468 | 0 | exp = StringUtils.replace(exp, "<", " < "); |
| 469 | 0 | exp = StringUtils.replace(exp, "<=", " <= "); |
| 470 | 0 | exp = StringUtils.replace(exp, ">=", " >= "); |
| 471 | 0 | exp = exp.trim(); |
| 472 | |
|
| 473 | 0 | String conditionJs = exp; |
| 474 | 0 | String stack = ""; |
| 475 | 0 | boolean expectingSingleQuote = false; |
| 476 | 0 | boolean ignoreNext = false; |
| 477 | 0 | for(int i = 0; i < exp.length(); i++) { |
| 478 | 0 | char c = exp.charAt(i); |
| 479 | 0 | if(!expectingSingleQuote && !ignoreNext && (c == '(' || c == ' ' || c == ')')){ |
| 480 | 0 | evaluateCurrentStack(stack.trim(), controlNames); |
| 481 | |
|
| 482 | 0 | stack = ""; |
| 483 | 0 | continue; |
| 484 | |
} |
| 485 | 0 | else if(!ignoreNext && c == '\''){ |
| 486 | 0 | stack = stack + c; |
| 487 | 0 | expectingSingleQuote = !expectingSingleQuote; |
| 488 | |
} |
| 489 | 0 | else if(c == '\\'){ |
| 490 | 0 | stack = stack + c; |
| 491 | 0 | ignoreNext = !ignoreNext; |
| 492 | |
} |
| 493 | |
else{ |
| 494 | 0 | stack = stack + c; |
| 495 | 0 | ignoreNext = false; |
| 496 | |
} |
| 497 | |
} |
| 498 | |
|
| 499 | 0 | conditionJs = conditionJs |
| 500 | |
.replaceAll("\\s(?i:ne)\\s", " != ") |
| 501 | |
.replaceAll("\\s(?i:eq)\\s", " == ") |
| 502 | |
.replaceAll("\\s(?i:gt)\\s", " > ") |
| 503 | |
.replaceAll("\\s(?i:lt)\\s", " < ") |
| 504 | |
.replaceAll("\\s(?i:lte)\\s", " <= ") |
| 505 | |
.replaceAll("\\s(?i:gte)\\s", " >= ") |
| 506 | |
.replaceAll("\\s(?i:and)\\s", " && ") |
| 507 | |
.replaceAll("\\s(?i:or)\\s", " || ") |
| 508 | |
.replaceAll("\\s(?i:not)\\s", " != ") |
| 509 | |
.replaceAll("\\s(?i:null)\\s?", " '' ") |
| 510 | |
.replaceAll("\\s?(?i:#empty)\\((.*?)\\)", "isValueEmpty($1)"); |
| 511 | 0 | if(conditionJs.contains("matches")){ |
| 512 | 0 | conditionJs = conditionJs.replaceAll("\\s+(?i:matches)\\s+'.*'", ".match(/" |
| 513 | |
+ "$0" + "/) != null "); |
| 514 | 0 | conditionJs = conditionJs.replaceAll("\\(/\\s+(?i:matches)\\s+'", "(/"); |
| 515 | 0 | conditionJs = conditionJs.replaceAll("'\\s*/\\)", "/)"); |
| 516 | |
} |
| 517 | 0 | for(String propertyName: controlNames){ |
| 518 | 0 | conditionJs = conditionJs.replace(propertyName, |
| 519 | |
"coerceValue(\""+ propertyName +"\")"); |
| 520 | |
} |
| 521 | 0 | return conditionJs; |
| 522 | |
} |
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
private static void evaluateCurrentStack(String stack, List<String> controlNames){ |
| 532 | 0 | if(StringUtils.isNotBlank(stack)){ |
| 533 | 0 | if(!(stack.equals("==") |
| 534 | |
|| stack.equals("!=") |
| 535 | |
|| stack.equals(">") |
| 536 | |
|| stack.equals("<") |
| 537 | |
|| stack.equals(">=") |
| 538 | |
|| stack.equals("<=") |
| 539 | |
|| stack.equalsIgnoreCase("ne") |
| 540 | |
|| stack.equalsIgnoreCase("eq") |
| 541 | |
|| stack.equalsIgnoreCase("gt") |
| 542 | |
|| stack.equalsIgnoreCase("lt") |
| 543 | |
|| stack.equalsIgnoreCase("lte") |
| 544 | |
|| stack.equalsIgnoreCase("gte") |
| 545 | |
|| stack.equalsIgnoreCase("matches") |
| 546 | |
|| stack.equalsIgnoreCase("null") |
| 547 | |
|| stack.equalsIgnoreCase("false") |
| 548 | |
|| stack.equalsIgnoreCase("true") |
| 549 | |
|| stack.equalsIgnoreCase("and") |
| 550 | |
|| stack.equalsIgnoreCase("or") |
| 551 | |
|| stack.contains("#empty") |
| 552 | |
|| stack.startsWith("'") |
| 553 | |
|| stack.endsWith("'"))){ |
| 554 | |
|
| 555 | 0 | boolean isNumber = false; |
| 556 | 0 | if((StringUtils.isNumeric(stack.substring(0,1)) |
| 557 | |
|| stack.substring(0,1).equals("-"))){ |
| 558 | |
try{ |
| 559 | 0 | Double.parseDouble(stack); |
| 560 | 0 | isNumber = true; |
| 561 | |
} |
| 562 | 0 | catch(NumberFormatException e){ |
| 563 | 0 | isNumber = false; |
| 564 | 0 | } |
| 565 | |
} |
| 566 | |
|
| 567 | 0 | if(!(isNumber)){ |
| 568 | 0 | if(!controlNames.contains(stack)){ |
| 569 | 0 | controlNames.add(stack); |
| 570 | |
} |
| 571 | |
} |
| 572 | |
} |
| 573 | |
} |
| 574 | 0 | } |
| 575 | |
|
| 576 | |
public static String getLinePathValue(Component component){ |
| 577 | 0 | CollectionGroup collectionGroup = (CollectionGroup)(component.getContext().get(UifConstants.ContextVariableNames.COLLECTION_GROUP)); |
| 578 | 0 | String linePath = ""; |
| 579 | 0 | if(collectionGroup != null){ |
| 580 | 0 | Object indexObj = component.getContext().get(UifConstants.ContextVariableNames.INDEX); |
| 581 | 0 | if(indexObj != null){ |
| 582 | 0 | int index = (Integer)indexObj; |
| 583 | 0 | boolean addLine = false; |
| 584 | 0 | Object addLineObj = component.getContext().get(UifConstants.ContextVariableNames.IS_ADD_LINE); |
| 585 | |
|
| 586 | 0 | if(addLineObj != null){ |
| 587 | 0 | addLine = (Boolean)addLineObj; |
| 588 | |
} |
| 589 | 0 | if (addLine) { |
| 590 | 0 | linePath = collectionGroup.getAddLineBindingInfo().getBindingPath(); |
| 591 | |
} |
| 592 | |
else { |
| 593 | 0 | linePath = collectionGroup.getBindingInfo().getBindingPath() + "[" + index + "]"; |
| 594 | |
} |
| 595 | |
} |
| 596 | |
} |
| 597 | 0 | return linePath; |
| 598 | |
} |
| 599 | |
|
| 600 | |
public static String replaceLineAttr(String statement, String replacement){ |
| 601 | 0 | if (statement.contains("#line") && StringUtils.isNotEmpty(replacement)) { |
| 602 | 0 | statement = statement.replace("#line?", replacement); |
| 603 | 0 | statement = statement.replace("#line", replacement); |
| 604 | |
} |
| 605 | 0 | return statement; |
| 606 | |
} |
| 607 | |
} |