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;
}
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));
}
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);
}
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;
}
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);
}
Aggregations