コード例 #1
0
ファイル: Quiz.java プロジェクト: roddevu/QXmlMoodle
  /**
   * Load XML Quiz moodle format.
   *
   * @param url url of the XML format of an moodle quiz
   * @return true if import success false otherwise
   */
  public final boolean load(final String url) {
    boolean bImportOK = true;
    /* Clear all the question */
    questions.clear();
    /* Load the XML document */
    bImportOK = xmlImporter.load(url);

    /* Import */
    if (bImportOK && (!privLoadQuiz())) {
      questions.clear();
      bImportOK = false;
    }
    /* Load completed */
    return bImportOK;
  }
コード例 #2
0
ファイル: Quiz.java プロジェクト: roddevu/QXmlMoodle
 /** @return the warnings. */
 public final XMLWarnings getWarnings() {
   return xmlImporter.getWarnings();
 }
コード例 #3
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;
  }
コード例 #4
0
ファイル: Quiz.java プロジェクト: roddevu/QXmlMoodle
 /** @return the errors. */
 public final XMLErrors getErrors() {
   return xmlImporter.getErrors();
 }