Search in sources :

Example 96 with VFSItem

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

the class FeedManagerImpl method createFeedMediaFile.

@Override
public VFSLeaf createFeedMediaFile(OLATResourceable feed, String fileName, Size thumbnailSize) {
    VFSLeaf mediaResource = null;
    // Brute force method for fast delivery
    try {
        VFSItem item = feedFileStorage.getOrCreateFeedMediaContainer(feed);
        item = item.resolve(fileName);
        if (thumbnailSize != null && thumbnailSize.getHeight() > 0 && thumbnailSize.getWidth() > 0 && item instanceof MetaTagged) {
            item = ((MetaTagged) item).getMetaInfo().getThumbnail(thumbnailSize.getWidth(), thumbnailSize.getHeight(), false);
        }
        if (item instanceof VFSLeaf) {
            mediaResource = (VFSLeaf) item;
        }
    } catch (NullPointerException e) {
        log.debug("Media resource could not be created from file: ", fileName);
    }
    return mediaResource;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 97 with VFSItem

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

the class CourseWebService method findEditorTreeModelById.

/**
 * Get the editor tree model of the course by id
 * @response.representation.200.mediaType application/xml
 * @response.representation.200.doc The editor tree model of the course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return It returns the XML representation of the <code>Editor model</code>
 *         object representing the course.
 */
@GET
@Path("editortreemodel")
@Produces(MediaType.APPLICATION_XML)
public Response findEditorTreeModelById(@Context HttpServletRequest httpRequest, @Context Request request) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    VFSItem editorModelItem = course.getCourseBaseContainer().resolve("editortreemodel.xml");
    Date lastModified = new Date(editorModelItem.getLastModified());
    Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
    if (response == null) {
        return Response.ok(myXStream.toXML(course.getEditorTreeModel())).build();
    }
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) VFSItem(org.olat.core.util.vfs.VFSItem) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 98 with VFSItem

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

the class CourseResourceFolderWebService method getFiles.

public Response getFiles(Long courseId, List<PathSegment> path, FolderType type, UriInfo uriInfo, HttpServletRequest httpRequest, Request request) {
    if (!isAuthor(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSContainer container = null;
    RepositoryEntry re = null;
    switch(type) {
        case COURSE_FOLDER:
            container = course.getCourseFolderContainer();
            break;
        case SHARED_FOLDER:
            {
                container = null;
                String sfSoftkey = course.getCourseConfig().getSharedFolderSoftkey();
                OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class).loadRepositoryEntryResourceBySoftKey(sfSoftkey);
                if (sharedResource != null) {
                    re = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(sharedResource.getKey());
                    container = SharedFolderManager.getInstance().getNamedSharedFolder(re, true);
                    CourseConfig courseConfig = course.getCourseConfig();
                    if (courseConfig.isSharedFolderReadOnlyMount()) {
                        container.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                }
                break;
            }
    }
    if (container == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSLeaf leaf = null;
    for (PathSegment seg : path) {
        VFSItem item = container.resolve(seg.getPath());
        if (item instanceof VFSLeaf) {
            leaf = (VFSLeaf) item;
            break;
        } else if (item instanceof VFSContainer) {
            container = (VFSContainer) item;
        }
    }
    if (leaf != null) {
        Date lastModified = new Date(leaf.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            String mimeType = WebappHelper.getMimeType(leaf.getName());
            if (mimeType == null)
                mimeType = MediaType.APPLICATION_OCTET_STREAM;
            response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
        }
        return response.build();
    }
    List<VFSItem> items = container.getItems(new SystemItemFilter());
    int count = 0;
    LinkVO[] links = new LinkVO[items.size()];
    for (VFSItem item : items) {
        UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        UriBuilder repoUri = baseUriBuilder.path(CourseResourceFolderWebService.class).path("files");
        if (type.equals(FolderType.SHARED_FOLDER) && re != null) {
            repoUri = baseUriBuilder.replacePath("restapi").path(SharedFolderWebService.class).path(re.getKey().toString()).path("files");
        }
        for (PathSegment pathSegment : path) {
            repoUri.path(pathSegment.getPath());
        }
        String uri = repoUri.path(item.getName()).build(courseId).toString();
        links[count++] = new LinkVO("self", uri, item.getName());
    }
    return Response.ok(links).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) SharedFolderWebService(org.olat.restapi.repository.SharedFolderWebService) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) VFSItem(org.olat.core.util.vfs.VFSItem) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Response(javax.ws.rs.core.Response) LinkVO(org.olat.restapi.support.vo.LinkVO) UriBuilder(javax.ws.rs.core.UriBuilder) RepositoryService(org.olat.repository.RepositoryService)

Example 99 with VFSItem

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

the class CourseLayoutGeneratorController 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) {
    setFormTitle("tab.layout.title");
    List<String> keys = new ArrayList<String>();
    List<String> vals = new ArrayList<String>();
    List<String> csss = new ArrayList<String>();
    String actualCSSSettings = courseConfig.getCssLayoutRef();
    // add a default option
    keys.add(CourseLayoutHelper.CONFIG_KEY_DEFAULT);
    vals.add(translate("course.layout.default"));
    csss.add("");
    // check for old legacy template, only available if yet one set
    if (actualCSSSettings.startsWith("/") && actualCSSSettings.lastIndexOf("/") == 0) {
        keys.add(actualCSSSettings);
        vals.add(translate("course.layout.legacy", actualCSSSettings));
        csss.add("");
    }
    // add css from hidden coursecss-folder
    VFSContainer coursecssCont = (VFSContainer) courseEnvironment.getCourseFolderContainer().resolve(CourseLayoutHelper.COURSEFOLDER_CSS_BASE);
    if (coursecssCont != null) {
        coursecssCont.setDefaultItemFilter(new VFSItemSuffixFilter(new String[] { "css" }));
        List<VFSItem> coursecssStyles = coursecssCont.getItems();
        if (coursecssStyles != null) {
            for (VFSItem vfsItem : coursecssStyles) {
                keys.add(CourseLayoutHelper.COURSEFOLDER_CSS_BASE + "/" + vfsItem.getName());
                vals.add(translate("course.layout.legacy", vfsItem.getName()));
                csss.add("");
            }
        }
    }
    // get the olat-wide templates
    List<VFSItem> templates = CourseLayoutHelper.getCourseThemeTemplates();
    if (templates != null) {
        for (VFSItem vfsItem : templates) {
            if (CourseLayoutHelper.isCourseThemeFolderValid((VFSContainer) vfsItem)) {
                keys.add(CourseLayoutHelper.CONFIG_KEY_TEMPLATE + vfsItem.getName());
                String name = translate("course.layout.template", vfsItem.getName());
                vals.add(name);
                csss.add("");
            }
        }
    }
    // get the predefined template for this course if any
    VFSItem predefCont = courseEnvironment.getCourseBaseContainer().resolve(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER + "/" + CourseLayoutHelper.CONFIG_KEY_PREDEFINED);
    if (predefCont != null && CourseLayoutHelper.isCourseThemeFolderValid((VFSContainer) predefCont)) {
        keys.add(CourseLayoutHelper.CONFIG_KEY_PREDEFINED);
        vals.add(translate("course.layout.predefined"));
        csss.add("");
    }
    // add option for customizing
    keys.add(CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    vals.add(translate("course.layout.custom"));
    csss.add("");
    String[] theKeys = ArrayHelper.toArray(keys);
    String[] theValues = ArrayHelper.toArray(vals);
    String[] theCssClasses = ArrayHelper.toArray(csss);
    styleSel = uifactory.addDropdownSingleselect("course.layout.selector", formLayout, theKeys, theValues, theCssClasses);
    styleSel.addActionListener(FormEvent.ONCHANGE);
    styleSel.setEnabled(editable);
    if (keys.contains(actualCSSSettings)) {
        styleSel.select(actualCSSSettings, true);
    } else {
        styleSel.select(CourseLayoutHelper.CONFIG_KEY_DEFAULT, true);
    }
    previewImgFlc = FormLayoutContainer.createCustomFormLayout("preview.image", getTranslator(), velocity_root + "/image.html");
    formLayout.add(previewImgFlc);
    previewImgFlc.setLabel("preview.image.label", null);
    refreshPreviewImage(ureq, actualCSSSettings);
    logoImgFlc = FormLayoutContainer.createCustomFormLayout("logo.image", getTranslator(), velocity_root + "/image.html");
    formLayout.add(logoImgFlc);
    logoImgFlc.setLabel("logo.image.label", null);
    refreshLogoImage(ureq);
    // offer upload for 2nd logo
    if (editable) {
        logoUpl = uifactory.addFileElement(getWindowControl(), "upload.second.logo", formLayout);
        logoUpl.addActionListener(FormEvent.ONCHANGE);
        Set<String> mimeTypes = new HashSet<String>();
        mimeTypes.add("image/*");
        logoUpl.limitToMimeType(mimeTypes, "logo.file.type.error", null);
        logoUpl.setMaxUploadSizeKB(2048, "logo.size.error", null);
    }
    // prepare the custom layouter
    styleFlc = FormLayoutContainer.createCustomFormLayout("style", getTranslator(), velocity_root + "/style.html");
    formLayout.add(styleFlc);
    styleFlc.setLabel(null, null);
    enableDisableCustom(CourseLayoutHelper.CONFIG_KEY_CUSTOM.equals(actualCSSSettings));
    if (editable) {
        uifactory.addFormSubmitButton("course.layout.save", formLayout);
    }
}
Also used : VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet)

Example 100 with VFSItem

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

the class CourseLayoutGeneratorController method refreshLogoImage.

private void refreshLogoImage(UserRequest ureq) {
    VFSContainer baseFolder = CourseLayoutHelper.getThemeBaseFolder(courseEnvironment, CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    VFSItem logo = customCMgr.getLogoItem(baseFolder);
    if (logo instanceof VFSLeaf) {
        ImageComponent image = new ImageComponent(ureq.getUserSession(), "preview");
        logoImgFlc.setVisible(true);
        logoImgFlc.put("preview", image);
        image.setMedia((VFSLeaf) logo);
        image.setMaxWithAndHeightToFitWithin(300, 300);
        logoDel = uifactory.addFormLink("logo.delete", logoImgFlc, Link.BUTTON_XSMALL);
        logoDel.setUserObject(logo);
        logoDel.setVisible(editable);
        return;
    }
    logoImgFlc.setVisible(false);
    logoImgFlc.remove(logoImgFlc.getComponent("preview"));
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ImageComponent(org.olat.core.gui.components.image.ImageComponent) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20