Search in sources :

Example 61 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf 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 62 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class ContentPackage method updatePage.

protected void updatePage(CPPage page) {
    DefaultElement ele = cpcore.getElementByIdentifier(page.getIdentifier());
    if (ele instanceof CPItem) {
        CPItem item = (CPItem) ele;
        item.setTitle(page.getTitle());
        item.setMetadata(page.getMetadata());
        String itemIdentifierRef = item.getIdentifierRef();
        if (itemIdentifierRef == null || itemIdentifierRef.equals("")) {
            // This item has no linked resource yet. Add one if there is a page file
            // attached.
            VFSLeaf pageFile = page.getPageFile();
            if (pageFile != null) {
                CPResource res = new CPResource();
                CPFile file = new CPFile(pageFile);
                res.addFile(file);
                // TODO:GW Set type according to file
                res.setType("text/html");
                res.setHref(file.getHref());
                item.setIdentifierRef(res.getIdentifier());
                cpcore.getRootNode().getResources().addResource(res);
            }
        } else {
        // this item has already a linked resource
        // this is not supported, we don't change linked resources...
        }
    } else if (ele instanceof CPOrganization) {
        CPOrganization organization = (CPOrganization) ele;
        organization.setTitle(page.getTitle());
    } else {
        // ERROR: this shouldn't be
        throw new OLATRuntimeException("Error while updating manifest with new Page-Data. Invalid identifier " + page.getIdentifier(), null);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CPFile(org.olat.ims.cp.objects.CPFile) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResource(org.olat.ims.cp.objects.CPResource) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 63 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.

the class ContentPackage method writeToFile.

/**
 * writes the manifest.xml
 */
void writeToFile() {
    String filename = "imsmanifest.xml";
    OutputFormat format = OutputFormat.createPrettyPrint();
    try {
        VFSLeaf outFile;
        // file may exist
        outFile = (VFSLeaf) cpcore.getRootDir().resolve("/" + filename);
        if (outFile == null) {
            // if not, create it
            outFile = cpcore.getRootDir().createChildLeaf("/" + filename);
        }
        DefaultDocument manifestDocument = cpcore.buildDocument();
        XMLWriter writer = new XMLWriter(outFile.getOutputStream(false), format);
        writer.write(manifestDocument);
    } catch (Exception e) {
        log.error("imsmanifest for ores " + ores.getResourceableId() + "couldn't be written to file.", e);
        throw new OLATRuntimeException(CPOrganizations.class, "Error writing imsmanifest-file", new IOException());
    }
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OutputFormat(org.dom4j.io.OutputFormat) DefaultDocument(org.dom4j.tree.DefaultDocument) IOException(java.io.IOException) XMLWriter(org.dom4j.io.XMLWriter) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 64 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf 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 65 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf 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)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34