use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processAssessmentFiles.
protected void processAssessmentFiles(QuestionItemImpl item, ItemInfos itemInfos) {
// a package with an item
String dir = item.getDirectory();
String rootFilename = item.getRootFilename();
VFSContainer container = qpoolFileStorage.getContainer(dir);
VFSLeaf endFile = container.createChildLeaf(rootFilename);
// embed in <questestinterop>
DocumentFactory df = DocumentFactory.getInstance();
Document itemDoc = df.createDocument();
Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
itemDoc.setRootElement(questestinteropEl);
Element deepClone = (Element) itemInfos.getItemEl().clone();
questestinteropEl.add(deepClone);
// write
try {
OutputStream os = endFile.getOutputStream(false);
;
XMLWriter xw = new XMLWriter(os, new OutputFormat(" ", true));
xw.write(itemDoc.getRootElement());
xw.close();
os.close();
} catch (IOException e) {
log.error("", e);
}
// there perhaps some other materials
if (importedFilename.toLowerCase().endsWith(".zip")) {
processAssessmentMaterials(deepClone, container);
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class AssignmentEditController method persistUploadedFiles.
private void persistUploadedFiles() {
if (tempUploadFolder == null)
return;
VFSContainer container = portfolioFileStorage.getAssignmentContainer(assignment);
if (container != null) {
List<VFSItem> tmpFList = tempUploadFolder.getItems(new SystemItemFilter());
for (VFSItem file : tmpFList) {
try {
VFSLeaf leaf = (VFSLeaf) file;
VFSLeaf storedFile = container.createChildLeaf(leaf.getName());
FileUtils.bcopy(leaf.getInputStream(), storedFile.getOutputStream(false), "");
} catch (Exception e) {
logError("", e);
}
}
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class FileHandler method createMedia.
@Override
public Media createMedia(AbstractArtefact artefact) {
Media media = null;
if (artefact instanceof FileArtefact) {
VFSContainer artefactFolder = oldPortfolioManager.getArtefactContainer(artefact);
String filename = ((FileArtefact) artefact).getFilename();
String extension = FileUtils.getFileSuffix(filename);
String type = FILE_TYPE;
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension)) {
type = ImageHandler.IMAGE_TYPE;
}
String businessPath = artefact.getBusinessPath();
if (businessPath == null) {
businessPath = "[PortfolioV2:0][MediaCenter:0]";
}
media = mediaDao.createMedia(artefact.getTitle(), artefact.getDescription(), filename, type, businessPath, artefact.getKey().toString(), artefact.getSignature(), artefact.getAuthor());
ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
File mediaDir = fileStorage.generateMediaSubDirectory(media);
String storagePath = fileStorage.getRelativePath(mediaDir);
mediaDao.updateStoragePath(media, storagePath, filename);
VFSContainer mediaContainer = fileStorage.getMediaContainer(media);
VFSManager.copyContent(artefactFolder, mediaContainer);
}
return media;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class FileHandler method getThumbnail.
@Override
public VFSLeaf getThumbnail(MediaLight media, Size size) {
String storagePath = media.getStoragePath();
VFSLeaf thumbnail = null;
if (StringHelper.containsNonWhitespace(storagePath)) {
VFSContainer storageContainer = fileStorage.getMediaContainer(media);
VFSItem item = storageContainer.resolve(media.getRootFilename());
if (item instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) item;
if (leaf instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
thumbnail = metaInfo.getThumbnail(size.getHeight(), size.getWidth(), true);
}
}
}
return thumbnail;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class MediaDAO method deleteMedia.
public void deleteMedia(Media media) {
if (StringHelper.containsNonWhitespace(media.getRootFilename())) {
VFSContainer container = fileStorage.getMediaContainer(media);
VFSItem item = container.resolve(media.getRootFilename());
if (item instanceof VFSLeaf) {
((VFSLeaf) item).delete();
}
}
Media reloadedMedia = dbInstance.getCurrentEntityManager().getReference(MediaImpl.class, media.getKey());
dbInstance.getCurrentEntityManager().remove(reloadedMedia);
}
Aggregations