use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.
the class GlossaryManagerImpl method exportGlossary.
/**
* Exports the glossary resource to the given export directory
*
* @param glossarySoftkey
* @param exportedDataDir
* @return
*/
@Override
public boolean exportGlossary(String glossarySoftkey, File exportedDataDir) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(glossarySoftkey, false);
if (re == null)
return false;
File fExportBaseDirectory = new File(exportedDataDir, EXPORT_FOLDER_NAME);
if (!fExportBaseDirectory.mkdir())
return false;
// export properties
RepositoryEntryImportExport reImportExport = new RepositoryEntryImportExport(re, fExportBaseDirectory);
return reImportExport.exportDoExport();
}
use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.
the class BinderTemplateHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
try {
// create resource
OLATResource resource = portfolioService.createBinderTemplateResource();
OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
File fResourceFileroot = fResourceRootContainer.getBasefile();
File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
FileResource.copyResource(file, filename, zipRoot);
// create repository entry
RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
// import binder
File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
File posterImage = null;
if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
posterImage = new File(zipRoot, transientBinder.getImagePath());
}
portfolioService.importBinder(transientBinder, re, posterImage);
RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
if (rei.anyExportedPropertiesAvailable()) {
re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
}
// delete the imported files
FileUtils.deleteDirsAndFiles(zipRoot, true, true);
return re;
} catch (IOException e) {
log.error("", e);
return null;
}
}
use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.
the class BinderTemplateMediaResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
Binder loadedTemplate = portfolioService.getBinderByKey(template.getKey());
String label = loadedTemplate.getTitle();
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
zout.setLevel(9);
zout.putNextEntry(new ZipEntry("binder.xml"));
BinderXStream.toStream(loadedTemplate, zout);
zout.closeEntry();
if (StringHelper.containsNonWhitespace(loadedTemplate.getImagePath())) {
File posterImage = portfolioService.getPosterImageFile(loadedTemplate);
if (posterImage.exists()) {
zout.putNextEntry(new ZipEntry(loadedTemplate.getImagePath()));
FileUtils.copyFile(posterImage, new ShieldOutputStream(zout));
zout.closeEntry();
}
}
OLATResource resource = templateEntry.getOlatResource();
File baseContainer = FileResourceManager.getInstance().getFileResource(resource);
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(templateEntry, baseContainer);
importExport.exportDoExportProperties(zout);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.
the class AbstractFeedCourseNode method exportNode.
@Override
public void exportNode(File exportDirectory, ICourse course) {
RepositoryEntry re = getReferencedRepositoryEntry();
if (re == null)
return;
// build current export ZIP for feed learning resource
FeedManager.getInstance().getFeedArchive(re.getOlatResource());
// trigger resource file export
File fExportDirectory = new File(exportDirectory, getIdent());
fExportDirectory.mkdirs();
RepositoryEntryImportExport reie = new RepositoryEntryImportExport(re, fExportDirectory);
reie.exportDoExport();
}
use of org.olat.repository.RepositoryEntryImportExport in project openolat by klemens.
the class IQTESTCourseNode method importNode.
@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
RepositoryEntryImportExport rie = new RepositoryEntryImportExport(importDirectory, getIdent());
if (withReferences && rie.anyExportedPropertiesAvailable()) {
File file = rie.importGetExportedFile();
RepositoryHandler handlerQTI21 = RepositoryHandlerFactory.getInstance().getRepositoryHandler(ImsQTI21Resource.TYPE_NAME);
RepositoryEntry re;
if (handlerQTI21.acceptImport(file, "repo.zip").isValid()) {
re = handlerQTI21.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
getModuleConfiguration().set(IQEditController.CONFIG_KEY_TYPE_QTI, IQEditController.CONFIG_VALUE_QTI21);
} else {
RepositoryHandler handlerQTI = RepositoryHandlerFactory.getInstance().getRepositoryHandler(TestFileResource.TYPE_NAME);
re = handlerQTI.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
}
IQEditController.setIQReference(re, getModuleConfiguration());
} else {
IQEditController.removeIQReference(getModuleConfiguration());
}
}
Aggregations