use of org.olat.core.util.vfs.filters.VFSItemSuffixFilter in project openolat by klemens.
the class WikiManager method createFolders.
/**
* API change stop
*/
void createFolders(OLATResourceable ores) {
long start = 0;
if (log.isDebug()) {
start = System.currentTimeMillis();
}
VFSContainer rootContainer = getWikiRootContainer(ores);
VFSContainer unzippedDir = (VFSContainer) rootContainer.resolve(FileResourceManager.ZIPDIR);
if (unzippedDir == null) {
// check for _unzipped_ dir from imported wiki's
if (rootContainer.createChildContainer(WIKI_RESOURCE_FOLDER_NAME) == null)
throwError(ores);
if (rootContainer.createChildContainer(WikiContainer.MEDIA_FOLDER_NAME) == null)
throwError(ores);
if (rootContainer.createChildContainer(VERSION_FOLDER_NAME) == null)
throwError(ores);
} else {
// _unzipped_ dir found: move elements to wiki folder and delete
// unzipped dir and zip files
List<VFSItem> files = unzippedDir.getItems();
VFSContainer wikiCtn = rootContainer.createChildContainer(WIKI_RESOURCE_FOLDER_NAME);
VFSContainer mediaCtn = rootContainer.createChildContainer(WikiContainer.MEDIA_FOLDER_NAME);
if (rootContainer.createChildContainer(VERSION_FOLDER_NAME) == null)
throwError(ores);
if (wikiCtn == null)
throwError(ores);
// copy files to wiki and media folder
for (Iterator<VFSItem> iter = files.iterator(); iter.hasNext(); ) {
VFSLeaf leaf = ((VFSLeaf) iter.next());
if (leaf.getName().endsWith(WikiManager.WIKI_FILE_SUFFIX) || leaf.getName().endsWith(WikiManager.WIKI_PROPERTIES_SUFFIX)) {
wikiCtn.copyFrom(leaf);
} else {
if (leaf.getName().contains(WikiManager.WIKI_FILE_SUFFIX + "-") || leaf.getName().contains(WikiManager.WIKI_PROPERTIES_SUFFIX + "-")) {
// delete version history
leaf.delete();
} else
mediaCtn.copyFrom(leaf);
}
}
unzippedDir.delete();
List<VFSItem> zipFiles = rootContainer.getItems(new VFSItemSuffixFilter(new String[] { "zip" }));
// delete all zips
for (Iterator<VFSItem> iter = zipFiles.iterator(); iter.hasNext(); ) {
VFSLeaf element = (VFSLeaf) iter.next();
element.delete();
}
// reset forum key and author references keys back to default as users and forums may not exist
List<VFSItem> propertyLeafs = wikiCtn.getItems(new VFSItemSuffixFilter(new String[] { WikiManager.WIKI_PROPERTIES_SUFFIX }));
for (Iterator<VFSItem> iter = propertyLeafs.iterator(); iter.hasNext(); ) {
VFSLeaf element = (VFSLeaf) iter.next();
WikiPage page = Wiki.assignPropertiesToPage(element);
page.setForumKey(0);
page.setInitalAuthor(0);
page.setModifyAuthor(0);
page.setModificationTime(0);
page.setViewCount(0);
page.setVersion("0");
page.setCreationTime(System.currentTimeMillis());
saveWikiPageProperties(ores, page);
}
}
if (log.isDebug()) {
long end = System.currentTimeMillis();
log.debug("creating folders and move files and updating properties to default values took: (milliseconds)" + (end - start), null);
}
}
use of org.olat.core.util.vfs.filters.VFSItemSuffixFilter in project OpenOLAT by OpenOLAT.
the class WikiManager method createFolders.
/**
* API change stop
*/
void createFolders(OLATResourceable ores) {
long start = 0;
if (log.isDebug()) {
start = System.currentTimeMillis();
}
VFSContainer rootContainer = getWikiRootContainer(ores);
VFSContainer unzippedDir = (VFSContainer) rootContainer.resolve(FileResourceManager.ZIPDIR);
if (unzippedDir == null) {
// check for _unzipped_ dir from imported wiki's
if (rootContainer.createChildContainer(WIKI_RESOURCE_FOLDER_NAME) == null)
throwError(ores);
if (rootContainer.createChildContainer(WikiContainer.MEDIA_FOLDER_NAME) == null)
throwError(ores);
if (rootContainer.createChildContainer(VERSION_FOLDER_NAME) == null)
throwError(ores);
} else {
// _unzipped_ dir found: move elements to wiki folder and delete
// unzipped dir and zip files
List<VFSItem> files = unzippedDir.getItems();
VFSContainer wikiCtn = rootContainer.createChildContainer(WIKI_RESOURCE_FOLDER_NAME);
VFSContainer mediaCtn = rootContainer.createChildContainer(WikiContainer.MEDIA_FOLDER_NAME);
if (rootContainer.createChildContainer(VERSION_FOLDER_NAME) == null)
throwError(ores);
if (wikiCtn == null)
throwError(ores);
// copy files to wiki and media folder
for (Iterator<VFSItem> iter = files.iterator(); iter.hasNext(); ) {
VFSLeaf leaf = ((VFSLeaf) iter.next());
if (leaf.getName().endsWith(WikiManager.WIKI_FILE_SUFFIX) || leaf.getName().endsWith(WikiManager.WIKI_PROPERTIES_SUFFIX)) {
wikiCtn.copyFrom(leaf);
} else {
if (leaf.getName().contains(WikiManager.WIKI_FILE_SUFFIX + "-") || leaf.getName().contains(WikiManager.WIKI_PROPERTIES_SUFFIX + "-")) {
// delete version history
leaf.delete();
} else
mediaCtn.copyFrom(leaf);
}
}
unzippedDir.delete();
List<VFSItem> zipFiles = rootContainer.getItems(new VFSItemSuffixFilter(new String[] { "zip" }));
// delete all zips
for (Iterator<VFSItem> iter = zipFiles.iterator(); iter.hasNext(); ) {
VFSLeaf element = (VFSLeaf) iter.next();
element.delete();
}
// reset forum key and author references keys back to default as users and forums may not exist
List<VFSItem> propertyLeafs = wikiCtn.getItems(new VFSItemSuffixFilter(new String[] { WikiManager.WIKI_PROPERTIES_SUFFIX }));
for (Iterator<VFSItem> iter = propertyLeafs.iterator(); iter.hasNext(); ) {
VFSLeaf element = (VFSLeaf) iter.next();
WikiPage page = Wiki.assignPropertiesToPage(element);
page.setForumKey(0);
page.setInitalAuthor(0);
page.setModifyAuthor(0);
page.setModificationTime(0);
page.setViewCount(0);
page.setVersion("0");
page.setCreationTime(System.currentTimeMillis());
saveWikiPageProperties(ores, page);
}
}
if (log.isDebug()) {
long end = System.currentTimeMillis();
log.debug("creating folders and move files and updating properties to default values took: (milliseconds)" + (end - start), null);
}
}
use of org.olat.core.util.vfs.filters.VFSItemSuffixFilter in project OpenOLAT by OpenOLAT.
the class WikiManager method getOrLoadWiki.
/**
* @param ores
* @return a wiki loaded from cache or the fileSystem
*/
public Wiki getOrLoadWiki(final OLATResourceable ores) {
final String wikiKey = OresHelper.createStringRepresenting(ores);
// cluster_OK by guido
if (wikiCache == null) {
wikiCache = coordinator.getCoordinator().getCacher().getCache(WikiManager.class.getSimpleName(), "wiki");
}
return wikiCache.computeIfAbsent(wikiKey, (key) -> {
long start = 0;
// wiki not in cache load form filesystem
if (log.isDebug()) {
log.debug("wiki not in cache. Loading wiki from filesystem. Ores: " + ores.getResourceableId());
start = System.currentTimeMillis();
}
VFSContainer folder = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
// wiki in group context
if (folder == null) {
// createWikiforExistingResource(ores);
createFolders(ores);
folder = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
}
// folders should be present, create the wiki
Wiki wiki = new Wiki(getWikiRootContainer(ores));
// filter for xyz.properties files
List<VFSItem> wikiLeaves = folder.getItems(new VFSItemSuffixFilter(new String[] { WikiManager.WIKI_PROPERTIES_SUFFIX }));
for (Iterator<VFSItem> iter = wikiLeaves.iterator(); iter.hasNext(); ) {
VFSLeaf propertiesFile = (VFSLeaf) iter.next();
WikiPage page = Wiki.assignPropertiesToPage(propertiesFile);
if (page == null) {
// broken pages get automatically cleaned from filesystem
String contentFileToBeDeleted = (propertiesFile.getName().substring(0, propertiesFile.getName().length() - WikiManager.WIKI_PROPERTIES_SUFFIX.length()) + WikiManager.WIKI_FILE_SUFFIX);
folder.resolve(contentFileToBeDeleted).delete();
propertiesFile.delete();
continue;
}
// index and menu page are loaded by default
if (page.getPageName().equals(WikiPage.WIKI_INDEX_PAGE) || page.getPageName().equals(WikiPage.WIKI_MENU_PAGE)) {
VFSLeaf leaf = (VFSLeaf) folder.resolve(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
page.setContent(FileUtils.load(leaf.getInputStream(), "utf-8"));
}
// due to a bug we have to rename some pages that start with an non
// ASCII lowercase letter
String idOutOfFileName = propertiesFile.getName().substring(0, propertiesFile.getName().indexOf("."));
if (!page.matchIds(idOutOfFileName)) {
// rename corrupt prop file
propertiesFile.rename(page.getPageId() + "." + WikiManager.WIKI_PROPERTIES_SUFFIX);
// load content and delete corrupt content file
VFSLeaf contentFile = (VFSLeaf) folder.resolve(idOutOfFileName + "." + WikiManager.WIKI_FILE_SUFFIX);
contentFile.rename(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
}
wiki.addPage(page);
}
// if index and menu page not present create the first page and save it
if (wiki.getNumberOfPages() == 0) {
WikiPage indexPage = new WikiPage(WikiPage.WIKI_INDEX_PAGE);
WikiPage menuPage = new WikiPage(WikiPage.WIKI_MENU_PAGE);
indexPage.setCreationTime(System.currentTimeMillis());
wiki.addPage(indexPage);
menuPage.setCreationTime(System.currentTimeMillis());
menuPage.setContent("* [[Index]]\n* [[Index|Your link]]");
wiki.addPage(menuPage);
saveWikiPage(ores, indexPage, false, wiki);
saveWikiPage(ores, menuPage, false, wiki);
}
// add pages internally used for displaying dynamic data, they are not persisted
WikiPage recentChangesPage = new WikiPage(WikiPage.WIKI_RECENT_CHANGES_PAGE);
WikiPage a2zPage = new WikiPage(WikiPage.WIKI_A2Z_PAGE);
wiki.addPage(recentChangesPage);
wiki.addPage(a2zPage);
if (log.isDebug()) {
long stop = System.currentTimeMillis();
log.debug("loading of wiki from filessystem took (ms) " + (stop - start));
}
return wiki;
});
}
use of org.olat.core.util.vfs.filters.VFSItemSuffixFilter in project openolat by klemens.
the class VideoManagerImpl method getAllTracks.
/**
* get all tracks saved in the video metadata as map
*/
@Override
public Map<String, VFSLeaf> getAllTracks(OLATResource videoResource) {
Map<String, VFSLeaf> tracks = new HashMap<>();
VFSContainer vfsContainer = getMasterContainer(videoResource);
for (VFSItem item : vfsContainer.getItems(new VFSItemSuffixFilter(new String[] { FILETYPE_SRT }))) {
String itemname = item.getName();
String key = itemname.substring(itemname.indexOf("_") + 1, itemname.indexOf("."));
tracks.put(key, resolveFromMasterContainer(videoResource, itemname));
}
// }
return tracks;
}
use of org.olat.core.util.vfs.filters.VFSItemSuffixFilter in project openolat by klemens.
the class VersionsFileManager method getDeletedFiles.
@Override
public List<Versions> getDeletedFiles(VFSContainer container) {
List<Versions> deletedRevisions = new ArrayList<Versions>();
VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
if (versionContainer != null) {
Set<String> currentNames = new HashSet<String>();
for (VFSItem item : container.getItems(new VFSLeafFilter())) {
currentNames.add(item.getName() + ".xml");
}
List<VFSItem> versionItems = versionContainer.getItems(new VFSItemSuffixFilter(new String[] { "xml" }));
for (VFSItem versionItem : versionItems) {
String name = versionItem.getName();
if (versionItem instanceof VFSLeaf && !currentNames.contains(name) && isVersionsXmlFile((VFSLeaf) versionItem)) {
Versions versions = readVersions(null, (VFSLeaf) versionItem);
if (versions != null) {
List<VFSRevision> revisions = versions.getRevisions();
if (!revisions.isEmpty()) {
deletedRevisions.add(versions);
}
}
}
}
}
return deletedRevisions;
}
Aggregations