Search in sources :

Example 21 with SystemItemFilter

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

the class VersionsFileManager method pruneVersionHistory.

private void pruneVersionHistory(VFSContainer container, long maxHistoryLength, ProgressDelegate progress, int count) {
    List<VFSItem> children = container.getItems(new SystemItemFilter());
    for (VFSItem child : children) {
        if (child instanceof VFSContainer) {
            if (progress != null)
                progress.setActual(++count);
            pruneVersionHistory((VFSContainer) child, maxHistoryLength, progress, count);
        }
        if (child instanceof VFSLeaf) {
            VFSLeaf versionsLeaf = (VFSLeaf) child;
            pruneVersionHistory(versionsLeaf, maxHistoryLength, progress);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 22 with SystemItemFilter

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

the class VFSWebservice method resolveFile.

protected VFSItem resolveFile(List<PathSegment> path) {
    VFSContainer directory = container;
    VFSItem resolvedItem = directory;
    boolean notFound = false;
    // remove trailing segment if a trailing / is used
    if (path.size() > 0 && !StringHelper.containsNonWhitespace(path.get(path.size() - 1).getPath())) {
        path = path.subList(0, path.size() - 1);
    }
    a_a: for (PathSegment seg : path) {
        String segPath = seg.getPath();
        for (VFSItem item : directory.getItems(new SystemItemFilter())) {
            if (normalize(item.getName()).equals(segPath)) {
                if (item instanceof VFSLeaf) {
                    if (path.get(path.size() - 1) == seg) {
                        resolvedItem = item;
                        break a_a;
                    }
                } else if (item instanceof VFSContainer) {
                    resolvedItem = directory = (VFSContainer) item;
                    continue a_a;
                }
            }
        }
        notFound = true;
    }
    if (notFound) {
        return null;
    }
    return resolvedItem;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 23 with SystemItemFilter

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

the class VFSWebservice method resolveContainer.

protected VFSContainer resolveContainer(List<PathSegment> path, boolean create) {
    VFSContainer directory = container;
    boolean notFound = false;
    // remove trailing segment if a trailing / is used
    if (path.size() > 0 && !StringHelper.containsNonWhitespace(path.get(path.size() - 1).getPath())) {
        path = path.subList(0, path.size() - 1);
    }
    a_a: for (PathSegment seg : path) {
        String segPath = seg.getPath();
        for (VFSItem item : directory.getItems(new SystemItemFilter())) {
            if (item instanceof VFSLeaf) {
            // 
            } else if (item instanceof VFSContainer && normalize(item.getName()).equals(segPath)) {
                directory = (VFSContainer) item;
                continue a_a;
            }
        }
        if (create) {
            directory = directory.createChildContainer(segPath);
        } else if (path.get(path.size() - 1) == seg) {
            break a_a;
        } else {
            notFound = true;
        }
    }
    if (notFound) {
        return null;
    }
    return directory;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 24 with SystemItemFilter

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

the class VFSWebservice method get.

protected Response get(List<PathSegment> path, UriInfo uriInfo, Request request) {
    VFSItem vItem = resolveFile(path);
    if (vItem == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (vItem instanceof VFSContainer) {
        VFSContainer directory = (VFSContainer) vItem;
        List<VFSItem> items = directory.getItems(new SystemItemFilter());
        int count = 0;
        FileVO[] links = new FileVO[items.size()];
        for (VFSItem item : items) {
            UriBuilder builder = uriInfo.getAbsolutePathBuilder();
            String uri = builder.path(normalize(item.getName())).build().toString();
            if (item instanceof VFSLeaf) {
                links[count++] = new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize());
            } else {
                links[count++] = new FileVO("self", uri, item.getName());
            }
        }
        return Response.ok(links).build();
    } else if (vItem instanceof VFSLeaf) {
        VFSLeaf leaf = (VFSLeaf) vItem;
        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();
    }
    return Response.serverError().status(Status.BAD_REQUEST).build();
}
Also used : Response(javax.ws.rs.core.Response) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileVO(org.olat.restapi.support.vo.FileVO) VFSItem(org.olat.core.util.vfs.VFSItem) List(java.util.List) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) UriBuilder(javax.ws.rs.core.UriBuilder) Date(java.util.Date)

Example 25 with SystemItemFilter

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

the class ForumWebService method getAttachments.

private FileVO[] getAttachments(Message mess, UriInfo uriInfo) {
    VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
    List<FileVO> attachments = new ArrayList<FileVO>();
    for (VFSItem item : container.getItems(new SystemItemFilter())) {
        UriBuilder attachmentUri = uriInfo.getBaseUriBuilder().path("repo").path("forums").path(mess.getForum().getKey().toString()).path("posts").path(mess.getKey().toString()).path("attachments").path(format(item.getName()));
        String uri = attachmentUri.build().toString();
        if (item instanceof VFSLeaf) {
            attachments.add(new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize()));
        } else {
            attachments.add(new FileVO("self", uri, item.getName()));
        }
    }
    FileVO[] attachmentArr = new FileVO[attachments.size()];
    attachmentArr = attachments.toArray(attachmentArr);
    return attachmentArr;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileVO(org.olat.restapi.support.vo.FileVO) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)36 VFSItem (org.olat.core.util.vfs.VFSItem)34 VFSContainer (org.olat.core.util.vfs.VFSContainer)30 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)24 Date (java.util.Date)10 OutputStream (java.io.OutputStream)8 PathSegment (javax.ws.rs.core.PathSegment)8 UriBuilder (javax.ws.rs.core.UriBuilder)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 RepositoryEntry (org.olat.repository.RepositoryEntry)4 FileVO (org.olat.restapi.support.vo.FileVO)4 LinkVO (org.olat.restapi.support.vo.LinkVO)4 File (java.io.File)2 Collator (java.text.Collator)2 HashSet (java.util.HashSet)2