Search in sources :

Example 66 with VFSContainer

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) DocumentFactory(org.dom4j.DocumentFactory) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) XMLWriter(org.dom4j.io.XMLWriter)

Example 67 with VFSContainer

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);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 68 with VFSContainer

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;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) UploadMedia(org.olat.modules.portfolio.ui.media.UploadMedia) Media(org.olat.modules.portfolio.Media) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact) File(java.io.File)

Example 69 with VFSContainer

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 70 with VFSContainer

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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Media(org.olat.modules.portfolio.Media) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34