Package org.apache.wicket.resource
Class FileSystemResourceReference
- java.lang.Object
-
- org.apache.wicket.request.resource.ResourceReference
-
- org.apache.wicket.resource.FileSystemResourceReference
-
- All Implemented Interfaces:
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(attributes, 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(Class<?> scope, String name)Creates a file system resource reference based on the given scope and nameFileSystemResourceReference(String name)Creates a file system resource reference based on the given nameFileSystemResourceReference(String name, 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 PathgetPath(URI uri)Creates a path and a file system (if required) based on the given URIstatic PathgetPath(URI uri, Map<String,String> env)Creates a path and a file system (if required) based on the given URIIResourcegetResource()Creates a newFileSystemResourceand 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(String name, 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(String name)
Creates a file system resource reference based on the given name- Parameters:
name- the name of the resource reference
-
FileSystemResourceReference
public FileSystemResourceReference(Class<?> scope, 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 newFileSystemResourceand 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 Path getPath(URI uri, Map<String,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 Path getPath(URI uri) throws IOException, URISyntaxException
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 of- Returns:
- the path of the file in the file system
- Throws:
IOException- if the file system could'nt be createdURISyntaxException- if the URI has no valid syntax
-
-