Search in sources :

Example 51 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.

the class ZipUtil method unzipNonStrict.

/**
 * Unzip with jazzlib
 * @param in
 * @param targetDir
 * @param identity
 * @param versioning
 * @return
 */
private static boolean unzipNonStrict(InputStream in, VFSContainer targetDir, Identity identity, boolean versioning) {
    net.sf.jazzlib.ZipInputStream oZip = new net.sf.jazzlib.ZipInputStream(in);
    try {
        // unzip files
        net.sf.jazzlib.ZipEntry oEntr = oZip.getNextEntry();
        while (oEntr != null) {
            if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
                if (oEntr.isDirectory()) {
                    // skip MacOSX specific metadata directory
                    // create directories
                    getAllSubdirs(targetDir, oEntr.getName(), identity, true);
                } else {
                    // create file
                    VFSContainer createIn = targetDir;
                    String name = oEntr.getName();
                    // check if entry has directories which did not show up as
                    // directories above
                    int dirSepIndex = name.lastIndexOf('/');
                    if (dirSepIndex == -1) {
                        // try it windows style, backslash is also valid format
                        dirSepIndex = name.lastIndexOf('\\');
                    }
                    if (dirSepIndex > 0) {
                        // create subdirs
                        createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, true);
                        if (createIn == null) {
                            if (log.isDebug())
                                log.debug("Error creating directory structure for zip entry: " + oEntr.getName());
                            return false;
                        }
                        name = name.substring(dirSepIndex + 1);
                    }
                    if (versioning) {
                        VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
                        if (newEntry == null) {
                            newEntry = createIn.createChildLeaf(name);
                            OutputStream out = newEntry.getOutputStream(false);
                            if (!FileUtils.copy(oZip, out))
                                return false;
                            FileUtils.closeSafely(out);
                        } else if (newEntry instanceof Versionable) {
                            Versionable versionable = (Versionable) newEntry;
                            if (versionable.getVersions().isVersioned()) {
                                versionable.getVersions().addVersion(identity, "", oZip);
                            }
                        }
                        if (newEntry instanceof MetaTagged) {
                            MetaInfo info = ((MetaTagged) newEntry).getMetaInfo();
                            if (info != null) {
                                info.setAuthor(identity);
                                info.write();
                            }
                        }
                    } else {
                        VFSLeaf newEntry = createIn.createChildLeaf(name);
                        if (newEntry != null) {
                            OutputStream out = newEntry.getOutputStream(false);
                            if (!FileUtils.copy(oZip, out))
                                return false;
                            FileUtils.closeSafely(out);
                        }
                        if (newEntry instanceof MetaTagged) {
                            MetaInfo info = ((MetaTagged) newEntry).getMetaInfo();
                            if (info != null && identity != null) {
                                info.setAuthor(identity);
                                info.write();
                            }
                        }
                    }
                }
            }
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
        }
    } catch (IOException e) {
        return false;
    } finally {
        FileUtils.closeSafely(oZip);
    }
    return true;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) ZipOutputStream(java.util.zip.ZipOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) IOException(java.io.IOException) Versionable(org.olat.core.util.vfs.version.Versionable) ZipInputStream(java.util.zip.ZipInputStream)

Example 52 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.

the class GTANotifications method getAuthor.

private String getAuthor(File file, VFSContainer container) {
    String author = null;
    VFSItem item = container.resolve(file.getName());
    if (item instanceof MetaTagged) {
        MetaInfo info = ((MetaTagged) item).getMetaInfo();
        if (info != null) {
            String username = info.getAuthor();
            if (username != null) {
                author = userManager.getUserDisplayName(username);
            }
        }
    }
    return author == null ? "" : author;
}
Also used : 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 53 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.

the class FileHandler method getInformations.

@Override
public MediaInformations getInformations(Object mediaObject) {
    String title = null;
    String description = null;
    if (mediaObject instanceof MetaTagged) {
        MetaInfo meta = ((MetaTagged) mediaObject).getMetaInfo();
        title = meta.getTitle();
        description = meta.getComment();
    }
    return new Informations(title, description);
}
Also used : MediaInformations(org.olat.modules.portfolio.MediaInformations) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo)

Example 54 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.

the class VFSResource method increaseDownloadCount.

@Override
public void increaseDownloadCount() {
    try {
        if (item instanceof VFSLeaf && item instanceof MetaTagged) {
            MetaTagged itemWithMeta = (MetaTagged) item;
            MetaInfo meta = itemWithMeta.getMetaInfo();
            meta.increaseDownloadCount();
            meta.write();
        }
    } catch (Exception e) {
        log.error("Cannot increase download counter: " + item, e);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) IOException(java.io.IOException)

Example 55 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.

the class CmdServeThumbnailResource method execute.

@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    VFSSecurityCallback inheritedSecCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (inheritedSecCallback != null && !inheritedSecCallback.canRead())
        throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
    // extract file
    String path = ureq.getModuleURI();
    MediaResource mr = null;
    VFSLeaf vfsfile = (VFSLeaf) folderComponent.getRootContainer().resolve(path);
    if (vfsfile == null) {
        // double decoding of ++
        vfsfile = (VFSLeaf) FolderCommandHelper.tryDoubleDecoding(ureq, folderComponent);
    }
    if (vfsfile instanceof MetaTagged) {
        MetaInfo info = ((MetaTagged) vfsfile).getMetaInfo();
        if (info != null && info.isThumbnailAvailable()) {
            VFSLeaf thumbnail = info.getThumbnail(200, 200, false);
            if (thumbnail != null) {
                mr = new VFSMediaResource(thumbnail);
            }
        }
    }
    if (mr == null) {
        mr = new NotFoundMediaResource();
    }
    ureq.getDispatchResult().setResultingMediaResource(mr);
    return null;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Aggregations

MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)92 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)86 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 VFSItem (org.olat.core.util.vfs.VFSItem)48 VFSContainer (org.olat.core.util.vfs.VFSContainer)34 File (java.io.File)16 OutputStream (java.io.OutputStream)14 Versionable (org.olat.core.util.vfs.version.Versionable)12 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 MediaResource (org.olat.core.gui.media.MediaResource)10 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)10 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8 BufferedOutputStream (java.io.BufferedOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Test (org.junit.Test)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)6