Search in sources :

Example 21 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.

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 22 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.

the class SurveyFileResource method validate.

/**
 * @param unzippedDir
 * @return True if is of type.
 */
public static boolean validate(File unzippedDir) {
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    // getDocument(..) ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    return validateQti(doc, new ResourceEvaluation(false)).isValid();
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 23 with ResourceEvaluation

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

the class CourseHandler method acceptImport.

@Override
public ResourceEvaluation acceptImport(File file, String filename) {
    ResourceEvaluation eval = new ResourceEvaluation();
    try {
        IndexFileFilter visitor = new IndexFileFilter();
        Path fPath = PathUtils.visit(file, filename, visitor);
        if (visitor.isValid()) {
            Path repoXml = fPath.resolve("export/repo.xml");
            if (repoXml != null) {
                eval.setValid(true);
                RepositoryEntryImport re = RepositoryEntryImportExport.getConfiguration(repoXml);
                if (re != null) {
                    eval.setDisplayname(re.getDisplayname());
                    eval.setDescription(re.getDescription());
                }
                eval.setReferences(hasReferences(fPath));
            }
        }
        eval.setValid(visitor.isValid());
        PathUtils.closeSubsequentFS(fPath);
    } catch (IOException | IllegalArgumentException e) {
        log.error("", e);
    }
    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 24 with ResourceEvaluation

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

the class WebDocumentHandler 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)) {
        if (DocFileResource.TYPE_NAME.equals(supportedType) && DocFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (XlsFileResource.TYPE_NAME.equals(supportedType) && XlsFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (PowerpointFileResource.TYPE_NAME.equals(supportedType) && PowerpointFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (PdfFileResource.TYPE_NAME.equals(supportedType) && PdfFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (ImageFileResource.TYPE_NAME.equals(supportedType) && ImageFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (MovieFileResource.TYPE_NAME.equals(supportedType) && MovieFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (SoundFileResource.TYPE_NAME.equals(supportedType) && SoundFileResource.validate(filename)) {
            eval.setValid(true);
        } else if (AnimationFileResource.TYPE_NAME.equals(supportedType) && AnimationFileResource.validate(filename)) {
            eval.setValid(true);
        }
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation)

Example 25 with ResourceEvaluation

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

the class EvaluationFormResource method evaluate.

public static ResourceEvaluation evaluate(File file, String filename) {
    ResourceEvaluation eval = new ResourceEvaluation();
    try {
        FormFileFilter visitor = new FormFileFilter();
        Path fPath = PathUtils.visit(file, filename, visitor);
        if (visitor.isValid()) {
            Path formPath = fPath.resolve(FORM_XML_FILE);
            if (validateForm(formPath)) {
                eval.setValid(true);
            } else {
                eval.setValid(false);
            }
        } 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)

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