Search in sources :

Example 6 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class FileElementImpl method reset.

@Override
public void reset() {
    if (tempUploadFile != null && tempUploadFile.exists()) {
        tempUploadFile.delete();
    }
    tempUploadFile = null;
    if (previewEl != null) {
        if (initialFile != null) {
            VFSLeaf media = new LocalFileImpl(initialFile);
            previewEl.setMedia(media);
            previewEl.setMaxWithAndHeightToFitWithin(300, 200);
            previewEl.setVisible(true);
        } else if (previewEl != null) {
            previewEl.setVisible(false);
        }
    }
    uploadFilename = null;
    uploadMimeType = null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 7 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class ImageComponent method setMedia.

public void setMedia(File mediaFile) {
    setDirty(true);
    setMedia(new LocalFileImpl(mediaFile));
}
Also used : LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 8 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class LogFileParser method getLogfilePath.

/**
 * @param date the date of the log to retrieve, or null when no date suffix should be appended (= take today's log)
 * @return the VFSLeaf of the Logfile given the Date, or null if no such file could be found
 */
public static VFSLeaf getLogfilePath(Date date) {
    String tmpFileName = logfilepathBase;
    if (date != null) {
        SimpleDateFormat sdb = new SimpleDateFormat("yyyy-MM-dd");
        String suffix = sdb.format(date);
        String today = sdb.format(new Date());
        if (suffix.equals(today))
            tmpFileName = logfilepathBase;
        else
            tmpFileName = logfilepathBase + "." + suffix;
    }
    File logf = new File(tmpFileName);
    if (!logf.exists())
        return null;
    return new LocalFileImpl(logf);
}
Also used : LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date)

Example 9 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class VersionsFileManager method isSameFile.

private boolean isSameFile(VFSLeaf currentFile, VersionsFileImpl versions) {
    boolean same = false;
    if (versions.getRevisions() != null && !versions.getRevisions().isEmpty()) {
        VFSRevision lastRevision = versions.getRevisions().get(versions.getRevisions().size() - 1);
        long lastSize = lastRevision.getSize();
        long currentSize = currentFile.getSize();
        if (currentSize == lastSize && currentSize > 0 && lastRevision instanceof RevisionFileImpl && currentFile instanceof LocalFileImpl) {
            RevisionFileImpl lastRev = ((RevisionFileImpl) lastRevision);
            LocalFileImpl current = (LocalFileImpl) currentFile;
            // can be the same file
            try {
                Checksum cm1 = FileUtils.checksum(((LocalFileImpl) lastRev.getFile()).getBasefile(), new Adler32());
                Checksum cm2 = FileUtils.checksum(current.getBasefile(), new Adler32());
                same = cm1.getValue() == cm2.getValue();
            } catch (IOException e) {
                log.debug("Error calculating the checksum of files");
            }
        }
    }
    return same;
}
Also used : Checksum(java.util.zip.Checksum) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) IOException(java.io.IOException) Adler32(java.util.zip.Adler32)

Example 10 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class HTMLEditorController method initEditorForm.

private void initEditorForm(VFSContainer bContainer, String relFilePath, CustomLinkTreeModel linkTreeModel, String mPath, boolean editorCheck, boolean versions, boolean withButtons) {
    this.baseContainer = bContainer;
    this.fileRelPath = relFilePath;
    this.mediaPath = mPath;
    this.versionsEnabled = versions;
    this.buttonsEnabled = withButtons;
    this.customLinkTreeModel = linkTreeModel;
    this.editorCheckEnabled = editorCheck;
    // make sure the filename doesn't start with a slash
    this.fileName = ((relFilePath.charAt(0) == '/') ? relFilePath.substring(1) : relFilePath);
    this.fileLeaf = (VFSLeaf) bContainer.resolve(fileName);
    if (fileLeaf == null)
        throw new AssertException("file::" + getFileDebuggingPath(bContainer, relFilePath) + " does not exist!");
    long size = fileLeaf.getSize();
    if (size > FolderConfig.getMaxEditSizeLimit()) {
        // limit to reasonable size, see OO-57
        fileToLargeError = translate("plaintext.error.tolarge", new String[] { (size / 1000) + "", (FolderConfig.getMaxEditSizeLimit() / 1000) + "" });
        this.body = "";
        this.editable = false;
        return;
    }
    // check if someone else is already editing the file
    if (fileLeaf instanceof LocalFileImpl) {
        // Cast to LocalFile necessary because the VFSItem is missing some
        // ID mechanism that identifies an item within the system
        OLATResourceable lockResourceable = createLockResourceable(fileLeaf);
        // OLAT-5066: the use of "fileName" gives users the (false) impression that the file they wish to access
        // is already locked by someone else. Since the lock token must be smaller than 50 characters we us an
        // MD5 hash of the absolute file path which will always be 32 characters long and virtually unique.
        String lockToken = createLockToken(bContainer, relFilePath);
        lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockResourceable, getIdentity(), lockToken);
        VelocityContainer vc = (VelocityContainer) flc.getComponent();
        if (!lock.isSuccess()) {
            vc.contextPut("locked", Boolean.TRUE);
            String fullname = UserManager.getInstance().getUserDisplayName(lock.getOwner());
            vc.contextPut("lockOwner", fullname);
            editable = false;
            return;
        } else {
            vc.contextPut("locked", Boolean.FALSE);
        }
    }
    // Parse the content of the page
    this.body = parsePage(fileLeaf);
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Aggregations

LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)126 File (java.io.File)70 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 Size (org.olat.core.commons.services.image.Size)22 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 RandomAccessFile (java.io.RandomAccessFile)14 FileChannel (java.nio.channels.FileChannel)12 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)12 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)12 OLATResource (org.olat.resource.OLATResource)10 Date (java.util.Date)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 BufferedImage (java.awt.image.BufferedImage)6 InputStream (java.io.InputStream)6