Search in sources :

Example 61 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

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;
}
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) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Element(org.dom4j.Element) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document)

Example 62 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class QTIQPoolServiceProvider method extractTextContent.

@Override
public String extractTextContent(QuestionItemFull item) {
    String content = null;
    if (item.getRootFilename() != null) {
        String dir = item.getDirectory();
        VFSContainer container = qpoolFileStorage.getContainer(dir);
        VFSItem file = container.resolve(item.getRootFilename());
        if (file instanceof VFSLeaf) {
            VFSLeaf leaf = (VFSLeaf) file;
            InputStream is = leaf.getInputStream();
            QTI12SAXHandler handler = new QTI12SAXHandler();
            try {
                XMLReader parser = XMLReaderFactory.createXMLReader();
                parser.setContentHandler(handler);
                parser.setEntityResolver(new IMSEntityResolver());
                parser.setFeature("http://xml.org/sax/features/validation", false);
                parser.parse(new InputSource(is));
            } catch (Exception e) {
                log.error("", e);
            } finally {
                FileUtils.closeSafely(is);
            }
            return handler.toString();
        }
    }
    return content;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) XMLReader(org.xml.sax.XMLReader)

Example 63 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : ParserManager(org.olat.ims.qti.editor.beecom.parser.ParserManager) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 64 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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 65 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer 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)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34