コード例 #1
0
  /**
   * Set the answer texts for item.
   *
   * @param itemTextList the text(s) for item
   */
  public void setAnswers(ArrayList itemTextList, Item itemXml) {
    // other types either have no answer or include them in their template
    if (!itemXml.isMatching()
        && !itemXml.isFIB()
        && !itemXml.isFIN()
        && !itemXml.isMCSC()
        && !itemXml.isMCMC()
        && !itemXml.isMCMCSS()
        && !itemXml.isMXSURVEY()) {
      return;
    }
    // OK, so now we are in business.
    String xpath = "assessmentItem/itemBody/choiceInteraction/<simpleChoice";

    List list = itemXml.selectNodes(xpath);
    log.debug("xpath size:" + list.size());
    Iterator nodeIter = list.iterator();

    Iterator iter = itemTextList.iterator();
    Set answerSet = new HashSet();

    char label = 'A';
    int xpathIndex = 1;
    while (iter.hasNext()) {
      answerSet = ((ItemTextIfc) iter.next()).getAnswerSet();
      Iterator aiter = answerSet.iterator();
      while (aiter.hasNext()) {
        AnswerIfc answer = (AnswerIfc) aiter.next();
        if (Boolean.TRUE.equals(answer.getIsCorrect())) {
          this.addCorrectAnswer("" + label, itemXml);
        }
        String value = answer.getText();
        log.debug("answer: " + answer.getText());
        // process into XML
        // we assume that we have equal to or more than the requisite elements
        // if we have more than the existing elements we manufacture more
        // with labels 'A', 'B'....etc.
        Node node = null;
        try {
          boolean isInsert = true;
          if (nodeIter.hasNext()) {
            isInsert = false;
          }

          this.addIndexedEntry(itemXml, xpath, value, isInsert, xpathIndex, "" + label);

        } catch (Exception ex) {
          log.error("Cannot process source document.", ex);
        }

        label++;
        xpathIndex++;
      }
    }
  }
コード例 #2
0
  /**
   * get item type string we use title for this for now
   *
   * @param itemXml
   * @return type as string
   */
  public String getItemType(Item itemXml) {
    String type = "";
    String xpath = "assessmentItem";
    List list = itemXml.selectNodes(xpath);
    if (list.size() > 0) {
      Element element = (Element) list.get(0);
      element.getAttribute(QTIConstantStrings.TITLE);
    }

    return type;
  }
コード例 #3
0
  /**
   * @todo NEED TO SET CORRECT, INCORRECT, GENERAL FEEDBACK Set the feedback texts for item.
   * @param itemTextList the text(s) for item
   */
  public void setFeedback(ArrayList itemTextList, Item itemXml) {
    String xpath = "assessmentItem/itemBody/choiceInteraction/<simpleChoice/feedbackInline";
    // for any answers that are now in the template, create a feedback
    int xpathIndex = 1;
    List list = itemXml.selectNodes(xpath);
    if (list == null) {
      return;
    }

    Iterator nodeIter = list.iterator();
    Iterator iter = itemTextList.iterator();
    Set answerSet = new HashSet();

    char label = 'A';
    boolean first = true;
    while (iter.hasNext()) {
      ItemTextIfc itemTextIfc = (ItemTextIfc) iter.next();

      if (first) // then do once
      {
        // add in Correct and InCorrect Feedback
        String correctFeedback = itemTextIfc.getItem().getCorrectItemFeedback();
        String incorrectFeedback = itemTextIfc.getItem().getInCorrectItemFeedback();
        String generalFeedback = itemTextIfc.getItem().getGeneralItemFeedback();
        log.debug("NEED TO SET CORRECT FEEDBACK: " + correctFeedback);
        log.debug("NEED TO SET INCORRECT FEEDBACK: " + incorrectFeedback);
        log.debug("NEED TO SET GENERAL FEEDBACK: " + incorrectFeedback);
        first = false;
      }

      // answer feedback
      answerSet = itemTextIfc.getAnswerSet();
      Iterator aiter = answerSet.iterator();
      while (aiter.hasNext()) {
        AnswerIfc answer = (AnswerIfc) aiter.next();
        String value = answer.getGeneralAnswerFeedback();
        log.debug("answer feedback: " + answer.getText());
        Node node = null;
        try {
          boolean isInsert = true;
          if (nodeIter.hasNext()) {
            isInsert = false;
          }
          addIndexedEntry(itemXml, xpath, value, isInsert, xpathIndex, null);
        } catch (Exception ex) {
          log.error("Cannot process source document.", ex);
        }

        label++;
        xpathIndex++;
      }
    }
  }
コード例 #4
0
 /**
  * Add minimum score to item XML
  *
  * @param score
  * @param itemXml
  */
 public void addMinScore(Double score, Item itemXml) {
   // normalize if null
   if (score == null) {
     score = Double.valueOf(0);
   }
   // first, set the outcomeDeclaration defaultValue, if it exists
   String xPath = "assessmentItem/responseDeclaration/outcomeDeclaration/defaultValue";
   // test if this is a type that has a defaultValue
   List list = itemXml.selectNodes(xPath);
   if (list == null || list.size() == 0) {
     return;
   }
   updateItemXml(itemXml, xPath, score.toString());
   // next, set the responseElse baseValue, if it exists
   xPath = "assessmentItem/responseCondition/responseElse/" + "setOutcomeValue/baseValue";
   // test if this is a type that has this baseValue
   list = itemXml.selectNodes(xPath);
   if (list == null || list.size() == 0) {
     return;
   }
   updateItemXml(itemXml, xPath, score.toString());
 }