use of org.polymap.service.fs.spi.IContentFolder 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;
}
use of org.polymap.service.fs.spi.IContentFolder 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;
}
use of org.polymap.service.fs.spi.IContentFolder in project polymap4-core by Polymap4.
the class WebDavFolderResource method sendContent.
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException {
try {
org.polymap.service.fs.spi.Range fsRange = range != null ? new org.polymap.service.fs.spi.Range(range.getStart(), range.getFinish()) : null;
((IContentFolder) node).sendDescription(out, fsRange, params, contentType);
// if (contentType.toLowerCase().contains( "html" )) {
// new OutputStreamWriter( out, Charset.forName( "UTF-8" ) )
// .append( "<hr><em>Generated by POLYMAP3 WebDAV</hr></em>" ).flush();
// }
} catch (IOException e) {
throw e;
} catch (org.polymap.service.fs.spi.BadRequestException e) {
throw new BadRequestException(this, e.getMessage());
}
}
Aggregations