use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class CPFileImportController method containsItemsToAdd.
/**
* Breadth-first search for leafs inside the container that are to be added to
* the tree.
*
* @param container
* @param menuItemTypes
* @return true if there is a leaf inside container that should be added
*/
private boolean containsItemsToAdd(VFSContainer container, Collection<String> menuItemTypes) {
LinkedList<VFSItem> queue = new LinkedList<VFSItem>();
// enqueue root node
queue.add(container);
do {
// dequeue and exmaine
VFSItem item = queue.poll();
if (item instanceof VFSLeaf) {
if (isToBeAdded((VFSLeaf) item, menuItemTypes)) {
// node found, return
return true;
}
} else {
// enqueue successors
VFSContainer parent = (VFSContainer) item;
queue.addAll(parent.getItems());
}
} while (!queue.isEmpty());
return false;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class GuiDemoFileChooserController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == chooserCtr) {
// catch the events from the file chooser controller here
if (event instanceof FileChoosenEvent) {
// User pressed select button, get selected item from controller
VFSItem selectedItem = FileChooserUIFactory.getSelectedItem((FileChoosenEvent) event);
// for this demo just get file path and display an info message
LocalImpl localFile = (LocalImpl) selectedItem;
String absPath = localFile.getBasefile().getAbsolutePath();
String relPath = absPath.substring(webappRootFile.getAbsolutePath().length());
getWindowControl().setInfo("user selected /static" + relPath);
} else if (event == Event.CANCELLED_EVENT) {
// user pressed cancel
getWindowControl().setInfo("user cancelled");
} else if (event == Event.FAILED_EVENT) {
// selection failed for unknown reason
getWindowControl().setError("Ups, an error occured");
}
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class WikiMainController method updateFileAndLinkList.
private void updateFileAndLinkList(Wiki wiki) {
List<VFSItem> mediaFiles = wiki.getMediaFileList();
Collections.sort(mediaFiles, new WikiFileComparator(getLocale()));
editContent.contextPut("fileList", mediaFiles);
List<String> allPages = wiki.getListOfAllPageNames();
Collections.sort(allPages, new WikiPageNameComparator(getLocale()));
editContent.contextPut("linkList", allPages);
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class WikiToCPResource method wikiToCP.
private void wikiToCP(Wiki wiki, ZipOutputStream zout) throws IOException {
WikiToCPExport export = new WikiToCPExport(ores, translator);
// create the ims manifest
String manifest = export.createIMSManifest(wiki, identity);
zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
IOUtils.write(manifest, zout, "UTF-8");
zout.closeEntry();
VFSContainer mediaContainer = WikiManager.getInstance().getMediaFolder(ores);
List<VFSItem> images = mediaContainer.getItems();
for (VFSItem image : images) {
ZipUtil.addToZip(image, "", zout);
}
// create the javascript mapping file
String jsContent = export.createJsMappingContent(wiki);
zout.putNextEntry(new ZipEntry("mapping.js"));
IOUtils.write(jsContent, zout, "UTF-8");
zout.closeEntry();
List<WikiPage> pages = wiki.getAllPagesWithContent(true);
for (WikiPage page : pages) {
String htmlPage = export.wikiPageToHtml(page);
zout.putNextEntry(new ZipEntry(page.getPageId() + ".html"));
IOUtils.write(htmlPage, zout, "UTF-8");
zout.closeEntry();
}
WikiPage index = wiki.getPage(WikiPage.WIKI_INDEX_PAGE, true);
String indexSrc = index.getPageId() + ".html";
CPOfflineReadableManager.getInstance().makeCPOfflineReadable(manifest, indexSrc, zout);
}
use of org.olat.core.util.vfs.VFSItem 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());
}
}
Aggregations