return ERXStringUtilities.attributeValueFromString(attribute, stringValue, context().request().formValueEncoding(), new NSTimestampFormatter());
}
/** Retrieves and executes the fetch specification given in the request. */
public EOFetchSpecification fetchSpecificationFromRequest(String entityName) {
EOFetchSpecification fs = null;
if(context().request().formValueKeys().containsObject(fetchSpecificationKey)) {
String fsName = context().request().stringFormValueForKey(fetchSpecificationKey);
if(ERXStringUtilities.stringIsNullOrEmpty(fsName)) {
EOEntity rootEntity = ERXEOAccessUtilities.entityNamed(session().defaultEditingContext(), entityName);
NSMutableArray qualifiers = new NSMutableArray();
for(Enumeration e = context().request().formValueKeys().objectEnumerator(); e.hasMoreElements(); ) {
String key = (String)e.nextElement();
EOEntity entity = rootEntity;
EOAttribute attribute = null;
String attributeName = key;
if(key.indexOf(".") > 0) {
String path = ERXStringUtilities.keyPathWithoutLastProperty(key);
attributeName = ERXStringUtilities.lastPropertyKeyInKeyPath(key);
entity = ERXEOAccessUtilities.destinationEntityForKeyPath(rootEntity, path);
}
if(entity != null) {
attribute = entity.attributeNamed(attributeName);
if(attribute != null) {
String stringValue = context().request().stringFormValueForKey(key);
if(stringValue != null) {
Object value = null;
NSSelector selector = EOKeyValueQualifier.QualifierOperatorEqual;
if(stringValue.indexOf('*') >= 0) {
selector = EOKeyValueQualifier.QualifierOperatorCaseInsensitiveLike;
}
if(!NSKeyValueCoding.NullValue.toString().equals(stringValue)) {
//AK: I still don't like this...in particular the new NSTimestampFormatter() which would be totally arbitrary...
value = qualifierValueForAttribute(attribute, stringValue);
if(value!=null) {
qualifiers.addObject(new EOKeyValueQualifier(key, selector, value));
}
} else {
qualifiers.addObject(new EOKeyValueQualifier(key, selector, value));
}
}
}
}
}
EOQualifier qualifier = null;
if(qualifiers.count() > 0) {
qualifier = new EOAndQualifier(qualifiers);
}
fs = new EOFetchSpecification(entityName, qualifier, null);
boolean usesDictinct = ERXValueUtilities.booleanValueWithDefault(context().request().stringFormValueForKey(usesDistinctKey), true);
fs.setUsesDistinct(usesDictinct);
int limit = ERXValueUtilities.intValueWithDefault(context().request().stringFormValueForKey(fetchLimitKey), 200);
fs.setFetchLimit(limit);
} else {
fs = EOFetchSpecification.fetchSpecificationNamed(fsName, entityName);
NSMutableDictionary bindings = new NSMutableDictionary();
Enumeration e = fs.qualifier().bindingKeys().objectEnumerator();
while(e.hasMoreElements()) {
String key = (String)e.nextElement();
String formValue = context().request().stringFormValueForKey(key);
if(formValue != null) {
bindings.setObjectForKey(formValue, key);
}
}
if(bindings.count() > 0) {
fs = fs.fetchSpecificationWithQualifierBindings(bindings);
}
}
}
return fs;
}