Package org.olat.ims.qti.editor.beecom.objects

Examples of org.olat.ims.qti.editor.beecom.objects.Item


   * @param trans
   * @return New Multiple Choice item.
   */
  public static Item createMCItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT+":"+ITEM_TYPE_MC+":"+String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");

    // conrols
    Control control = new Control();
    ArrayList controls = new ArrayList();
    controls.add(control);
    newItem.setItemcontrols(controls);
   
    // pepare question
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_MC);
    question.setSingleCorrect(true);
    question.setSingleCorrectScore(1);
   
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice.setCorrect(true);
    newChoice.setPoints(1);
    question.getResponses().add(newChoice);
    newItem.setQuestion(question);
   
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "")

    return newItem;
View Full Code Here


   * @param trans
   * @return New Kprim item.
   */
  public static Item createKPRIMItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT+":"+ITEM_TYPE_KPRIM+":"+String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");

    // controls
    Control control = new Control();
    ArrayList controls = new ArrayList();
    controls.add(control);
    newItem.setItemcontrols(controls);
   
    // prepare question
    float maxValue = 1;
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_KPRIM);
    question.setSingleCorrect(false);
   
    // Kprim has always 4 answers, each of them score 1/4 of the maximum value
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice.setCorrect(false);
    newChoice.setPoints(maxValue/4);
    question.getResponses().add(newChoice);
    ChoiceResponse newChoice2 = new ChoiceResponse();
    newChoice2.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice2.setCorrect(false);
    newChoice2.setPoints(maxValue/4);
    question.getResponses().add(newChoice2);
    ChoiceResponse newChoice3 = new ChoiceResponse();
    newChoice3.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice3.setCorrect(false);
    newChoice3.setPoints(maxValue/4);
    question.getResponses().add(newChoice3);
    ChoiceResponse newChoice4 = new ChoiceResponse();
    newChoice4.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice4.setCorrect(false);
    newChoice4.setPoints(maxValue/4);
    question.getResponses().add(newChoice4);
    question.setMaxValue(maxValue);
    newItem.setQuestion(question);
   
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "")

    return newItem;
View Full Code Here

   * @param trans
   * @return New fib item.
   */
  public static Item createFIBItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT+":"+ITEM_TYPE_FIB+":"+String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");

    // conrols
    Control control = new Control();
    ArrayList controls = new ArrayList();
    controls.add(control);
    newItem.setItemcontrols(controls);
   
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "")
   
    FIBQuestion fibquestion = new FIBQuestion();
    fibquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    fibquestion.setSingleCorrect(true);
    fibquestion.setSingleCorrectScore(1);

    FIBResponse response = new FIBResponse();
    response.setType(FIBResponse.TYPE_CONTENT);
    Material mat = new Material();
    mat.add(new Mattext(trans.translate("editor.newtextelement")));
    response.setContent(mat);
    fibquestion.getResponses().add(response);
    newItem.setQuestion(fibquestion);

    return newItem;
  }
View Full Code Here

   * @param trans
   * @return New essay item.
   */
  public static Item createEssayItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT+":"+ITEM_TYPE_ESSAY+":"+String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");

    // conrols
    Control control = new Control();
    ArrayList controls = new ArrayList();
    controls.add(control);
    newItem.setItemcontrols(controls);
   
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "")
   
    EssayQuestion essayquestion = new EssayQuestion();
    essayquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    essayquestion.setSingleCorrect(true);
    essayquestion.setSingleCorrectScore(1);

    EssayResponse response = new EssayResponse();
    Material mat = new Material();
    mat.add(new Mattext(trans.translate("editor.newtextelement")));
    response.setContent(mat);
    essayquestion.getResponses().add(response);
    newItem.setQuestion(essayquestion);

    return newItem;
  }
View Full Code Here

   */
  public static Control getControl(QTIObject object) {
    Control control = null;
    List controls = null;
    if (Item.class.isAssignableFrom(object.getClass())) {
      Item item = (Item) object;
      controls = item.getItemcontrols();
    } else if (Section.class.isAssignableFrom(object.getClass())) {
      Section section = (Section) object;
      controls = section.getSectioncontrols();
    } else if (Assessment.class.isAssignableFrom(object.getClass())) {
      Assessment assessment = (Assessment) object;
View Full Code Here

   * @return
   */
  private static List<Feedback> getFeedbacks(QTIObject object) {
    List<Feedback> feedbacks = null;
    if (Item.class.isAssignableFrom(object.getClass())) {
      Item item = (Item) object;
      feedbacks = item.getItemfeedbacks();
    } else if (Section.class.isAssignableFrom(object.getClass())) {
      Section section = (Section) object;
      feedbacks = section.getSectionfeedbacks();
    } else if (Assessment.class.isAssignableFrom(object.getClass())) {
      Assessment assessment = (Assessment) object;
View Full Code Here

      Section section = (Section)sectionIterator.next();
      List itemList = section.getItems();
      Iterator listIterator = itemList.iterator();
      while(listIterator.hasNext()) {
        //item
        Item item = (Item)listIterator.next();       
        if((filterOut && thisItem.getIdent().equals(item.getIdent())) || (!filterOut && !thisItem.getIdent().equals(item.getIdent()))) {
          continue;
        }
        //question       
        Material material = item.getQuestion().getQuestion();
        if(material!=null) {
          String htmlContent = material.renderAsHtmlForEditor();
          //parse filenames
          returnSet.addAll(getMediaFileNames(htmlContent));
        }     
        //responses
        List responseList = item.getQuestion().getResponses();
        Iterator responseIterator = responseList.iterator();
        while(responseIterator.hasNext()) {
          Response response = (Response)responseIterator.next();
          Material responseMat = response.getContent();
          //parse filenames
View Full Code Here

  /**
   * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
   */
  public Object parse(Element element) {
    //assert element.getName().equalsIgnoreCase("item");
    Item item = new Item();
    Attribute tmp = element.attribute("ident");
    if (tmp != null)
      item.setIdent(tmp.getValue());
    else
      item.setIdent("" + CodeHelper.getRAMUniqueID());
   
    tmp = element.attribute("title");
    if (tmp != null)
      item.setTitle(tmp.getValue());
   
    tmp = element.attribute("label");
    if (tmp != null)
      item.setLabel(tmp.getValue());
   
    tmp = element.attribute("maxattempts");
    if (tmp != null) {
      try {
        item.setMaxattempts(Integer.parseInt(tmp.getValue()));
      } catch (NumberFormatException nfe) {
        item.setMaxattempts(0);
      }
    }

    // if editor can't handle type of item, just keep raw XML
    if (!(item.getIdent().startsWith(ITEM_PREFIX_SCQ)
    || item.getIdent().startsWith(ITEM_PREFIX_MCQ)
    || item.getIdent().startsWith(ITEM_PREFIX_FIB)
    || item.getIdent().startsWith(ITEM_PREFIX_ESSAY)
    || item.getIdent().startsWith(ITEM_PREFIX_KPRIM))) {
      item.setRawXML(new QTIXMLWrapper(element));
      return item;
    }
   
    // exported olat surveys don't have the correct essay prefix. Search
    // for render_fib that contains rows attribute and convert them to essay
    if (item.getIdent().startsWith(ITEM_PREFIX_FIB)
      && element.selectNodes(".//render_fib[@rows]").size() > 0){
      item.setIdent(item.getIdent().replaceFirst("FIB", "ESSAY"));
    }

   
    // DURATION
    Duration duration =
      (Duration) parserManager.parse(element.element("duration"));
    item.setDuration(duration);

    // CONTROLS
    List itemcontrolsXML = element.elements("itemcontrol");
    List itemcontrols = new ArrayList();
    for (Iterator i = itemcontrolsXML.iterator(); i.hasNext();) {
      itemcontrols.add(parserManager.parse((Element) i.next()));
    }
    if (itemcontrols.size() == 0) {
      itemcontrols.add(new Control());
    }
    item.setItemcontrols(itemcontrols);

    //OBJECTIVES
    Element mattext = (Element)element.selectSingleNode("./objectives/material/mattext");
    if (mattext != null)
      item.setObjectives(mattext.getTextTrim());
   
    // QUESTIONS
    if (item.getIdent().startsWith(ITEM_PREFIX_SCQ))
      item.setQuestion(ChoiceQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_MCQ))
      item.setQuestion(ChoiceQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_FIB))
      item.setQuestion(FIBQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_ESSAY))
      item.setQuestion(EssayQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_KPRIM))
      item.setQuestion(ChoiceQuestion.getInstance(element));
   
    // FEEDBACKS
    List feedbacksXML = element.elements("itemfeedback");
    List feedbacks = new ArrayList();
    item.setItemfeedbacks(feedbacks);
    Question question = item.getQuestion();
    for (Iterator i = feedbacksXML.iterator(); i.hasNext();) {
      Element el_feedback = (Element)i.next();
      if (el_feedback.element("solution") != null) { // fetch solution
        Element el_solution = el_feedback.element("solution");
        question.setSolutionText(getMaterialAsString(el_solution));
View Full Code Here

      Section elem = (Section)sections.get(i);
      GenericQtiNode sectionNode = new SectionNode(elem, qtiPackage);
      List items = elem.getItems();
      for (int j=0; j < items.size(); j++) {
        //get item data
        Item elem2 = (Item)items.get(j);
        GenericQtiNode itemNode = new ItemNode(elem2, qtiPackage);
        //add item to its parent section
        sectionNode.addChild(itemNode);
      }
      //add section with its items to the rootNode
View Full Code Here

   * Creates a new Single Choice item
   * @param trans
   * @return New Singe Choice item.
   */
  public static Item createSCItem(Translator trans) {
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT+":"+ITEM_TYPE_SC+":"+String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    ArrayList controls = new ArrayList();
    controls.add(control);
    newItem.setItemcontrols(controls);

    // pepare question
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(
        trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_SC);
    question.setSingleCorrect(true);
    question.setSingleCorrectScore(1);

    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.setCorrect(true);
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    question.getResponses().add(newChoice);

    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");

    newItem.setQuestion(question);
    return newItem;
  }
View Full Code Here

TOP

Related Classes of org.olat.ims.qti.editor.beecom.objects.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.