use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.
the class TestFileResource method validate.
/**
* @param unzippedDir
* @return True if is of type.
*/
public static boolean validate(File unzippedDir) {
// no longer needed.
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();
}
use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.
the class FileResourceTest method scormPackage_scosInSubDirectory.
@Test
public void scormPackage_scosInSubDirectory() throws URISyntaxException, IOException {
URL fileUrl = FileResourceTest.class.getResource("scorm_scos_in_sub_directory.zip");
File file = new File(fileUrl.toURI());
ResourceEvaluation eval = ScormCPFileResource.evaluate(file, file.getName());
Assert.assertTrue(eval.isValid());
}
Aggregations