コード例 #1
0
ファイル: Quiz.java プロジェクト: roddevu/QXmlMoodle
  /**
   * Load a XML quiz.
   *
   * @return true if success false otherwise
   */
  private boolean privLoadQuiz() {
    /* Variable */
    boolean bLoadOk = true;
    Category currentCategory = null;
    /* Check that the root element is "quiz" */
    final Element root = xmlImporter.getRootElement();

    if (!(xmlImporter.isElementName(root, "quiz"))) {
      xmlImporter.getErrors().addBadElement(root, "quiz");
      bLoadOk = false;
    }

    /* Load all the questions if OK */
    final Elements childs = root.getChildElements();
    for (int i = 0; (bLoadOk) && (i < childs.size()); i++) {
      final Element child = childs.get(i);

      if (xmlImporter.isElementName(child, "question")) {

        final String str = child.getAttributeValue("type");
        if (str.equalsIgnoreCase("category")) {
          /* Load category */
          currentCategory = doImportCategory(child);
          /* Check if loaded */
          if (currentCategory == null) {
            bLoadOk = false;
            break;
          }
        } else {
          final QuestionType type = questions.stringToquestionType(str);
          if (type == null) {
            xmlImporter
                .getErrors()
                .addAttrError(
                    child,
                    "type",
                    str,
                    "multichoice|truefalse|"
                        + "shortanswer|matching|cloze|"
                        + "description|calculated|"
                        + "numerical|essay|category");
          } else {
            /* Create the question */
            final AbstractQuestion ques = questions.createQuestion(type);
            ques.setCategory(currentCategory);
            /* Load the question */
            if (!ques.doImport(xmlImporter, child)) {
              bLoadOk = false;
              break;
            }
            /* Add the question */
            questions.add(ques);
          }
        }

      } else {
        xmlImporter.getWarnings().addUnknonwElement(child);
      }
    }
    /* Return */
    return bLoadOk;
  }
コード例 #2
0
ファイル: Quiz.java プロジェクト: roddevu/QXmlMoodle
 /** @return the warnings. */
 public final XMLWarnings getWarnings() {
   return xmlImporter.getWarnings();
 }