Search in sources :

Example 41 with VFSLeaf

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;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Translator(org.olat.core.gui.translator.Translator) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Element(org.dom4j.Element) VFSContainer(org.olat.core.util.vfs.VFSContainer) Document(org.dom4j.Document)

Example 42 with VFSLeaf

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Element(org.dom4j.Element)

Example 43 with VFSLeaf

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);
        }
    }
}
Also used : Path(java.nio.file.Path) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CopyVisitor(org.olat.core.util.PathUtils.CopyVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) YesMatcher(org.olat.core.util.PathUtils.YesMatcher) FileInputStream(java.io.FileInputStream)

Example 44 with VFSLeaf

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) DocumentFactory(org.dom4j.DocumentFactory) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) XMLWriter(org.dom4j.io.XMLWriter)

Example 45 with VFSLeaf

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);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34