예제 #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
  /**
   * Set the (one or more) item texts. Valid for single and multiple texts.
   *
   * @todo FIB, MATCHING TEXT
   * @param itemXml
   * @param itemText text to be updated
   */
  public void setItemTexts(ArrayList itemTextList, Item itemXml) {
    String xPath = "assessmentItem/itemBody";
    if (itemTextList.size() < 1) {
      return;
    }

    String text = ((ItemTextIfc) itemTextList.get(0)).getText();
    log.debug("item text: " + text);
    if (itemXml.isFIB()) {
      //      process fib
      //      return;
    }

    if (itemXml.isFIN()) {
      //      process fin
      //      return;
    }

    try {
      itemXml.update(xPath, text);
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }