use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class CPManagerImpl method writeToZip.
/**
* @see org.olat.ims.cp.CPManager#writeToZip(org.olat.ims.cp.ContentPackage)
*/
public VFSLeaf writeToZip(ContentPackage cp) {
OLATResourceable ores = cp.getResourcable();
VFSContainer cpRoot = cp.getRootDir();
VFSContainer oresRoot = FileResourceManager.getInstance().getFileResourceRootImpl(ores);
RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(ores, false);
String zipFileName = "imscp.zip";
if (repoEntry != null) {
String zipName = repoEntry.getResourcename();
if (zipName != null && zipName.endsWith(".zip")) {
zipFileName = zipName;
}
}
// delete old archive and create new one
VFSItem oldArchive = oresRoot.resolve(zipFileName);
if (oldArchive != null) {
// don't versioned the zip
oldArchive.deleteSilently();
}
ZipUtil.zip(cpRoot.getItems(), oresRoot.createChildLeaf(zipFileName), true);
VFSLeaf zip = (VFSLeaf) oresRoot.resolve(zipFileName);
return zip;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class CPContentController method setContent.
/**
* Set the content to display given the file path
*
* @param ureq
* @param filePath
*/
private void setContent(UserRequest ureq, String filePath) {
if (filePath.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (filePath.length() - 4)) {
if (mceCtr != null)
mceCtr.dispose();
VFSContainer rootDir = currentPage.getRootDir();
String virtualRootFolderName = translate("cpfileuploadcontroller.virtual.root");
VFSContainer pseudoContainer = new VFSRootCPContainer(virtualRootFolderName, cp, rootDir, getTranslator());
mceCtr = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), pseudoContainer, filePath, false, false);
if (mceCtr.isEditable()) {
mceCtr.setCancelButtonEnabled(false);
mceCtr.setSaveCloseButtonEnabled(false);
mceCtr.setShowMetadataEnabled(false);
}
listenTo(mceCtr);
mainPanel.setContent(mceCtr.getInitialComponent());
} else {
iframeCtr.setCurrentURI(filePath);
mainPanel.setContent(iframeCtr.getInitialComponent());
}
}
use of org.olat.core.util.vfs.VFSContainer 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.VFSContainer in project OpenOLAT by OpenOLAT.
the class CPTreeController method addNewHTMLPage.
/**
* Adds a new page to the CP
*
* @return
*/
protected String addNewHTMLPage() {
String newId = CPManager.getInstance().addBlankPage(cp, translate("cptreecontroller.newpage.title"), currentPage.getIdentifier());
CPPage newPage = new CPPage(newId, cp);
// Create an html file
VFSContainer root = cp.getRootDir();
VFSLeaf htmlFile = root.createChildLeaf(newId + ".html");
newPage.setFile(htmlFile);
updatePage(newPage);
updateTree();
return newId;
}
use of org.olat.core.util.vfs.VFSContainer 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);
}
Aggregations