@Override public boolean deleteRevisions(Versionable currentVersion, List<VFSRevision> versionsToDelete) { VFSLeaf currentFile = (VFSLeaf) currentVersion; Versions versions = readVersions(currentFile, true); List<VFSRevision> allVersions = versions.getRevisions(); Map<String, VFSLeaf> filenamesToDelete = new HashMap<String, VFSLeaf>(allVersions.size()); for (VFSRevision versionToDelete : versionsToDelete) { RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete; for (Iterator<VFSRevision> allVersionIt = allVersions.iterator(); allVersionIt.hasNext(); ) { RevisionFileImpl allVersionImpl = (RevisionFileImpl) allVersionIt.next(); if (allVersionImpl.getFilename() != null && allVersionImpl.getFilename().equals(versionImpl.getFilename())) { allVersionIt.remove(); break; } } VFSLeaf fileToDelete = versionImpl.getFile(); if (fileToDelete != null) { filenamesToDelete.put(fileToDelete.getName(), fileToDelete); } } List<RevisionFileImpl> missingFiles = new ArrayList<>(); for (VFSRevision survivingVersion : allVersions) { RevisionFileImpl survivingVersionImpl = (RevisionFileImpl) survivingVersion; VFSLeaf revFile = survivingVersionImpl.getFile(); if (revFile == null) { missingFiles.add(survivingVersionImpl); // file is missing } else if (filenamesToDelete.containsKey(revFile.getName())) { filenamesToDelete.remove(revFile.getName()); } } if (missingFiles.size() > 0) { allVersions.removeAll(missingFiles); } for (VFSLeaf fileToDelete : filenamesToDelete.values()) { fileToDelete.deleteSilently(); } VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true); XStreamHelper.writeObject(mystream, versionFile, versions); if (currentVersion.getVersions() instanceof VersionsFileImpl) { ((VersionsFileImpl) currentVersion.getVersions()).update(versions); } return true; }
/** * Some temporary/lock files of specific editors need to be force deleted with all versions. Word * can reuse older names. * * @param leaf * @return */ private boolean isTemporaryFile(VFSLeaf leaf) { String name = leaf.getName(); // temporary files if (name.endsWith(".tmp")) { // Word 2010: ~WRD0002.tmp if (name.startsWith("~WRD") || name.startsWith("~WRL")) { return true; } // PowerPoint 2010: ppt5101.tmp if (name.startsWith("ppt")) { return true; } } // lock files of Word 2010, Excel 2010, PowerPoint 2010: if (name.startsWith("~$") && (name.endsWith(".docx") || name.endsWith(".xlsx") || name.endsWith(".pptx"))) { return true; } // OpenOffice locks: .~lock.Versions_21.odt# if (name.startsWith(".~lock.") && (name.endsWith(".odt#") /* Writer */ || name.endsWith(".ods#") /* Calc */ || name.endsWith(".odp#") /* Impress */ || name.endsWith("odf#") /* Math */ || name.endsWith(".odg#") /* Draw */)) { return true; } // OpenOffice database lock if (name.endsWith(".odb.lck")) { return true; } return false; }
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); } } } }
@Override public boolean isThumbnailPossible(VFSLeaf file) { String extension = FileUtils.getFileSuffix(file.getName()); if (StringHelper.containsNonWhitespace(extension)) { for (ThumbnailSPI thumbnailSPI : thumbnailSPIes) { if (thumbnailSPI.getExtensions().contains(extension)) { return true; } } } return false; }
@Override public FinalSize generateThumbnail( VFSLeaf file, VFSLeaf thumbnailFile, int maxWidth, int maxHeight) throws CannotGenerateThumbnailException { String extension = FileUtils.getFileSuffix(file.getName()).toLowerCase(); for (ThumbnailSPI thumbnailSPI : thumbnailSPIes) { if (thumbnailSPI.getExtensions().contains(extension)) { FinalSize finalSize = thumbnailSPI.generateThumbnail(file, thumbnailFile, maxWidth, maxHeight); if (finalSize != null) { return finalSize; } // else, try to find an other SPI which can thumbnailed this file } } return null; }
/** * @see * org.olat.core.util.vfs.version.VersionsManager#addToRevisions(org.olat.core.util.vfs.version.Versionable, * org.olat.core.id.Identity, java.lang.String) */ @Override public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) { int maxNumOfVersions = versioningConfigurator.getMaxNumOfVersionsAllowed(); if (maxNumOfVersions == 0) { return true; // deactivated, return all ok } VFSLeaf currentFile = (VFSLeaf) currentVersion; VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true); if (versionFile == null) { return false; // cannot do something with the current file } VFSContainer versionContainer = versionFile.getParentContainer(); String name = currentFile.getName(); // read from the Versions v = readVersions(currentFile, versionFile); if (!(v instanceof VersionsFileImpl)) { log.error("Wrong implementation of Versions: " + v); return false; } VersionsFileImpl versions = (VersionsFileImpl) v; boolean sameFile = isSameFile(currentFile, versions); String uuid = sameFile ? getLastRevisionFilename(versions) : UUID.randomUUID().toString() + "_" + name; String versionNr = getNextRevisionNr(versions); String currentAuthor = versions.getAuthor(); long lastModifiedDate = 0; if (currentFile instanceof MetaTagged) { MetaInfo metaInfo = ((MetaTagged) currentFile).getMetaInfo(); if (metaInfo != null) { metaInfo.clearThumbnails(); if (currentAuthor == null) { currentAuthor = metaInfo.getAuthor(); } lastModifiedDate = metaInfo.getLastModified(); } } if (lastModifiedDate <= 0) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); lastModifiedDate = cal.getTimeInMillis(); } RevisionFileImpl newRevision = new RevisionFileImpl(); newRevision.setUuid(UUID.randomUUID().toString()); newRevision.setName(name); newRevision.setFilename(uuid); newRevision.setRevisionNr(versionNr); newRevision.setComment(versions.getComment()); newRevision.setAuthor(currentAuthor); newRevision.setLastModified(lastModifiedDate); if (versions.getRevisions().isEmpty() && currentVersion instanceof MetaTagged) { MetaTagged metaTagged = (MetaTagged) currentVersion; versions.setCreator(metaTagged.getMetaInfo().getAuthor()); } if (sameFile || VFSManager.copyContent(currentFile, versionContainer.createChildLeaf(uuid))) { if (identity != null) { versions.setAuthor(identity.getName()); } if (maxNumOfVersions >= 0 && versions.getRevisions().size() >= maxNumOfVersions) { List<VFSRevision> revisions = versions.getRevisions(); int numOfVersionsToDelete = Math.min(revisions.size(), (revisions.size() - maxNumOfVersions) + 1); if (numOfVersionsToDelete > 0) { List<VFSRevision> versionsToDelete = revisions.subList(0, numOfVersionsToDelete); deleteRevisions(currentVersion, versionsToDelete); versions = (VersionsFileImpl) currentVersion.getVersions(); } } versions.setComment(comment); versions.getRevisions().add(newRevision); versions.setRevisionNr(getNextRevisionNr(versions)); XStreamHelper.writeObject(mystream, versionFile, versions); if (currentVersion.getVersions() instanceof VersionsFileImpl) { ((VersionsFileImpl) currentVersion.getVersions()).update(versions); } return true; } else { log.error("Cannot create a version of this file: " + currentVersion); } return false; }