use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class QTIQPoolServiceProvider method createItem.
public QuestionItem createItem(Identity owner, QTI12ItemFactory.Type type, String title, Locale defaultLocale) {
Translator trans = Util.createPackageTranslator(QTIEditorMainController.class, defaultLocale);
Item item;
switch(type) {
case sc:
item = QTIEditHelper.createSCItem(trans);
break;
case mc:
item = QTIEditHelper.createMCItem(trans);
break;
case kprim:
item = QTIEditHelper.createKPRIMItem(trans);
break;
case fib:
item = QTIEditHelper.createFIBItem(trans);
break;
case essay:
item = QTIEditHelper.createEssayItem(trans);
break;
default:
return null;
}
item.setLabel(title);
item.setTitle(title);
QTIImportProcessor processor = new QTIImportProcessor(owner, defaultLocale);
Document doc = QTIEditHelper.itemToXml(item);
Element itemEl = (Element) doc.selectSingleNode("questestinterop/item");
QuestionItemImpl qitem = processor.processItem(itemEl, "", null, "OpenOLAT", Settings.getVersion(), null, null);
// save to file System
VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
QTIEditHelper.serialiazeDoc(doc, leaf);
return qitem;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class QTIExportProcessor method exportToQTIEditor.
public Element exportToQTIEditor(QuestionItemFull fullItem, VFSContainer editorContainer) {
ItemsAndMaterials itemAndMaterials = new ItemsAndMaterials();
collectMaterials(fullItem, itemAndMaterials);
if (itemAndMaterials.getItemEls().isEmpty()) {
// nothing found
return null;
}
Element itemEl = itemAndMaterials.getItemEls().get(0);
// write materials
for (ItemMaterial material : itemAndMaterials.getMaterials()) {
String exportPath = material.getExportUri();
VFSLeaf leaf = editorContainer.createChildLeaf(exportPath);
VFSManager.copyContent(material.getLeaf(), leaf);
}
return itemEl;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processItemFiles.
/**
* Process the file of an item's package
* @param item
* @param itemInfos
*/
protected void processItemFiles(QuestionItemImpl item, DocInfos docInfos) {
// a package with an item
String dir = item.getDirectory();
String rootFilename = item.getRootFilename();
VFSContainer container = qpoolFileStorage.getContainer(dir);
if (docInfos != null && docInfos.getRoot() != null) {
try {
Path destDir = ((LocalImpl) container).getBasefile().toPath();
// unzip to container
Path path = docInfos.getRoot();
Files.walkFileTree(path, new CopyVisitor(path, destDir, new YesMatcher()));
} catch (IOException e) {
log.error("", e);
}
} else if (importedFilename.toLowerCase().endsWith(".zip")) {
ZipUtil.unzipStrict(importedFile, container);
} else {
VFSLeaf endFile = container.createChildLeaf(rootFilename);
OutputStream out = null;
FileInputStream in = null;
try {
out = endFile.getOutputStream(false);
in = new FileInputStream(importedFile);
IOUtils.copy(in, out);
} catch (IOException e) {
log.error("", e);
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
}
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
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.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class AssignmentEditController method persistUploadedFiles.
private void persistUploadedFiles() {
if (tempUploadFolder == null)
return;
VFSContainer container = portfolioFileStorage.getAssignmentContainer(assignment);
if (container != null) {
List<VFSItem> tmpFList = tempUploadFolder.getItems(new SystemItemFilter());
for (VFSItem file : tmpFList) {
try {
VFSLeaf leaf = (VFSLeaf) file;
VFSLeaf storedFile = container.createChildLeaf(leaf.getName());
FileUtils.bcopy(leaf.getInputStream(), storedFile.getOutputStream(false), "");
} catch (Exception e) {
logError("", e);
}
}
}
}
Aggregations