Package org.apache.wicket.resource
Class FileSystemResourceReference
- java.lang.Object
-
- org.apache.wicket.request.resource.ResourceReference
-
- org.apache.wicket.resource.FileSystemResourceReference
-
- All Implemented Interfaces:
java.io.Serializable,org.apache.wicket.util.io.IClusterable
public class FileSystemResourceReference extends ResourceReference
This resource reference is used to provide a reference to a resource based on Java NIO FileSystem API.
To implement a mime type detection refer to the documentation ofFiles.probeContentType(Path)and provide an implementation for java.nio.file.spi.FileTypeDetector in the META-INF/services folder for jars or in the /WEB-INF/classes/META-INF/services folder for webapps
You can optionally overridegetFileSystemResource()to provide an inline mime type detection, which is preferred to the default detection.
Example:
Example 2:Path path = FileSystemResourceReference.getPath(URI.create("jar:file:///folder/file.zip!/folderInZip/video.mp4")); add(new Video("video", new FileSystemResourceReference(path)));mountResource("/filecontent/${name}", new FileSystemResourceReference("filesystem") { private static final long serialVersionUID = 1L; @Override public IResource getResource() { return new FileSystemResource() { private static final long serialVersionUID = 1L; protected ResourceResponse newResourceResponse(Attributes attributes) { try { String name = attributes.getParameters().get("name").toString(""); URI uri = URI.create( "jar:file:////folder/example.zip!/zipfolder/" + name); return createResourceResponse( FileSystemResourceReference.getPath(uri)); } catch (IOException | URISyntaxException e) { throw new WicketRuntimeException("Error while reading the file.", e); } }; }; } });- Author:
- Tobias Soloschenko
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.wicket.request.resource.ResourceReference
ResourceReference.Key, ResourceReference.LambdaResourceReference, ResourceReference.UrlAttributes
-
-
Constructor Summary
Constructors Constructor Description FileSystemResourceReference(java.lang.Class<?> scope, java.lang.String name)Creates a file system resource reference based on the given scope and nameFileSystemResourceReference(java.lang.String name)Creates a file system resource reference based on the given nameFileSystemResourceReference(java.lang.String name, java.nio.file.Path path)Creates a file system resource reference based on the given path
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected FileSystemResourcegetFileSystemResource()Gets the file system resource to be used for the resource referencestatic java.nio.file.PathgetPath(java.net.URI uri)Creates a path and a file system (if required) based on the given URIstatic java.nio.file.PathgetPath(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> env)Creates a path and a file system (if required) based on the given URIIResourcegetResource()Creates a neworg.apache.wicket.markup.html.media.FileSystemResourceand applies the path to it.-
Methods inherited from class org.apache.wicket.request.resource.ResourceReference
canBeRegistered, equals, getDependencies, getExtension, getKey, getLocale, getName, getScope, getStyle, getUrlAttributes, getVariation, hashCode, of, of, toString
-
-
-
-
Constructor Detail
-
FileSystemResourceReference
public FileSystemResourceReference(java.lang.String name, java.nio.file.Path path)Creates a file system resource reference based on the given path- Parameters:
name- the name of the resource reference to expose datapath- the path to create the resource reference
-
FileSystemResourceReference
public FileSystemResourceReference(java.lang.String name)
Creates a file system resource reference based on the given name- Parameters:
name- the name of the resource reference
-
FileSystemResourceReference
public FileSystemResourceReference(java.lang.Class<?> scope, java.lang.String name)Creates a file system resource reference based on the given scope and name- Parameters:
scope- the scope as classname- the name of the resource reference
-
-
Method Detail
-
getResource
public IResource getResource()
Creates a neworg.apache.wicket.markup.html.media.FileSystemResourceand applies the path to it.- Specified by:
getResourcein classResourceReference- Returns:
- resource instance
-
getFileSystemResource
protected FileSystemResource getFileSystemResource()
Gets the file system resource to be used for the resource reference- Returns:
- the file system resource to be used for the resource reference
-
getPath
public static java.nio.file.Path getPath(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> env)Creates a path and a file system (if required) based on the given URI- Parameters:
uri- the URI to create the file system and the path ofenv- the environment parameter to create the file system with- Returns:
- the path of the file in the file system
-
getPath
public static java.nio.file.Path getPath(java.net.URI uri) throws java.io.IOException, java.net.URISyntaxExceptionCreates a path and a file system (if required) based on the given URI- Parameters:
uri- the URI to create the file system and the path of- Returns:
- the path of the file in the file system
- Throws:
java.io.IOException- if the file system could'nt be createdjava.net.URISyntaxException- if the URI has no valid syntax
-
-