Search in sources :

Example 86 with VFSContainer

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException) Properties(java.util.Properties)

Example 87 with VFSContainer

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());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties)

Example 88 with VFSContainer

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

Example 89 with VFSContainer

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

Example 90 with VFSContainer

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) Document(org.apache.lucene.document.Document) IMSMetadataDocument(org.olat.search.service.document.file.IMSMetadataDocument) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

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