use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
the class CSVToQuestionConverter method createMaterialWithText.
private Material createMaterialWithText(String text) {
Material material = new Material();
material.add(createMattext(text));
return material;
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
the class QTIEditHelper method setFeedback.
/**
* Set feedback
* @param object
* @param feedbackString
* @param sIdent
*/
public static void setFeedback(QTIObject object, String feedbackString, String sIdent) {
List<Feedback> feedbacks = getFeedbacks(object);
Feedback feedback = getFeedback(sIdent, feedbacks);
if (feedbackString == null || feedbackString.trim().length() == 0) {
feedbacks.remove(feedback);
return;
}
if (feedback != null) {
feedbackString = feedbackString.trim();
List matList = feedback.getMaterials();
if (matList.size() > 0) {
Material mat = (Material) feedback.getMaterials().get(0);
if (mat == null) {
mat = new Material();
mat.getElements().add(new Mattext(feedbackString));
feedback.getMaterials().add(mat);
} else if (mat.getElements().size() > 0) {
mat.getElements().set(0, new Mattext(feedbackString));
} else {
mat.getElements().add(new Mattext(feedbackString));
}
} else {
Material mat = new Material();
mat.getElements().add(new Mattext(feedbackString));
feedback.getMaterials().add(mat);
}
} else {
Feedback newFeedback = new Feedback();
newFeedback.setIdent(sIdent);
newFeedback.setView("All");
Mattext newMattext = new Mattext(feedbackString);
List<QTIObject> newMattextL = new ArrayList<>();
newMattextL.add(newMattext);
Material material = new Material();
material.setElements(newMattextL);
List<Material> newMaterialL = new ArrayList<>();
newMaterialL.add(material);
newFeedback.setMaterials(newMaterialL);
feedbacks.add(newFeedback);
}
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
the class QTIEditHelper method getFeedbackMaterial.
/**
* @param object
* @param sIdent
* @return
*/
public static Material getFeedbackMaterial(QTIObject object, String sIdent) {
Feedback feedback = getFeedback(object, sIdent);
Material mat = null;
try {
mat = (Material) feedback.getMaterials().get(0);
} catch (NullPointerException e) {
// feedback is null
}
return mat;
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
the class QTIEditHelper method getMediaReferences.
/**
* Retrieves all referenced media by thisItem if filterOut is false,
* or all referenced media by other items if filterOut is true.
* <p>
* Iterates over all sections, items, etc. </br>
* -> if filterOut is true gets all references except those for thisItem.
* -> if filterOut is false gets all references for thisItem.
*
* @param qtiDocument
* @param thisItem
* @param filterOut
* @return Returns empty set if no reference found.
*/
private static Set<String> getMediaReferences(QTIDocument qtiDocument, Item thisItem, boolean filterOut) {
HashSet<String> returnSet = new HashSet<String>();
// sections
List sectionList = qtiDocument.getAssessment().getSections();
Iterator sectionIterator = sectionList.iterator();
while (sectionIterator.hasNext()) {
// section
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
if (responseMat != null) {
returnSet.addAll(getMediaFileNames(responseMat.renderAsHtmlForEditor()));
}
// response-level feedback
Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
if (responseFeedbackMat != null) {
returnSet.addAll(getMediaFileNames(responseFeedbackMat.renderAsHtmlForEditor()));
}
}
// feedback
Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
if (masteryMat != null) {
returnSet.addAll(getMediaFileNames(masteryMat.renderAsHtmlForEditor()));
}
Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
if (failureMat != null) {
returnSet.addAll(getMediaFileNames(failureMat.renderAsHtmlForEditor()));
}
}
}
return returnSet;
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
the class QTIEditHelper method fetchChoices.
/**
* Fetch choices.
* @param response_labels
* @return Map of choices.
*/
public static List<Response> fetchChoices(List response_labels) {
List<Response> choices = new ArrayList<Response>();
for (Iterator i = response_labels.iterator(); i.hasNext(); ) {
ChoiceResponse choice = new ChoiceResponse();
Element response_label = (Element) i.next();
choice.setIdent(response_label.attributeValue("ident"));
List materials = response_label.selectNodes(".//material");
Material content = new Material();
for (Iterator iter = materials.iterator(); iter.hasNext(); ) {
Element el_material = (Element) iter.next();
Material mat = (Material) parserManager.parse(el_material);
content.getElements().addAll(mat.getElements());
}
// assure material always has some content
if (content.getElements().size() == 0) {
content.getElements().add(new Mattext(""));
}
choice.setContent(content);
choices.add(choice);
}
return choices;
}
Aggregations