Ejemplo n.º 1
0
 public GapText getGapTextByID(String id) {
   for (int i = 0; i < fGapTextList.size(); i++) {
     GapText aGapText = (GapText) fGapTextList.getBasicElementAt(i);
     if (aGapText.getId().equals(id)) return aGapText;
   }
   return null;
 }
Ejemplo n.º 2
0
  public void fromJDOM(Element element) {
    super.fromJDOM(element);

    for (Object attribute : element.getAttributes()) {
      String tag = ((Attribute) attribute).getName();
      String value = ((Attribute) attribute).getValue();

      if (AssessmentElementFactory.IDENTIFIER.equals(tag)) {
        fID = value;
      } else if (AssessmentElementFactory.SHUFFLE.equals(tag)) {
        fShuffle = "true".equalsIgnoreCase(value);
      }
    }

    for (Object o : element.getChildren()) {
      Element child = (Element) o;
      String tag = child.getName();
      // String value = child.getText();

      if (tag.equals(AssessmentElementFactory.GAP_TEXT)) {
        GapText aGapText = new GapText(fAssessmentItem, this);
        aGapText.fromJDOM((Element) child);
        fGapTextList.addElement(aGapText);
      } else if (tag.equals(AssessmentElementFactory.P)) {
        List grandChildren = child.getContent();
        Iterator iterator = grandChildren.iterator();
        Text textString = new Text("");
        while (iterator.hasNext()) {
          Object grandChild = iterator.next();

          if (grandChild instanceof Element) {
            Element e = (Element) grandChild;
            if (e.getName().equals(AssessmentElementFactory.GAP)) {

              Gap aGap = new Gap(fAssessmentItem, this);
              aGap.fromJDOM((Element) grandChild);

              aGap.setStart(textString.getText().length() + 1);

              InterpretationValue aInterpretationValue =
                  getResponseDeclaration().getCorrectResponse();
              for (int i = 0; i < aInterpretationValue.size(); i++) {
                String valueData = aInterpretationValue.getValueAt(i).getData();
                int index = valueData.indexOf(" ");
                if (index != -1) {
                  String targetID = valueData.substring(index + 1);
                  if (targetID.equals(aGap.getId())) {
                    String sourceID = valueData.substring(0, index);
                    GapText aGapText = getGapTextByID(sourceID);
                    aGap.setData(aGapText.getData());
                    aGap.setMatchedGapText(aGapText);
                    aGap.setLength(aGapText.getData().length());
                    if (!aGapText.getData().equals("")) {
                      textString.append(" " + aGapText.getData());
                    } else {
                      System.out.println("correct choice is an empty string");
                    }
                    fGapList.addElement(aGap);
                  }
                }
              }
            }
          } else if (grandChild instanceof Text) {
            textString.append((Text) grandChild);
          }
        }
        data = textString.getText();
      }
    }
  }