Search in sources :

Example 66 with VFSLeaf

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

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

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

the class WikiToZipUtils method createIndexPageForExport.

/**
 * creates an html page with the mappings between the pagename and the Base64
 * encoded filename.
 *
 * @param vfsLeaves
 * @return
 */
private static String createIndexPageForExport(List<VFSItem> vfsLeaves) {
    boolean hasProperties = false;
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head>");
    sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
    sb.append("</head><body><ul>");
    for (Iterator<VFSItem> iter = vfsLeaves.iterator(); iter.hasNext(); ) {
        VFSLeaf element = (VFSLeaf) iter.next();
        // destination.copyFrom(element);
        if (element.getName().endsWith(WikiManager.WIKI_PROPERTIES_SUFFIX)) {
            hasProperties = true;
            Properties p = new Properties();
            try {
                p.load(element.getInputStream());
            } catch (IOException e) {
                throw new AssertException("Wiki propterties couldn't be read! ", e);
            }
            sb.append("<li>");
            sb.append(p.getProperty(WikiManager.PAGENAME));
            sb.append(" ----> ");
            sb.append(element.getName().substring(0, element.getName().indexOf(".")));
            sb.append("</li>");
        }
    }
    sb.append("</ul></body></html>");
    if (!hasProperties)
        return null;
    return sb.toString();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties)

Example 69 with VFSLeaf

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

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

the class FeedFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // title might be longer from external source
    String saveTitle = PersistenceHelper.truncateStringDbSave(feed.getTitle(), 256, true);
    title = uifactory.addTextElement("title", "feed.title.label", 256, saveTitle, formLayout);
    title.setElementCssClass("o_sel_feed_title");
    title.setMandatory(true);
    title.setNotEmptyCheck("feed.form.field.is_mandatory");
    description = uifactory.addRichTextElementForStringDataMinimalistic("description", "feed.form.description", feed.getDescription(), 5, -1, formLayout, getWindowControl());
    description.setMaxLength(4000);
    RichTextConfiguration richTextConfig = description.getEditorConfiguration();
    // set upload dir to the media dir
    richTextConfig.setFileBrowserUploadRelPath("media");
    // Add a delete link and an image component to the image container.
    deleteImage = uifactory.addFormLink("feed.image.delete", formLayout, Link.BUTTON);
    deleteImage.setVisible(false);
    file = uifactory.addFileElement(getWindowControl(), "feed.file.label", formLayout);
    file.addActionListener(FormEvent.ONCHANGE);
    file.setPreview(ureq.getUserSession(), true);
    if (feed.getImageName() != null) {
        VFSLeaf imageResource = FeedManager.getInstance().createFeedMediaFile(feed, feed.getImageName(), null);
        if (imageResource instanceof LocalFileImpl) {
            file.setPreview(ureq.getUserSession(), true);
            file.setInitialFile(((LocalFileImpl) imageResource).getBasefile());
            deleteImage.setVisible(true);
        }
    }
    Set<String> mimeTypes = new HashSet<String>();
    mimeTypes.add("image/jpeg");
    mimeTypes.add("image/jpg");
    mimeTypes.add("image/png");
    mimeTypes.add("image/gif");
    file.limitToMimeType(mimeTypes, "feed.form.file.type.error.images", null);
    int maxFileSizeKB = feedQuota.getUlLimitKB().intValue();
    String supportAddr = WebappHelper.getMailConfig("mailQuota");
    file.setMaxUploadSizeKB(maxFileSizeKB, "ULLimitExceeded", new String[] { new Long(maxFileSizeKB / 1024).toString(), supportAddr });
    // if external feed, display feed-url text-element:
    if (feed.isExternal()) {
        feedUrl = uifactory.addTextElement("feedUrl", "feed.form.feedurl", 5000, feed.getExternalFeedUrl(), flc);
        feedUrl.setElementCssClass("o_sel_feed_url");
        feedUrl.setDisplaySize(70);
        String type = feed.getResourceableTypeName();
        if (type != null && type.indexOf("BLOG") >= 0) {
            feedUrl.setExampleKey("feed.form.feedurl.example", null);
        } else {
            feedUrl.setExampleKey("feed.form.feedurl.example_podcast", null);
        }
    }
    // Submit and cancelButton buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("submit", buttonLayout);
    cancelButton = uifactory.addFormLink("cancel", buttonLayout, Link.BUTTON);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HashSet(java.util.HashSet)

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