Search in sources :

Example 51 with LocalFileImpl

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

the class FileElementImpl method reset.

@Override
public void reset() {
    if (tempUploadFile != null && tempUploadFile.exists()) {
        tempUploadFile.delete();
    }
    tempUploadFile = null;
    if (previewEl != null) {
        if (initialFile != null) {
            VFSLeaf media = new LocalFileImpl(initialFile);
            previewEl.setMedia(media);
            previewEl.setMaxWithAndHeightToFitWithin(300, 200);
            previewEl.setVisible(true);
        } else if (previewEl != null) {
            previewEl.setVisible(false);
        }
    }
    uploadFilename = null;
    uploadMimeType = null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 52 with LocalFileImpl

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

the class FileElementImpl method setInitialFile.

@Override
public void setInitialFile(File initialFile) {
    this.initialFile = initialFile;
    if (initialFile != null && previewEl != null) {
        VFSLeaf media = new LocalFileImpl(initialFile);
        previewEl.setMedia(media);
        previewEl.setMaxWithAndHeightToFitWithin(300, 200);
        previewEl.setVisible(true);
    } else if (previewEl != null) {
        previewEl.setVisible(false);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 53 with LocalFileImpl

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

the class ProjectBrokerCourseNode method importProject.

private void importProject(File projectDir, File projectFile, ProjectBroker projectBroker, ICourse course, CourseEnvironmentMapper envMapper) {
    XStream xstream = XStreamHelper.createXStreamInstance();
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    // read the projectConfiguration from the importDirectory
    try {
        @SuppressWarnings("unchecked") Map<String, Object> projectConfig = (HashMap<String, Object>) XStreamHelper.readObject(xstream, projectFile);
        String projectTitle = (String) projectConfig.get("title");
        Long originalGroupKey = null;
        if (projectConfig.containsKey("businessGroupKey")) {
            originalGroupKey = (Long) projectConfig.get("businessGroupKey");
        } else {
            for (BusinessGroupReference ref : envMapper.getGroups()) {
                if (ref.getName().endsWith(projectTitle)) {
                    originalGroupKey = ref.getOriginalKey();
                }
            }
        }
        BusinessGroup projectGroup = null;
        if (originalGroupKey != null) {
            Long groupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
            projectGroup = bgs.loadBusinessGroup(groupKey);
        }
        if (projectGroup == null) {
            projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), envMapper.getAuthor(), projectTitle, (String) projectConfig.get("description"), course.getResourceableId());
        }
        if (envMapper.getAuthor() != null) {
            Identity author = envMapper.getAuthor();
            bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
        }
        Project project = projectBrokerManager.createAndSaveProjectFor(projectTitle, (String) projectConfig.get("description"), projectBrokerManager.getProjectBrokerId(cpm, this), projectGroup);
        projectGroupManager.setDeselectionAllowed(project, (boolean) projectConfig.get("allowDeselection"));
        project.setMailNotificationEnabled((boolean) projectConfig.get("mailNotificationEnabled"));
        project.setMaxMembers((int) projectConfig.get("maxMembers"));
        project.setAttachedFileName(projectConfig.get("attachmentFileName").toString());
        for (int i = 0; i < (int) projectConfig.get("customeFieldSize"); i++) {
            project.setCustomFieldValue(i, projectConfig.get("customFieldValue" + i).toString());
        }
        projectBrokerManager.updateProject(project);
        // get the attachment directory within the project
        // directory
        // .getParentFile().listFiles(attachmentFilter);
        File attachmentDir = new File(projectDir, "attachment");
        if (attachmentDir.exists()) {
            File[] attachment = attachmentDir.listFiles();
            if (attachment.length > 0) {
                VFSLeaf attachmentLeaf = new LocalFileImpl(attachment[0]);
                projectBrokerManager.saveAttachedFile(project, projectConfig.get("attachmentFileName").toString(), attachmentLeaf, course.getCourseEnvironment(), this);
            }
        }
    } catch (Exception e) {
        // handle/log error in case of FileIO exception or cast
        // exception if import input is not correct
        log.error("Error while importing a project into projectbroker", e);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) XStream(com.thoughtworks.xstream.XStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) Identity(org.olat.core.id.Identity) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 54 with LocalFileImpl

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

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 55 with LocalFileImpl

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

the class ForumWebService method getAttachment.

/**
 * Retrieves the attachment of the message
 * @response.representation.200.mediaType application/octet-stream
 * @response.representation.200.doc The portrait as image
 * @response.representation.404.doc The identity or the portrait not found
 * @param messageKey The identity key of the user being searched
 * @param filename The name of the attachment
 * @param request The REST request
 * @return The attachment
 */
@GET
@Path("posts/{messageKey}/attachments/{filename}")
@Produces({ "*/*", MediaType.APPLICATION_OCTET_STREAM })
public Response getAttachment(@PathParam("messageKey") Long messageKey, @PathParam("filename") String filename, @Context Request request) {
    // load message
    Message mess = fom.loadMessage(messageKey);
    if (mess == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!forum.equalsByPersistableKey(mess.getForum())) {
        return Response.serverError().status(Status.CONFLICT).build();
    }
    VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
    VFSItem item = container.resolve(filename);
    if (item instanceof LocalFileImpl) {
        // local file -> the length is given to the client which is good
        Date lastModified = new Date(item.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            File attachment = ((LocalFileImpl) item).getBasefile();
            String mimeType = WebappHelper.getMimeType(attachment.getName());
            if (mimeType == null)
                mimeType = "application/octet-stream";
            response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
        }
        return response.build();
    } else if (item instanceof VFSLeaf) {
        // stream -> the length is not given to the client which is not nice
        Date lastModified = new Date(item.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            StreamingOutput attachment = new VFSStreamingOutput((VFSLeaf) item);
            String mimeType = WebappHelper.getMimeType(item.getName());
            if (mimeType == null)
                mimeType = "application/octet-stream";
            response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
        }
        return response.build();
    }
    return Response.serverError().status(Status.NOT_FOUND).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Message(org.olat.modules.fo.Message) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VFSStreamingOutput(org.olat.core.util.vfs.restapi.VFSStreamingOutput) VFSStreamingOutput(org.olat.core.util.vfs.restapi.VFSStreamingOutput) StreamingOutput(javax.ws.rs.core.StreamingOutput) Date(java.util.Date) Response(javax.ws.rs.core.Response) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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