Search in sources :

Example 36 with MetaTagged

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

the class CmdZip method formOK.

/**
 * Creates a zipFile by using ZipUtil and fires Event.DONE_EVENT if successful.
 *
 * @see org.olat.core.commons.modules.bc.commands.AbstractCreateItemForm#formOK(org.olat.core.gui.UserRequest)
 */
@Override
protected void formOK(UserRequest ureq) {
    String name = textElement.getValue();
    if (!name.toLowerCase().endsWith(".zip")) {
        name += ".zip";
    }
    VFSItem zipFile = currentContainer.createChildLeaf(name);
    if (zipFile == null) {
        fireEvent(ureq, Event.FAILED_EVENT);
        return;
    }
    List<VFSItem> vfsFiles = new ArrayList<VFSItem>();
    for (String fileName : selection.getFiles()) {
        VFSItem item = currentContainer.resolve(fileName);
        if (item != null) {
            vfsFiles.add(item);
        }
    }
    if (!ZipUtil.zip(vfsFiles, (VFSLeaf) zipFile, true)) {
        // cleanup zip file
        zipFile.delete();
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, FOLDERCOMMAND_FINISHED);
    } else {
        if (zipFile instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) zipFile).getMetaInfo();
            if (info != null) {
                info.setAuthor(ureq.getIdentity());
                info.write();
            }
        }
        fireEvent(ureq, new FolderEvent(FolderEvent.ZIP_EVENT, selection.renderAsHtml()));
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) 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) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 37 with MetaTagged

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

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

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

the class GTASampleSolutionsEditController method doCreateSolutionEditor.

private void doCreateSolutionEditor(UserRequest ureq, Solution solution) {
    String documentName = solution.getFilename();
    VFSItem item = solutionContainer.resolve(documentName);
    if (item == null) {
        item = solutionContainer.createChildLeaf(documentName);
    } else {
        documentName = VFSManager.rename(solutionContainer, documentName);
        item = solutionContainer.createChildLeaf(documentName);
    }
    if (item instanceof MetaTagged) {
        MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
        if (metaInfo != null) {
            metaInfo.setAuthor(getIdentity());
        }
        metaInfo.write();
    }
    newSolutionEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), solutionContainer, documentName, "media", true, true);
    newSolutionEditorCtrl.getRichTextConfiguration().disableMedia();
    newSolutionEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
    newSolutionEditorCtrl.setNewFile(true);
    newSolutionEditorCtrl.setUserObject(solution);
    listenTo(newSolutionEditorCtrl);
    cmc = new CloseableModalController(getWindowControl(), "close", newSolutionEditorCtrl.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 39 with MetaTagged

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

the class GTASampleSolutionsEditController method updateModel.

private void updateModel() {
    List<Solution> solutionList = gtaManager.getSolutions(courseEnv, gtaNode);
    List<SolutionRow> rows = new ArrayList<>(solutionList.size());
    for (Solution solution : solutionList) {
        String filename = solution.getFilename();
        String author = null;
        VFSItem item = solutionContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                author = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        DownloadLink downloadLink = null;
        if (item instanceof VFSLeaf) {
            downloadLink = uifactory.addDownloadLink("file_" + (++linkCounter), filename, null, (VFSLeaf) item, solutionTable);
        }
        rows.add(new SolutionRow(solution, author, downloadLink));
    }
    solutionModel.setObjects(rows);
    solutionTable.reset();
}
Also used : DownloadLink(org.olat.core.gui.components.form.flexible.elements.DownloadLink) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) 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) Solution(org.olat.course.nodes.gta.model.Solution)

Example 40 with MetaTagged

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

the class SubmitDocumentsController method updateModel.

private void updateModel() {
    File[] documents = documentsDir.listFiles(new SystemFileFilter(true, false));
    List<SubmittedSolution> docList = new ArrayList<>(documents.length);
    for (File document : documents) {
        String filename = document.getName();
        String uploadedBy = null;
        VFSItem item = documentsContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                uploadedBy = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        FormItem download;
        if (filename.endsWith(".html")) {
            download = uifactory.addFormLink("view-" + CodeHelper.getRAMUniqueID(), "view", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
            download.setUserObject(filename);
        } else {
            download = uifactory.addDownloadLink("view-" + CodeHelper.getRAMUniqueID(), filename, null, document, tableEl);
        }
        docList.add(new SubmittedSolution(document, uploadedBy, download));
    }
    model.setObjects(docList);
    tableEl.reset();
    if (maxDocs > 0 && docList.size() >= maxDocs) {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(false);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(false);
        }
        String msg = translate("error.max.documents", new String[] { Integer.toString(maxDocs) });
        flc.contextPut("maxDocsWarning", msg);
    } else {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(true);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(true);
        }
        flc.contextPut("maxDocsWarning", Boolean.FALSE);
    }
    flc.contextPut("hasDocuments", Boolean.valueOf(hasUploadDocuments()));
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) 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) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) 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