Search in sources :

Example 56 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.

the class VersionsFileManager method cleanUp.

/**
 * Clean up all revisions files, xml file
 * @param leaf
 */
private void cleanUp(VFSLeaf leaf) {
    String relPath = getRelPath(leaf);
    // cannot handle
    if (relPath == null)
        return;
    File fVersion = new File(getRootVersionsFile(), relPath + ".xml");
    File fParentVersion = fVersion.getParentFile();
    // already deleted
    if (!fParentVersion.exists())
        return;
    VFSLeaf versionLeaf = null;
    if (fVersion.exists()) {
        LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
        versionLeaf = (VFSLeaf) localVersionContainer.resolve(fVersion.getName());
    }
    // already deleted
    if (versionLeaf == null)
        return;
    Versions versions = readVersions(leaf, versionLeaf);
    for (VFSRevision versionToDelete : versions.getRevisions()) {
        RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
        VFSLeaf fileToDelete = versionImpl.getFile();
        if (fileToDelete != null) {
            fileToDelete.delete();
        }
    }
    versionLeaf.delete();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 57 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.

the class VersionsFileManager method getRootVersionsFile.

public File getRootVersionsFile() {
    if (rootVersionsContainer == null) {
        rootVersionFolder = new File(FolderConfig.getCanonicalVersionRoot());
        if (!rootVersionFolder.exists()) {
            rootVersionFolder.mkdirs();
        }
        rootVersionsContainer = new LocalFolderImpl(rootVersionFolder);
    }
    return rootVersionFolder;
}
Also used : File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 58 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.

the class DialogCourseNode method doArchiveElement.

/**
 * Archive a single dialog element with files and forum
 * @param element
 * @param exportDirectory
 */
public void doArchiveElement(DialogElement element, File exportDirectory, Locale locale) {
    DialogElementsManager depm = CoreSpringFactory.getImpl(DialogElementsManager.class);
    VFSContainer dialogContainer = depm.getDialogContainer(element);
    // there is only one file (leave) in the top forum container
    VFSItem dialogFile = dialogContainer.getItems(new VFSLeafFilter()).get(0);
    VFSContainer exportContainer = new LocalFolderImpl(exportDirectory);
    // append export timestamp to avoid overwriting previous export
    String exportDirName = Formatter.makeStringFilesystemSave(getShortTitle()) + "_" + element.getForum().getKey() + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    VFSContainer diaNodeElemExportContainer = exportContainer.createChildContainer(exportDirName);
    // don't check quota
    diaNodeElemExportContainer.setLocalSecurityCallback(new FullAccessCallback());
    diaNodeElemExportContainer.copyFrom(dialogFile);
    ForumArchiveManager fam = ForumArchiveManager.getInstance();
    ForumFormatter ff = new ForumRTFFormatter(diaNodeElemExportContainer, false, locale);
    fam.applyFormatter(ff, element.getForum().getKey(), null);
}
Also used : ForumFormatter(org.olat.modules.fo.archiver.formatters.ForumFormatter) FullAccessCallback(org.olat.core.util.vfs.callbacks.FullAccessCallback) ForumArchiveManager(org.olat.modules.fo.archiver.ForumArchiveManager) ForumRTFFormatter(org.olat.modules.fo.archiver.formatters.ForumRTFFormatter) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) DialogElementsManager(org.olat.course.nodes.dialog.DialogElementsManager) Date(java.util.Date) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 59 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.

the class IQ12EditForm method update.

/**
 * Update the module configuration from the qti file: read min/max/cut values
 * @param res
 */
protected void update(OLATResource res) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedRoot = frm.unzipFileResource(res);
    // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    if (vfsQTI == null) {
        throw new AssertException("qti file did not exist even it should be guaranteed by repositor check-in ");
    }
    // ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    if (doc == null) {
        // error reading qti file (existence check was made before)
        throw new AssertException("qti file could not be read " + ((LocalFileImpl) vfsQTI).getBasefile().getAbsolutePath());
    }
    // Extract min, max and cut value
    Float minValue = null, maxValue = null, cutValue = null;
    Element decvar = (Element) doc.selectSingleNode("questestinterop/assessment/outcomes_processing/outcomes/decvar");
    if (decvar != null) {
        Attribute minval = decvar.attribute("minvalue");
        if (minval != null) {
            String mv = minval.getValue();
            try {
                minValue = new Float(Float.parseFloat(mv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
        Attribute maxval = decvar.attribute("maxvalue");
        if (maxval != null) {
            String mv = maxval.getValue();
            try {
                maxValue = new Float(Float.parseFloat(mv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
        Attribute cutval = decvar.attribute("cutvalue");
        if (cutval != null) {
            String cv = cutval.getValue();
            try {
                cutValue = new Float(Float.parseFloat(cv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
    }
    // Put values to module configuration
    minScoreEl.setValue(minValue == null ? "" : AssessmentHelper.getRoundedScore(minValue));
    minScoreEl.setVisible(minValue != null);
    maxScoreEl.setValue(maxValue == null ? "" : AssessmentHelper.getRoundedScore(maxValue));
    maxScoreEl.setVisible(maxValue != null);
    cutValueEl.setValue(cutValue == null ? "" : AssessmentHelper.getRoundedScore(cutValue));
    cutValueEl.setVisible(cutValue != null);
}
Also used : AssertException(org.olat.core.logging.AssertException) FileResourceManager(org.olat.fileresource.FileResourceManager) Attribute(org.dom4j.Attribute) VFSContainer(org.olat.core.util.vfs.VFSContainer) SelectionElement(org.olat.core.gui.components.form.flexible.elements.SelectionElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Element(org.dom4j.Element) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 60 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.

the class ImsRepositoryResolver method getQTIDocument.

/**
 * (non-Javadoc)
 *
 * @see org.olat.ims.qti.process.Resolver#getQTIDocument()
 */
public Document getQTIDocument() {
    // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(fUnzippedDirRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve(QTI_FILE);
    // getDocument(..) ensures that InputStream is closed in every case.
    Document theDoc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    // if doc is null an error loading the document occured (IOException, qti.xml does not exist)
    return theDoc;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Aggregations

LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)122 File (java.io.File)82 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 VFSItem (org.olat.core.util.vfs.VFSItem)38 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)30 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 Document (org.dom4j.Document)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Document (org.apache.lucene.document.Document)6 Element (org.dom4j.Element)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)6 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)6 CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)6 SearchResourceContext (org.olat.search.service.SearchResourceContext)6