public NSArray localList() { if (indexItem == null) return null; NSDictionary local = (NSDictionary) indexItem.valueForKey("local"); if (local == null) return null; NSArray result = (NSArray) local.valueForKey("list"); if (result != null) return result; String entityName = (String) local.valueForKey("entityName"); if (entityName != null) { EOQualifier qual = null; String qualifier = (String) local.valueForKey("qualifier"); if (qualifier != null) { NSArray args = (NSArray) local.valueForKey("args"); if (args != null && args.count() > 0) { Object[] a = new Object[args.count()]; for (int i = 0; i < a.length; i++) { a[i] = DisplayAny.ValueReader.evaluateValue(args.objectAtIndex(i), plist, this); } args = new NSArray(a); } qual = EOQualifier.qualifierWithQualifierFormat(qualifier, args); } NSArray sorter = (NSArray) local.valueForKey("sorter"); if (sorter != null && sorter.count() > 0) { Object[] s = new Object[sorter.count()]; for (int i = 0; i < s.length; i++) { Object sort = sorter.objectAtIndex(i); if (sort instanceof String) { s[i] = new EOSortOrdering((String) sort, EOSortOrdering.CompareAscending); } else { NSDictionary so = (NSDictionary) sort; String key = (String) so.valueForKey("key"); String order = (String) so.valueForKey("order"); s[i] = new EOSortOrdering(key, EOSortOrdering._operatorSelectorForString(order)); } } sorter = new NSArray(s); } EOFetchSpecification fs = new EOFetchSpecification(entityName, qual, sorter); result = ec.objectsWithFetchSpecification(fs); } else if (local.valueForKey("methodName") != null) result = (NSArray) DisplayAny.ValueReader.evaluateDict(local, plist, this); if (result != null) { String uniq = (String) local.valueForKey("uniqueAttribute"); if (uniq != null) { NSMutableArray res = new NSMutableArray(); for (int i = 0; i < result.count(); i++) { Object obj = NSKeyValueCodingAdditions.Utility.valueForKeyPath(result.objectAtIndex(i), uniq); if (obj instanceof String) obj = WOMessage.stringByEscapingHTMLString((String) obj); if (!res.containsObject(obj)) res.addObject(obj); } result = res; } } local.takeValueForKey(result, "list"); return result; }
private String localValue() { if (item1 == null || item1 instanceof String) { return (String) item1; } else { String path = (String) indexItem.valueForKeyPath("local.valuePath"); if (path == null) { return MyUtility.getID((EOEnterpriseObject) item1); } else { return NSKeyValueCodingAdditions.Utility.valueForKeyPath(item1, path).toString(); } } }
@Override public boolean evaluateWithObject(Object object) { Object destinationValue = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, relationshipName); if (destinationValue != null) { if (destinationValue instanceof NSArray) { NSArray arr = (NSArray) destinationValue; return EOQualifier.filteredArrayWithQualifier(arr, qualifier).count() > 0; } return qualifier.evaluateWithObject(destinationValue); } return false; }
/** * Creates a dictionary from an objects and an array of key paths * * @param object object to pull the values from * @param keys array of keys * @return NSDictionary containing all of the object-key pairs. */ public static NSDictionary<String, Object> dictionaryFromObjectWithKeys( Object object, NSArray<String> keys) { NSMutableDictionary<String, Object> result = new NSMutableDictionary<String, Object>(); if (object != null && keys != null) { for (Enumeration<String> e = keys.objectEnumerator(); e.hasMoreElements(); ) { String key = e.nextElement(); Object value = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, key); if (value != null) { result.setObjectForKey(value, key); } } } return result.immutableClone(); }
public String value1() { if (item1 == null) return null; if (item1 instanceof String) return (String) item1; String format = (String) indexItem.valueForKeyPath("local.titlePath"); if (format != null) return WOMessage.stringByEscapingHTMLString( (String) NSKeyValueCodingAdditions.Utility.valueForKeyPath(item1, format)); format = (String) indexItem.valueForKeyPath("local.format"); if (format == null) return item1.toString(); NSArray fa = (NSArray) indexItem.valueForKeyPath("local.formatArgs"); Object[] args = null; if (fa != null && fa.count() > 0) { args = new Object[fa.count()]; for (int i = 0; i < args.length; i++) { args[i] = DisplayAny.ValueReader.evaluateValue(fa.objectAtIndex(i), item1, this); } } return WOMessage.stringByEscapingHTMLString(String.format(format, args)); }
public NSArray selections() { if (_selections == null) { NSArray oldValues = (NSArray) NSKeyValueCodingAdditions.Utility.valueForKeyPath(sourceObject(), relationshipKey()); if (oldValues != null) { if (oldValues.lastObject() instanceof EOEnterpriseObject) { oldValues = ERXEOControlUtilities.localInstancesOfObjects(editingContext(), oldValues); } } setSelections(oldValues); // deal with isMandatory if ((_selections == null) && isMandatory()) { if (theList().count() > 0) { Object anObject = theList().objectAtIndex(0); setSelections(new NSArray(anObject)); } } } return _selections; }
/** * Overridden to handle case of in-memory evaluation of QualifierOperatorContains selector and a * keyPath that has multiple toMany and/or manyToMany-flattened relationships resulting in arrays * of arrays rather than an array of discrete objects. In that case the object is evaluated * against a flattened array which gives the same result as SQL evaluation. * * <p>Since legacy code may depend on workarounds to the incorrect behavior, this patch can be * disabled by setting the property <code>er.extensions.ERXKeyValueQualifier.Contains.flatten * </code> to <code>false</code> */ @Override public boolean evaluateWithObject(Object object) { Object objectValue = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, _key); if (_value instanceof EOQualifierVariable) { throw new IllegalStateException( "Error evaluating qualifier with key " + _key + ", selector " + _selector + ", value " + _value + " - value must be substitued for variable before evaluating"); } if (_selector.equals(EOQualifier.QualifierOperatorCaseInsensitiveLike)) { if (_lowercaseCache == null) { _lowercaseCache = (_value != NSKeyValueCoding.NullValue) ? (_value.toString()).toLowerCase() : ""; } return _NSStringUtilities.stringMatchesPattern( ((objectValue != null) && (objectValue != NSKeyValueCoding.NullValue)) ? objectValue.toString() : "", _lowercaseCache, true); } // Flatten in case we have array of arrays if (_selector.equals(EOQualifier.QualifierOperatorContains) && PROPERTIES.shouldFlattenValueObject && objectValue != null && objectValue instanceof NSArray) { objectValue = ERXArrayUtilities.flatten((NSArray<?>) objectValue); } return ComparisonSupport.compareValues( (objectValue != null) ? objectValue : NSKeyValueCoding.NullValue, _value, _selector); }