Search in sources :

Example 21 with LocalFileImpl

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

the class ForumRTFFormatter method addImagesToVFSContainer.

/**
 * Retrieves the appropriate images for the input messageNode, if any,
 * and adds it to the input container.
 *
 * @param messageNode
 * @param imageContainer
 * @return
 */
private List<String> addImagesToVFSContainer(MessageNode messageNode, VFSContainer imageContainer) {
    List<String> fileNameList = new ArrayList<String>();
    String iconPath = null;
    if (messageNode.isClosed() && messageNode.isSticky()) {
        iconPath = getImagePath("fo_sticky_closed");
    } else if (messageNode.isClosed()) {
        iconPath = getImagePath("fo_closed");
    } else if (messageNode.isSticky()) {
        iconPath = getImagePath("fo_sticky");
    }
    if (iconPath != null) {
        File file = new File(iconPath);
        if (file.exists()) {
            LocalFileImpl imgFile = new LocalFileImpl(file);
            imageContainer.copyFrom(imgFile);
            fileNameList.add(file.getName());
        } else {
            log.error("Could not find image for forum RTF formatter::" + iconPath);
        }
    }
    return fileNameList;
}
Also used : ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 22 with LocalFileImpl

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

the class FeedFileStorge method loadItemMedia.

/**
 * Load the media file of the item.
 *
 * @param item
 * @return
 */
public File loadItemMedia(Item item) {
    File file = null;
    Enclosure enclosure = item.getEnclosure();
    VFSContainer mediaDir = getOrCreateItemMediaContainer(item);
    if (mediaDir != null && enclosure != null) {
        VFSLeaf mediaFile = (VFSLeaf) mediaDir.resolve(enclosure.getFileName());
        if (mediaFile != null && mediaFile instanceof LocalFileImpl) {
            file = ((LocalFileImpl) mediaFile).getBasefile();
        }
    }
    return file;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Enclosure(org.olat.modules.webFeed.Enclosure) File(java.io.File)

Example 23 with LocalFileImpl

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

the class CustomConfigManager method appendLogoPart.

private void appendLogoPart(StringBuffer sb, VFSContainer themeBase) {
    VFSItem vfsItem = getLogoItem(themeBase);
    if (vfsItem != null) {
        sb.append("#o_right_logo {\n\tbackground-image: url(").append(vfsItem.getName()).append("); \n");
        sb.append("\tbackground-position: left top; \n");
        sb.append("\tbackground-repeat: no-repeat; \n");
        LocalFileImpl leaf = (LocalFileImpl) vfsItem;
        int[] size = getImageSize(leaf.getBasefile());
        if (size != null) {
            sb.append("\twidth: ").append(size[0]).append("px; \n").append("\theight: ").append(size[1]).append("px; \n");
        }
        sb.append("\tfloat: left; \n}\n");
        sb.append("#o_logo { \n\t float: left; \n}");
    }
}
Also used : VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 24 with LocalFileImpl

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

the class CPOfflineReadableManager method writeOfflineCPStartHTMLFile.

/**
 * generates a html-file (_START_.html) that presents the given cp-content
 * (specified by its "_unzipped_"-dir). The resulting file is suitable for
 * offline reading of the cp.
 *
 * @param unzippedDir
 *            the directory that contains the unzipped CP
 */
private void writeOfflineCPStartHTMLFile(File unzippedDir) throws IOException {
    /* first, we do the menu-tree */
    File mani = new File(unzippedDir, FILENAME_IMSMANIFEST);
    LocalFileImpl vfsMani = new LocalFileImpl(mani);
    CPManifestTreeModel ctm = new CPManifestTreeModel(vfsMani, "");
    TreeNode root = ctm.getRootNode();
    // let's take the rootnode title as  page title
    this.rootTitle = root.getTitle();
    StringBuilder menuTreeSB = new StringBuilder();
    renderMenuTreeNodeRecursively(root, menuTreeSB, 0);
    // now put values to velocityContext
    VelocityContext ctx = new VelocityContext();
    ctx.put("menutree", menuTreeSB.toString());
    ctx.put("rootTitle", this.rootTitle);
    ctx.put("cpoff", DIRNAME_CPOFFLINEMENUMAT);
    StringWriter sw = new StringWriter();
    try {
        String template = FileUtils.load(CPOfflineReadableManager.class.getResourceAsStream("_content/cpofflinereadable.html"), "utf-8");
        boolean evalResult = velocityEngine.evaluate(ctx, sw, "cpexport", template);
        if (!evalResult)
            log.error("Could not evaluate velocity template for CP Export");
    } catch (Exception e) {
        log.error("Error while evaluating velovity template for CP Export", e);
    }
    File f = new File(unzippedDir, FILENAME_START);
    if (f.exists()) {
        FileUtils.deleteDirsAndFiles(f, false, true);
    }
    ExportUtil.writeContentToFile(FILENAME_START, sw.toString(), unzippedDir, "utf-8");
}
Also used : StringWriter(java.io.StringWriter) TreeNode(org.olat.core.gui.components.tree.TreeNode) VelocityContext(org.apache.velocity.VelocityContext) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) IOException(java.io.IOException)

Example 25 with LocalFileImpl

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

the class CatalogEntryEditController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormStyle("o_catalog");
    String name = catalogEntry == null ? "" : catalogEntry.getName();
    nameEl = uifactory.addTextElement("name", "entry.category", 255, name, formLayout);
    nameEl.setMandatory(true);
    nameEl.setNotEmptyCheck("form.legende.mandatory");
    String desc = catalogEntry == null ? "" : catalogEntry.getDescription();
    descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("description", "entry.description", desc, 10, -1, formLayout, getWindowControl());
    String[] styleValues = new String[] { translate("tiles"), translate("list"), translate("list.compact") };
    styleEl = uifactory.addDropdownSingleselect("style", "style", formLayout, styleKeys, styleValues, null);
    Style style = catalogEntry == null ? null : catalogEntry.getStyle();
    if (style != null) {
        for (String styleKey : styleKeys) {
            if (styleKey.equals(style.name())) {
                styleEl.select(styleKey, true);
            }
        }
    }
    if (!styleEl.isOneSelected()) {
        styleEl.select(styleKeys[0], true);
    }
    VFSLeaf img = catalogEntry == null || catalogEntry.getKey() == null ? null : catalogManager.getImage(catalogEntry);
    fileUpload = uifactory.addFileElement(getWindowControl(), "entry.pic", "entry.pic", formLayout);
    fileUpload.setMaxUploadSizeKB(picUploadlimitKB, null, null);
    fileUpload.addActionListener(FormEvent.ONCHANGE);
    fileUpload.setPreview(ureq.getUserSession(), true);
    fileUpload.setCropSelectionEnabled(true);
    fileUpload.setDeleteEnabled(true);
    if (img instanceof LocalFileImpl) {
        fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
    }
    fileUpload.limitToMimeType(mimeTypes, "cif.error.mimetype", new String[] { mimeTypes.toString() });
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    buttonLayout.setElementCssClass("o_sel_catalog_entry_form_buttons");
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("submit", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Style(org.olat.repository.CatalogEntry.Style) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)126 File (java.io.File)70 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 Size (org.olat.core.commons.services.image.Size)22 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 RandomAccessFile (java.io.RandomAccessFile)14 FileChannel (java.nio.channels.FileChannel)12 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)12 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)12 OLATResource (org.olat.resource.OLATResource)10 Date (java.util.Date)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 BufferedImage (java.awt.image.BufferedImage)6 InputStream (java.io.InputStream)6