use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class WikiManager method saveWikiPageProperties.
private void saveWikiPageProperties(OLATResourceable ores, WikiPage page) {
VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
VFSLeaf leaf = (VFSLeaf) wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
if (leaf == null)
leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
Properties p = getPageProperties(page);
try {
p.store(leaf.getOutputStream(false), "wiki page meta properties");
} catch (IOException e) {
throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class WikiManager method saveWikiPage.
/**
* persists a wiki page on the filesystem. It moves the recent page and the
* metadata to the versions folder with the version on the tail and saves new
* page with metadata to the wiki folder. Does not need to be synchronized as
* editing is locked on page level by the
*
* @see WikiMainController
* @param ores
* @param page
*/
public void saveWikiPage(OLATResourceable ores, WikiPage page, boolean incrementVersion, Wiki wiki) {
// cluster_OK by guido
VFSContainer versionsContainer = getWikiContainer(ores, VERSION_FOLDER_NAME);
VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
// rename existing content file to version x and copy it to the version
// container
VFSItem item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
if (item != null && incrementVersion) {
if (page.getVersion() > 0) {
versionsContainer.copyFrom(item);
VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
String fileName = page.getPageId() + "." + WIKI_FILE_SUFFIX + "-" + page.getVersion();
copiedItem.rename(fileName);
}
item.delete();
}
// rename existing meta file to version x and copy it to the version
// container
item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
if (item != null && incrementVersion) {
// TODO renaming and coping does not work. Bug?? felix fragen
if (page.getVersion() > 0) {
versionsContainer.copyFrom(item);
VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
String fileName = page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX + "-" + page.getVersion();
copiedItem.rename(fileName);
}
item.delete();
}
// store recent content file
VFSLeaf leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_FILE_SUFFIX);
if (leaf == null)
throw new AssertException("Tried to save wiki page with id (" + page.getPageId() + ") and Olatresource: " + ores.getResourceableId() + " but page already existed!");
FileUtils.save(leaf.getOutputStream(false), page.getContent(), "utf-8");
// store recent properties file
leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
if (leaf == null)
throw new AssertException("could not create file for wiki page " + page.getPageId() + ", ores: " + ores.getResourceableTypeName() + ":" + ores.getResourceableId() + ", wikicontainer:" + wikiContentContainer);
if (incrementVersion)
page.incrementVersion();
// update modification time
if (!page.getContent().equals(""))
page.setModificationTime(System.currentTimeMillis());
Properties p = getPageProperties(page);
try {
OutputStream os = leaf.getOutputStream(false);
p.store(os, "wiki page meta properties");
os.close();
// if (incrementVersion) page.incrementVersion();
} catch (IOException e) {
throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
}
// reset view count of the page
page.setViewCount(0);
// update cache to inform all nodes about the change
if (wikiCache != null) {
wikiCache.update(OresHelper.createStringRepresenting(ores), wiki);
}
if (ThreadLocalUserActivityLogger.getLoggedIdentity() != null) {
// do logging only for real user
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_UPDATE, getClass());
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class WikiToZipUtils method getWikiAsZip.
/**
* get the whole wiki as a zip file for export, content is unparsed!
* @param rootContainer
* @return
*/
public static VFSLeaf getWikiAsZip(VFSContainer rootContainer) {
List<VFSItem> folders = rootContainer.getItems();
VFSLeaf indexLeaf = (VFSLeaf) rootContainer.resolve("index.html");
if (indexLeaf != null)
indexLeaf.delete();
List<VFSItem> filesTozip = new ArrayList<VFSItem>();
for (Iterator<VFSItem> iter = folders.iterator(); iter.hasNext(); ) {
VFSItem item = iter.next();
if (item instanceof VFSContainer) {
VFSContainer folder = (VFSContainer) item;
List<VFSItem> items = folder.getItems();
String overviewPage = WikiToZipUtils.createIndexPageForExport(items);
if (overviewPage != null) {
VFSLeaf overview = rootContainer.createChildLeaf("index.html");
// items.add(overview); take care not to have duplicate entries in the list
FileUtils.save(overview.getOutputStream(false), overviewPage, "utf-8");
}
// reload list, maybe there is a new index.html file
items = folder.getItems();
filesTozip.addAll(items);
}
}
VFSLeaf zipFile = (VFSLeaf) rootContainer.resolve("wiki.zip");
if (rootContainer.resolve("wiki.zip") != null)
zipFile.delete();
ZipUtil.zip(filesTozip, rootContainer.createChildLeaf("wiki.zip"), true);
return (VFSLeaf) rootContainer.resolve("wiki.zip");
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class WikiToZipUtils method wikiToZip.
public static void wikiToZip(VFSContainer rootContainer, String currentPath, ZipOutputStream exportStream) throws IOException {
for (VFSItem item : rootContainer.getItems()) {
if (item instanceof VFSContainer) {
VFSContainer folder = (VFSContainer) item;
List<VFSItem> items = folder.getItems();
String overviewPage = WikiToZipUtils.createIndexPageForExport(items);
if (overviewPage != null) {
exportStream.putNextEntry(new ZipEntry(currentPath + "/index.html"));
IOUtils.write(overviewPage, exportStream, "UTF-8");
exportStream.closeEntry();
}
for (VFSItem wikiItem : items) {
ZipUtil.addToZip(wikiItem, currentPath, exportStream);
}
}
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class ScormRepositoryIndexer method doIndex.
protected void doIndex(SearchResourceContext resourceContext, OlatFullIndexer indexWriter, File cpRoot) throws IOException, InterruptedException {
VFSContainer container = new LocalFolderImpl(cpRoot);
VFSLeaf fManifest = (VFSLeaf) container.resolve("imsmanifest.xml");
if (fManifest != null) {
Element rootElement = IMSLoader.loadIMSDocument(fManifest).getRootElement();
Document manfiestDoc = createManifestDocument(fManifest, rootElement, resourceContext);
indexWriter.addDocument(manfiestDoc);
ScormFileAccess accessRule = new ScormFileAccess();
doIndexVFSContainer(resourceContext, container, indexWriter, "", accessRule);
}
}
Aggregations