use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class VfsResourceReferenceHandler method handle.
@Override
public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException {
// This code only handles VFS Resource References.
VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference;
try {
// Verify that the user has the permission for the specified VFS scheme and for the VFS URI
this.permissionChecker.checkPermission(vfsResourceReference);
// Extract the asked resource from inside the zip and return its content for display.
// We need to convert the VFS Resource Reference into a hierarchical URI supported by TrueVFS
URI trueVFSURI = convertResourceReference(vfsResourceReference);
// We use TrueVFS. This line will automatically use the VFS Driver that matches the scheme passed in the URI
Path path = new TPath(trueVFSURI);
try (InputStream in = Files.newInputStream(path)) {
List<String> pathSegments = vfsResourceReference.getPathSegments();
serveResource(pathSegments.get(pathSegments.size() - 1), in);
}
} catch (Exception e) {
throw new ResourceReferenceHandlerException(String.format("Failed to extract resource [%s]", vfsResourceReference), e);
}
// Be a good citizen, continue the chain, in case some lower-priority Handler has something to do for this
// Resource Reference.
chain.handleNext(vfsResourceReference);
}
Aggregations