for (CommandEntry commandEntry : sortedCommandEntries) {
List<DisplayableInteractionContent> nestedInteractionList = null;
CommandEntryExtender<?> commandEntryExtender = commandEntryManager.createCommandEntryExtender(commandEntry);
String toolTipKey = commandEntryExtender.getTooltipKey();
DisplayableInteractionContent interaction = new DisplayableInteractionContent();
interaction.setToolTip(messages.getString(toolTipKey));
interaction.setComment(commandEntry instanceof CommentCommandEntry);
interaction.setCommandEntry(commandEntry);
SortLabel sortLabel = new SortLabel(commandEntry.getSortLabel());
interaction.setSortLabel(sortLabel);
interaction.setSortLabelStack(sortLabelStack);
interaction.setSortLabelDescription(sortLabelStack.stringRepresentation(sortLabel));
interaction.setEditable(sortLabelStack.isEmpty());
interaction.setInteractionDescription(commandEntryExtender.readableCommandDescription(req));
if (commandEntry instanceof FragmentCommandEntry){
interaction.setFragment(!expandFragments);
interaction.setExpandedFragment(expandFragments);
}
int indentation = enclosingIndentation + sortLabel.branchLevel();
interaction.setIndentation(indentation); // statements are indented according to the label depth
commandMap.put(interaction.getIndentation(), commandEntryExtender);
boolean withinLoop = listWithinLoop || loopLabel != null && sortLabel.nestedIn(loopLabel,"a");
boolean contactAvailable = contactAvailableWithinList || contactAssignLabel != null && sortLabel.nestedIn(contactAssignLabel,"a");
// check for illegal sort label continuation
if (!sortLabel.isAllowedAfter(previousCommandEntry != null ? new SortLabel(previousCommandEntry.getSortLabel()) : null)) {
// if label is not allowed here we set an error for the label
// but add it nevertheless to the list. Conditions and other stuff is ignored,
// also it is not used as the previous entry but the old previous entry is kept.
interaction.setError(true);
interaction.setErrorDescription(messages.getString("smssvc.labelNotAllowedHere"));
interactionList.add(interaction);
continue;
}
// check for interactions after break
if (breakLabel != null && !(commandEntry instanceof CommentCommandEntry) && sortLabel.follows(breakLabel)){
interaction.setError(true);
interaction.setErrorDescription(messages.getString("smssvc.UnreachableInteraction"));
} else if (commandEntry instanceof BreakCommandEntry){
breakLabel = sortLabel;
}
// add operation prefix to interaction log descriptions and check for empty operation values unless the list is a fragment
if (commandEntry instanceof InteractionLogCommandEntry){
InteractionLogCommandEntry interactionLogCommandEntry = (InteractionLogCommandEntry)commandEntry;
if (!interaction.isError() && !isFragment && operationPrefix == null && interactionLogCommandEntry.getOperation() == null){
interaction.setError(true);
interaction.setErrorDescription(messages.getString("smssvc.OperationValueMissing"));
}
interaction.setInteractionDescription(((InteractionLogCommandEntryExtender) commandEntryExtender).readableCommandDescription(req,operationPrefix));
}
// expand and check fragments and include if required
if (commandEntry instanceof FragmentCommandEntry){
FragmentCommandEntry fragmentCommandEntry = (FragmentCommandEntry)commandEntry;
Fragment fragment = fragmentCommandEntry.getFragment();
if (expandFragments){
interaction.setInteractionDescription(((FragmentCommandEntryExtender) commandEntryExtender).readableCommandDescription(req,false)); // do not show operation prefix, because it will be visible in the embedded entries
}
SortedSet<CommandEntry> sortedFragmentCommandEntries = CommandEntryManager.sortedCommandEntries(fragment.getCommandEntries());
String addedOperationPrefix = fragmentCommandEntry.getOperationPrefix();
String combinedOperationPrefix = operationPrefix == null ? addedOperationPrefix : (operationPrefix + (addedOperationPrefix == null ? "" : addedOperationPrefix));
nestedInteractionList = subInteractionList(req, group, sortedFragmentCommandEntries,isFragment, expandFragments, withinLoop, contactAvailable, combinedOperationPrefix,
indentation, new SortLabelStack(sortLabelStack,sortLabel));
if (nestedInteractionList == null){
if (!interaction.isError()){
interaction.setError(true);
interaction.setErrorDescription(ResourceBundle.getBundle("SmsServices", locale).getString("TooManyNestingLevels"));
}
} else if (!interaction.isError()){
if (!expandFragments){ // check for nested errors
for (DisplayableInteractionContent displayableInteractionContent : nestedInteractionList) {
if (displayableInteractionContent.isError()){
interaction.setError(true);
interaction.setErrorDescription(ResourceBundle.getBundle("SmsServices", locale).getString("ExpandFragmentsToSeeWarningMessages"));
break;
}
}
}
if (!interaction.isError()){ // check for last command at base level and assume branch result, tool tip and assign/parse/break labels
if (nestedInteractionList.size() >= 1){
DisplayableInteractionContent lastFragmentInteraction = nestedInteractionList.get(nestedInteractionList.size() - 1);
if (lastFragmentInteraction != null
&& !(lastFragmentInteraction.getCommandEntry() instanceof IterateCommandEntry)
&& (lastFragmentInteraction.getSortLabel().branchLevel() == 0)){
CommandEntry lastFragmentCommandEntry = lastFragmentInteraction.getCommandEntry();
if (lastFragmentCommandEntry instanceof BreakCommandEntry){
breakLabel = sortLabel;
}
interaction.setToolTip(lastFragmentInteraction.getToolTip()); // behave like last fragment interaction concerning tool tip and conditions
CommandEntryExtender lastFragmentCommandEntryExtender = commandEntryManager.createCommandEntryExtender(lastFragmentCommandEntry);
commandMap.put(interaction.getIndentation(), lastFragmentCommandEntryExtender);
if (!contactAvailable && lastFragmentCommandEntryExtender.assignsContact()){
contactAssignLabel = sortLabel;
}
}
}
}
}
}
// check for outer loops and current user set access outside of loops
if (commandEntry instanceof IterateCommandEntry){
if (!withinLoop){
loopLabel = sortLabel;
}
} else if (!interaction.isError() && !withinLoop && commandEntryExtender.requiresCurrentUserSet()){
interaction.setError(true);
interaction.setErrorDescription(messages.getString("smssvc.AccessedCurrentUserSetIsNotAvailable"));
}
// check for available contact user; no checks and prefix setting if contact already available
if (!contactAvailable){ // both contact user assigning interactions return "a" in case of success
if (!interaction.isError() && commandEntryExtender.requiresContactUser()){
interaction.setError(true);
interaction.setErrorDescription(messages.getString("smssvc.AccessedContactMayNotBeAvailable"));
}
if (commandEntryExtender.assignsContact()){
contactAssignLabel = sortLabel;
}
}
// check if command not usuable in this list by creating a command entry with the dummy event parameters
if (!interaction.isError() && eventParameters != null && commandEntryExtender.createCommand(eventParameters, new EventVariables(eventParameters), null) == null){
interaction.setError(true);
interaction.setErrorDescription(messages.getString("InteractionNotAllowedInThisInteractionList"));
}
// add condition entries if appropriate
if (previousCommandEntry != null) {
String condString = commandEntryManager.getCondition(previousCommandEntry, commandEntry);
String baseStringRepresentation = sortLabel.getBaseStringRepresentation();
if (condString != null && !labelsUsedForCondition.contains(baseStringRepresentation)) {
DisplayableInteractionContent condition = new DisplayableInteractionContent();
condition.setIndentation(interaction.getIndentation() - 1); // indent one less than statement itself
condition.setCondition(true);
CommandEntryExtender parentCommand = commandMap.get(interaction.getIndentation()-1);
if (parentCommand != null) {
if (parentCommand instanceof UpcallCommandEntryExtender){
condition.setInteractionDescription(messages.getString(parentCommand.getTooltipKey())+" '"+condString+"':");
} else if (parentCommand instanceof HttpCommandEntryExtender) {
if (condString.startsWith("a")){
condition.setInteractionDescription(messages.getString(parentCommand.getTooltipKey() + "_a___") + (condString.length() >= 2 ? (" (" + condString.substring(1) + ")") : ""));
if (((HttpCommandEntryExtender)parentCommand).getCommandEntry().getNofEvaluatedResponseLetters() < condString.length() - 1) {
condition.setError(true);
condition.setErrorDescription(messages.getString("smssvc.unreachableBranch"));
}
} else if (condString.equals("b")){
condition.setInteractionDescription(messages.getString(parentCommand.getTooltipKey() + "_b"));
} else {
condition.setInteractionDescription( messages.getString("smssvc.unreachableBranch"));
condition.setError(true);
condition.setErrorDescription(messages.getString("smssvc.unreachableBranch"));
}
} else if (parentCommand instanceof ImageRecognitionCommandEntryExtender) {
try {
condition.setInteractionDescription(messages.getString("smssvc.imageRecognition." + condString) + ":");
} catch (Exception e) {
condition.setInteractionDescription( messages.getString("smssvc.unreachableBranch"));
condition.setError(true);
condition.setErrorDescription(messages.getString("smssvc.unreachableBranch"));
}
} else {
String conditionKeyBase = parentCommand.getTooltipKey();
String conditionKey = conditionKeyBase + "_" + condString;
String conditionDescription = condString;
try {
conditionDescription = messages.getString(conditionKey);
} catch (Exception e) {
conditionDescription = messages.getString("smssvc.unreachableBranch");
condition.setError(true);
condition.setErrorDescription(conditionDescription);
}
condition.setInteractionDescription(conditionDescription);
}
interactionList.add(condition);
labelsUsedForCondition.add(baseStringRepresentation);
}
}