Search in sources :

Example 86 with MetaTagged

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

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 87 with MetaTagged

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

the class SubmitDocumentsController method doCreateDocumentEditor.

private void doCreateDocumentEditor(UserRequest ureq, String documentName) {
    if (newDocumentEditorCtrl != null)
        return;
    if (maxDocs > 0 && maxDocs <= model.getRowCount()) {
        showWarning("error.max.documents");
    } else {
        VFSItem item = documentsContainer.resolve(documentName);
        if (item == null) {
            documentsContainer.createChildLeaf(documentName);
        } else {
            documentName = VFSManager.rename(documentsContainer, documentName);
            documentsContainer.createChildLeaf(documentName);
        }
        // add missing identity in meta info
        item = documentsContainer.resolve(documentName);
        if (item instanceof MetaTagged) {
            MetaInfo metadata = ((MetaTagged) item).getMetaInfo();
            metadata.setAuthor(ureq.getIdentity());
            metadata.write();
        }
        newDocumentEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), documentsContainer, documentName, "media", true, true);
        newDocumentEditorCtrl.getRichTextConfiguration().disableMedia();
        newDocumentEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
        newDocumentEditorCtrl.setNewFile(true);
        listenTo(newDocumentEditorCtrl);
        cmc = new CloseableModalController(getWindowControl(), "close", newDocumentEditorCtrl.getInitialComponent());
        listenTo(cmc);
        cmc.activate();
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) 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 88 with MetaTagged

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

the class ZipUtil method getAllSubdirs.

/**
 * Get the whole subpath.
 * @param create the missing directories
 * @param base
 * @param subDirPath
 * @return Returns the last container of this subpath.
 */
public static VFSContainer getAllSubdirs(VFSContainer base, String subDirPath, Identity identity, boolean create) {
    StringTokenizer st;
    if (subDirPath.indexOf("/") != -1) {
        st = new StringTokenizer(subDirPath, "/", false);
    } else {
        // try it windows style, backslash is also valid format
        st = new StringTokenizer(subDirPath, "\\", false);
    }
    VFSContainer currentPath = base;
    while (st.hasMoreTokens()) {
        String nextSubpath = st.nextToken();
        VFSItem vfsSubpath = currentPath.resolve(nextSubpath);
        if (vfsSubpath == null && !create) {
            return null;
        }
        if (vfsSubpath == null || (vfsSubpath instanceof VFSLeaf)) {
            vfsSubpath = currentPath.createChildContainer(nextSubpath);
            if (vfsSubpath == null)
                return null;
            if (identity != null && vfsSubpath instanceof MetaTagged) {
                MetaInfo info = ((MetaTagged) vfsSubpath).getMetaInfo();
                if (info != null) {
                    info.setAuthor(identity);
                    info.write();
                }
            }
        }
        currentPath = (VFSContainer) vfsSubpath;
    }
    return currentPath;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) StringTokenizer(java.util.StringTokenizer) 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 89 with MetaTagged

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

the class ZipUtil method unzip.

/**
 * Unzip an inputstream to a directory using the versioning system of VFS
 * @param zipLeaf	The file to unzip
 * @param targetDir	The directory to unzip the file to
 * @param the identity of who unzip the file
 * @param versioning enabled or not
 * @return	True if successfull, false otherwise
 */
private static boolean unzip(InputStream in, VFSContainer targetDir, Identity identity, boolean versioning) {
    ZipInputStream oZip = new ZipInputStream(in);
    try {
        // unzip files
        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 : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) 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)

Example 90 with MetaTagged

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

the class VFSLockManagerImpl method unlock.

/**
 * Unlock the VFS lock only
 */
@Override
public boolean unlock(VFSItem item, Identity identity, Roles roles) {
    if (item instanceof MetaTagged) {
        MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo();
        if (info == null)
            return false;
        info.setLockedBy(null);
        info.setLockedDate(null);
        info.setLocked(false);
        info.write();
        boolean unlocked = false;
        File file = extractFile(item);
        if (file != null && fileLocks.containsKey(file)) {
            LockInfo lock = fileLocks.get(file);
            if (lock.isWebDAVLock()) {
                lock.setVfsLock(false);
            } else {
                if (lock.getWebPath() != null) {
                // LOCK resourceLocks.remove(lock.getWebPath());
                }
                fileLocks.remove(file);
                unlocked = true;
            }
        } else {
            unlocked = true;
        }
        return unlocked;
    }
    return false;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) File(java.io.File)

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