this.setEvalBody(this.proceedValues());
}
private ResultIterator retrieveResultIterator() throws TMLException, WGAPIException {
ResultIterator objectIterator = null;
Status status = (Status) getStatus();
if (status.forEachType.equals("content")) {
ResultSetTagStatus tag;
if (this.getSourcetag() != null) {
tag = (ResultSetTagStatus) this.getTagStatusById(this.getSourcetag(), ResultSetTagStatus.class);
if (tag == null) {
throw new TMLException("Could not find content list tag with id " + this.getSourcetag(), true);
}
}
else if (this.getRelationgroup() != null) {
String group = getRelationgroup();
status.contentLanguage = getTMLContext().content().getLanguage().getName();
return new ResultIterator(getTMLContext().content().getRelationsOfGroup(group));
}
else if (getStatus() instanceof ResultSetTagStatus) {
tag = (ResultSetTagStatus) getStatus();
}
else {
tag = (ResultSetTagStatus) getStatus().getAncestorTag(ResultSetTagStatus.class);
if (tag == null) {
throw new TMLException("No content list tag specified", true);
}
}
objectIterator = tag.getResultIterator();
status.contentLanguage = tag.getResultLanguage();
}
else if (status.forEachType.equals("loop") || status.forEachType.equals("level")) {
int count = 0;
if (status.forEachType.equals("loop")) {
String strCount = this.getCount();
if (strCount == null) {
throw new TMLException("Foreach with type loop but without attribute count", true);
}
count = stringToInteger(strCount, 0);
}
else if (status.forEachType.equals("level")) {
WGContentNavigator nav = new WGContentNavigator(null, new WebTMLLanguageChooser(getTMLContext().db(), getTMLContext()));
count = nav.getContentLevel(this.getTMLContext().content()).intValue();
}
List objects = new java.util.ArrayList();
for (int idx = 0; idx < count; idx++) {
objects.add(new Integer(idx + 1));
}
objectIterator = new ResultIterator(objects.iterator(), objects.size());
}
else if (status.forEachType.equals("itemvalue")) {
Object obj = this.getTMLContext().itemlist(this.getItem());
if (obj == null) {
throw new TMLException("Could not retrieve item " + this.getItem(), true);
}
if (obj instanceof List) {
objectIterator = new ResultIterator((java.util.List) obj);
}
else {
objectIterator = new ResultIterator(java.util.Collections.singletonList(obj));
}
}
else if (status.forEachType.equals("fieldvalue")) {
Object obj=null;
// Register with form parent (if present) and retrieve item values from it;
FormInputRegistrator form = (FormInputRegistrator) getStatus().getAncestorTag(FormBase.class);
if (form != null)
obj=form.getFieldValue(this.getItem(), false, "", false);
else obj = this.getTMLContext().itemlist(this.getItem());
if (obj == null) {
throw new TMLException("Could not retrieve item " + this.getItem(), true);
}
if (obj instanceof List) {
objectIterator = new ResultIterator((java.util.List) obj);
}
else {
objectIterator = new ResultIterator(java.util.Collections.singletonList(obj));
}
}
else if (status.forEachType.equals("tagresult")) {
if (this.getSourcetag() == null) {
throw new TMLException("No tag specified to take tagresult from", true);
}
BaseTagStatus tag = this.getTagStatusById(this.getSourcetag());
if (tag == null) {
throw new TMLException("Could not find tag with id " + this.getSourcetag(), true);
}
Object result = tag.result;
if (de.innovationgate.utils.WGUtils.isCollection(result)) {
objectIterator = new ResultIterator((java.util.Collection) result);
}
else {
objectIterator = new ResultIterator(java.util.Collections.singletonList(result));
}
}
else {
throw new TMLException("Unknown type for foreach tag: " + status.forEachType, true);
}