use of org.dom4j.DocumentFactory in project OpenOLAT by OpenOLAT.
the class QTIEditHelper method itemToXml.
public static Document itemToXml(Item qtiItem) {
try {
DocumentFactory df = DocumentFactory.getInstance();
Document doc = df.createDocument();
doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD);
Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
doc.setRootElement(questestinteropEl);
qtiItem.addToElement(questestinteropEl);
return doc;
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.dom4j.DocumentFactory in project openolat by klemens.
the class QTIExportProcessor method createSectionBasedAssessment.
private Element createSectionBasedAssessment(String title) {
DocumentFactory df = DocumentFactory.getInstance();
Document doc = df.createDocument();
doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD);
/*
<questestinterop>
<assessment ident="frentix_9_87230240084930" title="SR Test">
*/
Element questestinterop = doc.addElement(QTIConstants.XML_DOCUMENT_ROOT);
Element assessment = questestinterop.addElement("assessment");
assessment.addAttribute("ident", CodeHelper.getGlobalForeverUniqueID());
assessment.addAttribute("title", title);
// metadata
/*
<qtimetadata>
<qtimetadatafield>
<fieldlabel>qmd_assessmenttype</fieldlabel>
<fieldentry>Assessment</fieldentry>
</qtimetadatafield>
</qtimetadata>
*/
Element qtimetadata = assessment.addElement("qtimetadata");
addMetadataField("qmd_assessmenttype", "Assessment", qtimetadata);
// section
/*
<section ident="frentix_9_87230240084931" title="Section">
<selection_ordering>
<selection/>
<order order_type="Sequential"/>
</selection_ordering>
*/
Element section = assessment.addElement("section");
section.addAttribute("ident", CodeHelper.getGlobalForeverUniqueID());
section.addAttribute("title", "Section");
Element selectionOrdering = section.addElement("selection_ordering");
selectionOrdering.addElement("selection");
Element order = selectionOrdering.addElement("order");
order.addAttribute("order_type", "Sequential");
return section;
}
use of org.dom4j.DocumentFactory in project openolat by klemens.
the class QTIImportProcessor method processAssessmentFiles.
protected void processAssessmentFiles(QuestionItemImpl item, ItemInfos itemInfos) {
// a package with an item
String dir = item.getDirectory();
String rootFilename = item.getRootFilename();
VFSContainer container = qpoolFileStorage.getContainer(dir);
VFSLeaf endFile = container.createChildLeaf(rootFilename);
// embed in <questestinterop>
DocumentFactory df = DocumentFactory.getInstance();
Document itemDoc = df.createDocument();
Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
itemDoc.setRootElement(questestinteropEl);
Element deepClone = (Element) itemInfos.getItemEl().clone();
questestinteropEl.add(deepClone);
// write
try {
OutputStream os = endFile.getOutputStream(false);
;
XMLWriter xw = new XMLWriter(os, new OutputFormat(" ", true));
xw.write(itemDoc.getRootElement());
xw.close();
os.close();
} catch (IOException e) {
log.error("", e);
}
// there perhaps some other materials
if (importedFilename.toLowerCase().endsWith(".zip")) {
processAssessmentMaterials(deepClone, container);
}
}
use of org.dom4j.DocumentFactory in project openolat by klemens.
the class QTIEditHelper method itemToXml.
public static Document itemToXml(Item qtiItem) {
try {
DocumentFactory df = DocumentFactory.getInstance();
Document doc = df.createDocument();
doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD);
Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
doc.setRootElement(questestinteropEl);
qtiItem.addToElement(questestinteropEl);
return doc;
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.dom4j.DocumentFactory in project openolat by klemens.
the class TextMarkerManagerImpl method saveToFile.
/**
* @see org.olat.core.gui.control.generic.textmarker.TextMarkerManager#saveToFile(org.olat.core.util.vfs.VFSLeaf,
* java.util.List)
*/
public void saveToFile(VFSLeaf textMarkerFile, List<TextMarker> textMarkerList) {
DocumentFactory df = DocumentFactory.getInstance();
Document doc = df.createDocument();
// create root element with version information
Element root = df.createElement(XML_ROOT_ELEMENT);
root.addAttribute(XML_VERSION_ATTRIBUTE, String.valueOf(VERSION));
doc.setRootElement(root);
// add TextMarker elements
for (TextMarker textMarker : textMarkerList) {
textMarker.addToElement(root);
}
OutputStream stream = textMarkerFile.getOutputStream(false);
try {
XMLWriter writer = new XMLWriter(stream);
writer.write(doc);
writer.close();
stream.close();
} catch (UnsupportedEncodingException e) {
log.error("Error while saving text marker file", e);
} catch (IOException e) {
log.error("Error while saving text marker file", e);
}
}
Aggregations