use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIEditorTreeModel method init.
/**
* takes the assessment object tree and converts it to a QTIEditorTreeModel
*/
private void init() {
Assessment ass = qtiPackage.getQTIDocument().getAssessment();
GenericQtiNode rootNode = new AssessmentNode(ass, qtiPackage);
this.setRootNode(rootNode);
// Sections with their Items
List<Section> sections = ass.getSections();
for (int i = 0; i < sections.size(); i++) {
// get section data
Section elem = sections.get(i);
GenericQtiNode sectionNode = new SectionNode(elem, qtiPackage);
List<Item> items = elem.getItems();
for (int j = 0; j < items.size(); j++) {
// get item data
Item elem2 = 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
rootNode.addChild(sectionNode);
}
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class ItemParser method parse.
/**
* @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;
}
// 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));
} else if (el_feedback.element("hint") != null) {
// fetch hint
Element el_hint = el_feedback.element("hint");
question.setHintText(getMaterialAsString(el_hint));
} else {
QTIObject tmpObj = (QTIObject) parserManager.parse(el_feedback);
if (tmpObj != null)
feedbacks.add(tmpObj);
}
}
return item;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIQPoolServiceProvider method copyItem.
@Override
public void copyItem(QuestionItemFull original, QuestionItemFull copy) {
VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
VFSContainer copyDir = qpoolFileStorage.getContainer(copy.getDirectory());
VFSManager.copyContent(originalDir, copyDir);
VFSLeaf itemLeaf = qpoolService.getRootLeaf(copy);
Item item = QTIEditHelper.readItemXml(itemLeaf);
item.setTitle(copy.getTitle());
QTIEditHelper.serialiazeItem(item, itemLeaf);
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIQPoolServiceProvider method importBeecomItem.
public QuestionItemImpl importBeecomItem(Identity owner, ItemAndMetadata itemAndMetadata, VFSContainer sourceDir, Locale defaultLocale) {
QTIImportProcessor processor = new QTIImportProcessor(owner, defaultLocale);
String editor = null;
String editorVersion = null;
Item item = itemAndMetadata.getItem();
if (!item.isAlient()) {
editor = "OpenOLAT";
editorVersion = Settings.getVersion();
}
Document doc = QTIEditHelper.itemToXml(item);
Element itemEl = (Element) doc.selectSingleNode("questestinterop/item");
QuestionItemImpl qitem = processor.processItem(itemEl, "", null, editor, editorVersion, null, itemAndMetadata);
// save to file System
VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
QTIEditHelper.serialiazeDoc(doc, leaf);
if (sourceDir != null) {
List<String> materials = processor.getMaterials(itemEl);
// copy materials
for (String material : materials) {
VFSItem sourceItem = sourceDir.resolve(material);
if (sourceItem instanceof VFSLeaf) {
VFSLeaf targetItem = baseDir.createChildLeaf(material);
VFSManager.copyContent((VFSLeaf) sourceItem, targetItem);
}
}
}
return qitem;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIQPoolServiceProvider method exportToEditorPackage.
public void exportToEditorPackage(QTIEditorPackageImpl editorPackage, List<QuestionItemShort> items, boolean newTest) {
VFSContainer editorContainer = editorPackage.getBaseDir();
List<Long> itemKeys = toKeys(items);
List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
Section section = editorPackage.getQTIDocument().getAssessment().getSections().get(0);
if (newTest) {
// remove autogenerated question
section.getItems().clear();
}
QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
for (QuestionItemFull fullItem : fullItems) {
Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
Item item = (Item) new ParserManager().parse(itemEl);
item.setIdent(QTIEditHelper.generateNewIdent(item.getIdent()));
section.getItems().add(item);
}
}
Aggregations