Index: lams_common/src/java/org/lamsfoundation/lams/tool/OutputFactory.java =================================================================== diff -u -re23eafbb7e9d9b602f8b2ad972a662ba026f328a -r911aa099f3960c3b6cff064f37e7f52533e32ced --- lams_common/src/java/org/lamsfoundation/lams/tool/OutputFactory.java (.../OutputFactory.java) (revision e23eafbb7e9d9b602f8b2ad972a662ba026f328a) +++ lams_common/src/java/org/lamsfoundation/lams/tool/OutputFactory.java (.../OutputFactory.java) (revision 911aa099f3960c3b6cff064f37e7f52533e32ced) @@ -80,6 +80,7 @@ private String languageFilename; private MessageSource msgSource = null; // derived from toolMessageService, loadedMessageSourceService, languageFilename protected final String KEY_PREFIX = "output.desc."; + protected final String CONDITION_NAME_SEPARATOR = "#"; /** Create a map of the tool output definitions, suitable for returning from the method * getToolOutputDefinitions() in the ToolContentManager interface. The class for the toolContentObject @@ -274,4 +275,25 @@ return buildDefinition(definitionName, OutputType.OUTPUT_COMPLEX, null, null, null, Boolean.FALSE); } + /** + * Build a condition name based on a definition name. For user customised conditions, the + * conditions name MUST start with the definition name for Flash to be able to match conditions to definition + * in the authoring interface, but then each condition name needs to be unique, hence "uniquePart". + * @param definitionName: Must not be null + * @param uniquePart: May be null if the condition names are to be the same as the definition name. + * @return combined string + */ + protected String buildConditionName(String definitionName, String uniquePart) { + return uniquePart != null && uniquePart.length() > 0 ? definitionName + CONDITION_NAME_SEPARATOR + uniquePart : definitionName; + } + + /** + * Given a condition name built with buildConditionName, split is back into its definition name and unique part. + * @param conditionName: Must not be null + * @return String[definition name, unique part] + */ + protected String[] splitConditionName(String conditionName) { + int index = conditionName.indexOf(CONDITION_NAME_SEPARATOR); + return new String[] { conditionName.substring(0,index), conditionName.substring(index) }; + } } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteOutputFactory.java =================================================================== diff -u -re78349192758ecdd92d8523b3e58a34a5b210cc2 -r911aa099f3960c3b6cff064f37e7f52533e32ced --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteOutputFactory.java (.../VoteOutputFactory.java) (revision e78349192758ecdd92d8523b3e58a34a5b210cc2) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteOutputFactory.java (.../VoteOutputFactory.java) (revision 911aa099f3960c3b6cff064f37e7f52533e32ced) @@ -45,8 +45,8 @@ public class VoteOutputFactory extends OutputFactory { protected static final String OUTPUT_NAME_NOMINATION_SELECTION = "learner.selection"; - protected static final int FREE_TEXT_DISPLAY_ORDER_FOR_NOMINATION_SELECTION = 0; - protected static final String FREE_TEXT_CONDITION_FOR_NOMINATION_SELECTION = OUTPUT_NAME_NOMINATION_SELECTION+"0"; + protected static final int FREE_TEXT_NOM_SELECTION = 0; + protected static final String FREE_TEXT_NOM_SELECTION_STR = "0"; /** * @see org.lamsfoundation.lams.tool.OutputDefinitionFactory#getToolOutputDefinitions(java.lang.Object) @@ -72,7 +72,8 @@ int conditionOrderId = 1; if ( content.isAllowText() ) { - defaultConditions.add(new BranchCondition(null, null, new Integer(conditionOrderId++), FREE_TEXT_CONDITION_FOR_NOMINATION_SELECTION, + defaultConditions.add(new BranchCondition(null, null, new Integer(conditionOrderId++), + buildConditionName(OUTPUT_NAME_NOMINATION_SELECTION,FREE_TEXT_NOM_SELECTION_STR), getI18NText("label.open.vote", false), OutputType.OUTPUT_BOOLEAN.toString(), null, @@ -84,7 +85,7 @@ while ( iter.hasNext() ) { VoteQueContent nomination = (VoteQueContent) iter.next(); int displayOrder = nomination.getDisplayOrder(); - String name = OUTPUT_NAME_NOMINATION_SELECTION+new Integer(displayOrder).toString(); + String name = buildConditionName(OUTPUT_NAME_NOMINATION_SELECTION,new Integer(displayOrder).toString()); defaultConditions.add(new BranchCondition(null, null, new Integer(conditionOrderId++), name, VoteUtils.stripHTML(nomination.getQuestion()), OutputType.OUTPUT_BOOLEAN.toString(), @@ -134,15 +135,15 @@ */ private boolean checkDisplayOrderOfVoteQueContent(String name, VoteQueUsr queUser) { - String displayOrderString = name.substring(OUTPUT_NAME_NOMINATION_SELECTION.length()); - if ( name.length() <= OUTPUT_NAME_NOMINATION_SELECTION.length()) { + String[] dcNames = splitConditionName(name); + if ( dcNames[1].length() <= OUTPUT_NAME_NOMINATION_SELECTION.length()) { log.error("Unable to convert the display order to an int for tool output "+ OUTPUT_NAME_NOMINATION_SELECTION+". Returning false. Name doesn't contain the display order."+name); return false; } int displayOrder = 0; try { - displayOrder = new Integer(displayOrderString).intValue(); + displayOrder = new Integer(dcNames[1]).intValue(); } catch ( NumberFormatException e) { log.error("Unable to convert the display order to an int for tool output "+ OUTPUT_NAME_NOMINATION_SELECTION+". Returning false. Number format exception thrown. Condition name was:"+name,e); return false; @@ -157,7 +158,7 @@ Iterator iter = voteAttempts.iterator(); while ( iter.hasNext() ) { VoteUsrAttempt attempt = (VoteUsrAttempt) iter.next(); - if ( attempt.getVoteQueContentId().longValue() == 1 && displayOrder == FREE_TEXT_DISPLAY_ORDER_FOR_NOMINATION_SELECTION) { + if ( attempt.getVoteQueContentId().longValue() == 1 && displayOrder == FREE_TEXT_NOM_SELECTION) { // VoteQueContentId == 1 indicates that it is a free text entry return true; } else { @@ -193,14 +194,15 @@ found = ( attempt.getVoteQueContentId().longValue() == 1 ); } } - output.put(FREE_TEXT_CONDITION_FOR_NOMINATION_SELECTION, new ToolOutput(FREE_TEXT_CONDITION_FOR_NOMINATION_SELECTION, i18nDescription, found)); + String name = buildConditionName(OUTPUT_NAME_NOMINATION_SELECTION,FREE_TEXT_NOM_SELECTION_STR); + output.put(name, new ToolOutput(name, i18nDescription, found)); } Iterator contentIter = content.getVoteQueContents().iterator(); while ( contentIter.hasNext() ) { VoteQueContent nomination = (VoteQueContent) contentIter.next(); int displayOrder = nomination.getDisplayOrder(); - String name = OUTPUT_NAME_NOMINATION_SELECTION+new Integer(displayOrder).toString(); + String name = buildConditionName(OUTPUT_NAME_NOMINATION_SELECTION,new Integer(displayOrder).toString()); boolean found = false; if ( queUser != null ) { Set voteAttempts = queUser.getVoteUsrAttempts();