Search in sources :

Example 6 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.

the class FileResourceTest method scormPackage.

@Test
public void scormPackage() throws URISyntaxException {
    URL fileUrl = FileResourceTest.class.getResource("very_simple_scorm.zip");
    File file = new File(fileUrl.toURI());
    ResourceEvaluation eval = ScormCPFileResource.evaluate(file, file.getName());
    Assert.assertTrue(eval.isValid());
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 7 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.

the class VideoHandler method acceptImport.

@Override
public ResourceEvaluation acceptImport(File file, String filename) {
    if (!StringHelper.containsNonWhitespace(filename)) {
        filename = file.getName();
    }
    ResourceEvaluation eval = new ResourceEvaluation(false);
    String extension = FileUtils.getFileSuffix(filename);
    if (StringHelper.containsNonWhitespace(extension)) {
        VideoFileResource.validate(file, filename, eval);
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation)

Example 8 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.

the class BinderTemplateResource method evaluate.

public static ResourceEvaluation evaluate(File file, String filename) {
    ResourceEvaluation eval = new ResourceEvaluation();
    try {
        BinderFileFilter visitor = new BinderFileFilter();
        Path fPath = PathUtils.visit(file, filename, visitor);
        if (visitor.isValid()) {
            eval.setValid(true);
            Path repoXml = fPath.resolve(RepositoryEntryImportExport.PROPERTIES_FILE);
            if (Files.exists(repoXml)) {
                RepositoryEntryImport re = RepositoryEntryImportExport.getConfiguration(repoXml);
                if (re != null) {
                    eval.setDisplayname(re.getDisplayname());
                    eval.setDescription(re.getDescription());
                }
            }
        } else {
            eval.setValid(false);
        }
        PathUtils.closeSubsequentFS(fPath);
    } catch (IOException | IllegalArgumentException e) {
        log.error("", e);
        eval.setValid(false);
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) Path(java.nio.file.Path) IOException(java.io.IOException) RepositoryEntryImport(org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport)

Example 9 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.

the class SurveyFileResource method evaluate.

public static ResourceEvaluation evaluate(File file, String filename) {
    ResourceEvaluation eval = new ResourceEvaluation();
    try {
        QTIFileFilter visitor = new QTIFileFilter();
        Path fPath = PathUtils.visit(file, filename, visitor);
        if (visitor.isValid()) {
            Path qtiPath = fPath.resolve(QTI_FILE);
            Document doc = QTIHelper.getDocument(qtiPath);
            validateQti(doc, eval);
        } else {
            eval.setValid(false);
        }
        PathUtils.closeSubsequentFS(fPath);
    } catch (IOException | IllegalArgumentException e) {
        log.error("", e);
        eval.setValid(false);
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) Path(java.nio.file.Path) IOException(java.io.IOException) Document(org.dom4j.Document)

Example 10 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.

the class TestFileResource method evaluate.

public static ResourceEvaluation evaluate(File file, String filename) {
    ResourceEvaluation eval = new ResourceEvaluation();
    try {
        QTIFileFilter visitor = new QTIFileFilter();
        Path fPath = PathUtils.visit(file, filename, visitor);
        if (visitor.isValid()) {
            Path qtiPath = fPath.resolve(QTI_FILE);
            Document doc = QTIHelper.getDocument(qtiPath);
            validateQti(doc, eval);
        } else {
            eval.setValid(false);
        }
        PathUtils.closeSubsequentFS(fPath);
    } catch (IOException | IllegalArgumentException e) {
        log.error("", e);
        eval.setValid(false);
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) Path(java.nio.file.Path) IOException(java.io.IOException) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument)

Aggregations

ResourceEvaluation (org.olat.fileresource.types.ResourceEvaluation)30 File (java.io.File)10 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 URL (java.net.URL)8 Document (org.dom4j.Document)8 Test (org.junit.Test)8 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)4 RepositoryEntryImport (org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport)4 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)4 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryService (org.olat.repository.RepositoryService)2 RepositoryHandlerFactory (org.olat.repository.handlers.RepositoryHandlerFactory)2