Search in sources :

Example 1 with IContentNode

use of org.polymap.service.fs.spi.IContentNode in project polymap4-core by Polymap4.

the class WebDavResourceFactory method getResource.

public Resource getResource(String host, String path) {
    Request request = WebDavServer.request();
    assert request != null;
    ContentManager contentManager = (ContentManager) SessionContext.current().getAttribute("contentManager");
    // get content
    path = StringUtils.substringAfter(path, contextPath);
    IContentNode node = contentManager.getNode(contentManager.parsePath(path));
    return node != null ? wrapContentNode(node, contentManager, securityManager) : null;
}
Also used : Request(io.milton.http.Request) ContentManager(org.polymap.service.fs.ContentManager) IContentNode(org.polymap.service.fs.spi.IContentNode)

Example 2 with IContentNode

use of org.polymap.service.fs.spi.IContentNode in project polymap4-core by Polymap4.

the class ContentManager method checkInitContent.

/**
 * Initialize the content tree up to the given path, including the children of
 * the last node.
 *
 * @param path
 * @return
 */
private CachedNode checkInitContent(IPath path) {
    assert path != null;
    IPath initPath = rootNode.getPath();
    CachedNode lastResult = null;
    for (int i = -1; i < path.segmentCount(); i++) {
        // first loop for the root
        initPath = (i >= 0) ? initPath.append(path.segment(i)) : initPath;
        // check cache expiration
        if (lastResult != null) {
            IContentNode node = lastResult.get(initPath.lastSegment());
            if (node instanceof IContentFolder && !node.isValid()) {
                invalidateFolder((IContentFolder) node);
            }
        }
        // get/create
        lastResult = nodes.get(initPath, new CacheLoader<IPath, CachedNode, RuntimeException>() {

            private int memSize = 1024;

            @Override
            public CachedNode load(IPath key) throws RuntimeException {
                CachedNode result = new CachedNode();
                for (IContentProvider provider : providers) {
                    List<? extends IContentNode> children = provider.getChildren(key);
                    if (children != null) {
                        for (IContentNode child : children) {
                            IContentNode old = result.put(child.getName(), child);
                            if (old != null) {
                                log.warn("!!! Child node name already exists: " + child.getName() + "!!!");
                            }
                            memSize += child.getSizeInMemory();
                        }
                    }
                }
                return result;
            }

            @Override
            public int size() throws RuntimeException {
                return memSize;
            }
        });
    }
    return lastResult;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IContentProvider(org.polymap.service.fs.spi.IContentProvider) CacheLoader(org.polymap.core.runtime.cache.CacheLoader) IContentNode(org.polymap.service.fs.spi.IContentNode) IContentFolder(org.polymap.service.fs.spi.IContentFolder)

Example 3 with IContentNode

use of org.polymap.service.fs.spi.IContentNode in project polymap4-core by Polymap4.

the class ContentManager method dispose.

public void dispose() {
    for (IContentProvider provider : providers) {
        provider.dispose();
    }
    providers = null;
    for (Map<String, IContentNode> children : nodes.values()) {
        for (IContentNode child : children.values()) {
            child.dispose();
        }
    }
    nodes.clear();
    nodes.dispose();
    nodes = null;
}
Also used : IContentProvider(org.polymap.service.fs.spi.IContentProvider) IContentNode(org.polymap.service.fs.spi.IContentNode)

Example 4 with IContentNode

use of org.polymap.service.fs.spi.IContentNode in project polymap4-core by Polymap4.

the class ContentManager method invalidateFolder.

public void invalidateFolder(IContentFolder node) {
    assert node != null;
    // IPath path = node.getPath();
    // IPath parentPath = path.removeLastSegments( 1 );
    // String nodeName = path.lastSegment();
    // Map<String,IContentNode> parentChildren = nodes.get( parentPath );
    // 
    // if (parentChildren != null) {
    // IContentNode found = parentChildren.get( nodeName );
    // if (found == node) {
    // parentChildren.remove( nodeName );
    // }
    // }
    Map<String, IContentNode> children = nodes.remove(node.getPath());
    if (children != null) {
        // XXX do it recursively?
        for (IContentNode child : children.values()) {
            nodes.remove(child.getPath());
            child.dispose();
        }
    }
    node.dispose();
}
Also used : IContentNode(org.polymap.service.fs.spi.IContentNode)

Example 5 with IContentNode

use of org.polymap.service.fs.spi.IContentNode in project polymap4-core by Polymap4.

the class FsContentProvider method getChildren.

@Override
public List<? extends IContentNode> getChildren(IPath path) {
    // check admin
    if (!SecurityUtils.isAdmin()) {
        return null;
    }
    // roots
    if (path.segmentCount() == 0) {
        return roots;
    }
    // folder
    IContentFolder parent = getSite().getFolder(path);
    // check exact class because CmsFolder is instanceof FsFolder too
    if (parent.getClass().equals(FsFolder.class)) {
        File[] files = ((FsFolder) parent).getDir().listFiles();
        List<IContentNode> result = new ArrayList(files.length);
        for (File f : files) {
            if (f.isFile()) {
                result.add(new FsFile(parent.getPath(), this, f));
            } else if (f.isDirectory()) {
                result.add(new FsFolder(f.getName(), parent.getPath(), this, f));
            }
        }
        return result;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IContentFile(org.polymap.service.fs.spi.IContentFile) File(java.io.File) IContentFolder(org.polymap.service.fs.spi.IContentFolder) IContentNode(org.polymap.service.fs.spi.IContentNode)

Aggregations

IContentNode (org.polymap.service.fs.spi.IContentNode)6 IPath (org.eclipse.core.runtime.IPath)2 IContentFolder (org.polymap.service.fs.spi.IContentFolder)2 IContentProvider (org.polymap.service.fs.spi.IContentProvider)2 Request (io.milton.http.Request)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 CacheLoader (org.polymap.core.runtime.cache.CacheLoader)1 ContentManager (org.polymap.service.fs.ContentManager)1 IContentFile (org.polymap.service.fs.spi.IContentFile)1