use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.
the class ImportRepositoryEntryController method doAnalyseUpload.
private void doAnalyseUpload() {
File uploadedFile = uploadFileEl.getUploadFile();
if (uploadedFile == null) {
// OO-1320
typeEl.setVisible(false);
selectType.setVisible(false);
uploadFileEl.reset();
importButton.setEnabled(false);
} else {
String uploadedFilename = uploadFileEl.getUploadFileName();
List<ResourceHandler> handlers = new ArrayList<>(3);
for (String type : repositoryHandlerFactory.getSupportedTypes()) {
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(type);
ResourceEvaluation eval = handler.acceptImport(uploadedFile, uploadedFilename);
if (eval != null && eval.isValid()) {
handlers.add(new ResourceHandler(handler, eval));
}
}
updateResourceInfos(handlers);
validLimitationOnType(handlers);
}
}
use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.
the class FileResourceTest method scormPackage_withinDirectory.
@Test
public void scormPackage_withinDirectory() throws URISyntaxException {
URL fileUrl = FileResourceTest.class.getResource("very_simple_scorm_in_directory.zip");
File file = new File(fileUrl.toURI());
ResourceEvaluation eval = ScormCPFileResource.evaluate(file, file.getName());
Assert.assertTrue(eval.isValid());
}
use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.
the class FileResourceTest method scormPackage_invalid.
@Test
public void scormPackage_invalid() throws URISyntaxException {
URL fileUrl = FileResourceTest.class.getResource("invalid_scorm.zip");
File file = new File(fileUrl.toURI());
ResourceEvaluation eval = ScormCPFileResource.evaluate(file, file.getName());
Assert.assertFalse(eval.isValid());
}
use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.
the class RepositoryEntriesResource method importFileResource.
private RepositoryEntry importFileResource(Identity identity, File fResource, String resourcename, String displayname, String softkey, int access) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryHandlerFactory handlerFactory = CoreSpringFactory.getImpl(RepositoryHandlerFactory.class);
try {
RepositoryHandler handler = null;
for (String type : handlerFactory.getSupportedTypes()) {
RepositoryHandler h = handlerFactory.getRepositoryHandler(type);
ResourceEvaluation eval = h.acceptImport(fResource, fResource.getName());
if (eval != null && eval.isValid()) {
handler = h;
break;
}
}
RepositoryEntry addedEntry = null;
if (handler != null) {
Locale locale = I18nModule.getDefaultLocale();
addedEntry = handler.importResource(identity, null, displayname, "", true, locale, fResource, fResource.getName());
if (StringHelper.containsNonWhitespace(resourcename)) {
addedEntry.setResourcename(resourcename);
}
if (StringHelper.containsNonWhitespace(softkey)) {
addedEntry.setSoftkey(softkey);
}
if (access < RepositoryEntry.ACC_OWNERS || access > RepositoryEntry.ACC_USERS_GUESTS) {
addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
} else {
addedEntry.setAccess(access);
}
addedEntry = repositoryService.update(addedEntry);
}
return addedEntry;
} catch (Exception e) {
log.error("Fail to import a resource", e);
throw new WebApplicationException(e);
}
}
use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.
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();
}
Aggregations