Search in sources :

Example 6 with YesMatcher

use of org.olat.core.util.PathUtils.YesMatcher in project openolat by klemens.

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 7 with YesMatcher

use of org.olat.core.util.PathUtils.YesMatcher in project openolat by klemens.

the class QTI21AssessmentTestHandler method copyResource.

private boolean copyResource(File file, String filename, File targetDirectory) {
    try {
        Path path = FileResource.getResource(file, filename);
        if (path == null) {
            return false;
        }
        Path destDir = targetDirectory.toPath();
        QTI21IMSManifestExplorerVisitor visitor = new QTI21IMSManifestExplorerVisitor();
        Files.walkFileTree(path, visitor);
        Files.walkFileTree(path, new CopyAndConvertVisitor(path, destDir, visitor.getInfos(), new YesMatcher()));
        PathUtils.closeSubsequentFS(path);
        return true;
    } catch (IOException e) {
        log.error("", e);
        return false;
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) YesMatcher(org.olat.core.util.PathUtils.YesMatcher)

Example 8 with YesMatcher

use of org.olat.core.util.PathUtils.YesMatcher in project openolat by klemens.

the class QTI21AssessmentTestHandler method copyOnyxResources.

/**
 * Copy the Onyx assessmentTest, assessmentItems, attachments and media folder.
 *
 * @param onyxZippedDir
 * @param targetDirectory
 * @return true if the copy is successful
 */
private boolean copyOnyxResources(OLATResource onyxResource, File targetDirectory) {
    try {
        // copy files
        File onyxResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(onyxResource).getBasefile();
        File onyxZippedDir = new File(onyxResourceFileroot, FileResourceManager.ZIPDIR);
        Path path = onyxZippedDir.toPath();
        Path destDir = targetDirectory.toPath();
        QTI21IMSManifestExplorerVisitor visitor = new QTI21IMSManifestExplorerVisitor();
        Files.walkFileTree(path, visitor);
        Files.walkFileTree(path, new CopyAndConvertVisitor(path, destDir, visitor.getInfos(), new YesMatcher()));
        return true;
    } catch (IOException e) {
        log.error("", e);
        return false;
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) File(java.io.File) YesMatcher(org.olat.core.util.PathUtils.YesMatcher)

Aggregations

IOException (java.io.IOException)8 Path (java.nio.file.Path)8 YesMatcher (org.olat.core.util.PathUtils.YesMatcher)8 BufferedOutputStream (java.io.BufferedOutputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 CopyVisitor (org.olat.core.util.PathUtils.CopyVisitor)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2