use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method crawlForOrphans.
private void crawlForOrphans(VFSContainer container, List<OrphanVersion> orphans) {
if (!container.exists()) {
return;
}
List<VFSItem> children = container.getItems();
for (VFSItem child : children) {
if (child instanceof VFSContainer) {
crawlForOrphans((VFSContainer) child, orphans);
}
if (child instanceof VFSLeaf) {
VFSLeaf versionsLeaf = (VFSLeaf) child;
if (child.getName().endsWith(".xml")) {
Versions versions = isOrphan(versionsLeaf);
if (versions == null) {
continue;
} else {
List<VFSRevision> revisions = versions.getRevisions();
if (revisions != null) {
for (VFSRevision revision : revisions) {
if (revision instanceof RevisionFileImpl) {
((RevisionFileImpl) revision).setContainer(container);
}
}
}
}
File originalFile = reversedOriginFile(child);
if (!originalFile.exists()) {
VFSLeaf orphan = new LocalFileImpl(originalFile);
orphans.add(new OrphanVersion(orphan, versionsLeaf, versions));
}
}
}
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method pruneVersionHistory.
private void pruneVersionHistory(VFSLeaf versionsLeaf, long maxHistoryLength, ProgressDelegate progress) {
if (versionsLeaf.getName().endsWith(".xml") && isVersionsXmlFile(versionsLeaf)) {
File originalFile = reversedOriginFile(versionsLeaf);
if (originalFile.exists()) {
VFSLeaf original = new LocalFileImpl(originalFile);
if (progress != null)
progress.setInfo(original.getName());
Versions versions = readVersions(original, versionsLeaf);
List<VFSRevision> revisions = versions.getRevisions();
if (revisions.size() > maxHistoryLength) {
List<VFSRevision> revisionsToDelete = revisions.subList(0, revisions.size() - (int) maxHistoryLength);
deleteRevisions((Versionable) original, revisionsToDelete);
}
}
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class DrawingEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (readOnly)
return;
// title
itemBuilder.setTitle(titleEl.getValue());
File objectImg = null;
if (backgroundImage != null) {
objectImg = backgroundImage;
} else if (initialBackgroundImage != null) {
objectImg = initialBackgroundImage;
}
if (objectImg != null) {
String filename = objectImg.getName();
String mimeType = WebappHelper.getMimeType(filename);
Size size = imageService.getSize(new LocalFileImpl(objectImg), null);
int height = -1;
int width = -1;
if (size != null) {
height = size.getHeight();
width = size.getWidth();
}
itemBuilder.setBackground(filename, mimeType, height, width);
}
// question
String questionText = textEl.getRawValue();
itemBuilder.setQuestion(questionText);
fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.drawing));
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class CPFileImportController method uploadFiles.
/**
* Upload the selected files and import them into the content package.
*/
private void uploadFiles() {
VFSContainer root = cp.getRootDir();
String filenName = file.getUploadFileName();
// don't check on mimetypes - some browser use different mime types when sending files (OLAT-4547)
if (filenName.toLowerCase().endsWith(".zip")) {
// unzip and add files
VFSLeaf archive = new LocalFileImpl(file.getUploadFile());
String archiveName = file.getUploadFileName();
String unzipDirName = archiveName.substring(0, archiveName.toLowerCase().indexOf(".zip"));
unzipDirName = VFSManager.similarButNonExistingName(root, unzipDirName);
VFSContainer unzipDir = root.createChildContainer(unzipDirName);
ZipUtil.unzip(archive, unzipDir);
// add items of unzipDir to tree
pageToBeSelected = addItem(unzipDir, currentPage.getIdentifier(), true);
CPManager.getInstance().writeToFile(cp);
} else {
// Single file
VFSLeaf uploadedItem = new LocalFileImpl(file.getUploadFile());
uploadedItem.rename(file.getUploadFileName());
// rename to unique name in root folder
renameToNonExistingDesignation(root, uploadedItem);
// move item to root folder
root.copyFrom(uploadedItem);
pageToBeSelected = addItem(uploadedItem, currentPage.getIdentifier(), false);
CPManager.getInstance().writeToFile(cp);
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class RepositoryEditDescriptionController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (licenseModule.isEnabled(licenseHandler)) {
if (licenseEl != null && licenseEl.isOneSelected()) {
String licenseTypeKey = licenseEl.getSelectedKey();
LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
license.setLicenseType(licneseType);
}
String licensor = null;
String freetext = null;
if (licensorEl != null && licensorEl.isVisible()) {
licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
}
if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
}
license.setLicensor(licensor);
license.setFreetext(freetext);
license = licenseService.update(license);
licensorEl.setValue(license.getLicensor());
licenseFreetextEl.setValue(license.getFreetext());
}
File uploadedImage = fileUpload.getUploadFile();
if (uploadedImage != null && uploadedImage.exists()) {
VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
// give it it's real name and extension
VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
if (!ok) {
showWarning("cif.error.image");
} else {
VFSLeaf image = repositoryManager.getImage(repositoryEntry);
if (image instanceof LocalFileImpl) {
fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
}
}
container.delete();
}
File uploadedMovie = movieUpload.getUploadFile();
if (uploadedMovie != null && uploadedMovie.exists()) {
VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
if (newFile == null) {
showWarning("cif.error.movie");
} else {
String filename = movieUpload.getUploadFileName();
String extension = FileUtils.getFileSuffix(filename);
newFile.rename(repositoryEntry.getKey() + "." + extension);
}
}
String displayname = displayName.getValue().trim();
repositoryEntry.setDisplayname(displayname);
String mainLanguage = language.getValue();
if (StringHelper.containsNonWhitespace(mainLanguage)) {
repositoryEntry.setMainLanguage(mainLanguage);
} else {
repositoryEntry.setMainLanguage(null);
}
if (dateTypesEl != null) {
String type = "none";
if (dateTypesEl.isOneSelected()) {
type = dateTypesEl.getSelectedKey();
}
if ("none".equals(type)) {
repositoryEntry.setLifecycle(null);
} else if ("public".equals(type)) {
String key = publicDatesEl.getSelectedKey();
if (StringHelper.isLong(key)) {
Long cycleKey = Long.parseLong(key);
RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
repositoryEntry.setLifecycle(cycle);
}
} else if ("private".equals(type)) {
Date start = startDateEl.getDate();
Date end = endDateEl.getDate();
RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
if (cycle == null || !cycle.isPrivateCycle()) {
String softKey = "lf_" + repositoryEntry.getSoftkey();
cycle = lifecycleDao.create(displayname, softKey, true, start, end);
} else {
cycle.setValidFrom(start);
cycle.setValidTo(end);
cycle = lifecycleDao.updateLifecycle(cycle);
}
repositoryEntry.setLifecycle(cycle);
}
}
if (externalRef != null && externalRef.isEnabled()) {
String ref = externalRef.getValue().trim();
repositoryEntry.setExternalRef(ref);
}
String desc = description.getValue().trim();
repositoryEntry.setDescription(desc);
if (authors != null) {
String auth = authors.getValue().trim();
repositoryEntry.setAuthors(auth);
}
if (objectives != null) {
String obj = objectives.getValue().trim();
repositoryEntry.setObjectives(obj);
}
if (requirements != null) {
String req = requirements.getValue().trim();
repositoryEntry.setRequirements(req);
}
if (credits != null) {
String cred = credits.getValue().trim();
repositoryEntry.setCredits(cred);
}
if (expenditureOfWork != null) {
String exp = expenditureOfWork.getValue().trim();
repositoryEntry.setExpenditureOfWork(exp);
}
if (location != null) {
String loc = location.getValue().trim();
repositoryEntry.setLocation(loc);
}
repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
if (repositoryEntry == null) {
showWarning("repositoryentry.not.existing");
fireEvent(ureq, Event.CLOSE_EVENT);
} else {
fireEvent(ureq, Event.CHANGED_EVENT);
MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
}
}
Aggregations