Search in sources :

Example 81 with VFSContainer

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 82 with VFSContainer

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());
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer)

Example 83 with VFSContainer

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) LinkedList(java.util.LinkedList)

Example 84 with VFSContainer

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer)

Example 85 with VFSContainer

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);
}
Also used : ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34