java.lang.Object
org.apache.wicket.request.resource.ResourceReference
org.apache.wicket.resource.FileSystemResourceReference
- All Implemented Interfaces:
Serializable
,IClusterable
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 of
You can optionally override
Example:
To implement a mime type detection refer to the documentation of
Files.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 webappsYou can optionally override
getFileSystemResource()
to provide an inline mime type
detection, which is preferred to the default detection.Example:
Path path = FileSystemResourceReference.getPath(URI.create("jar:file:///folder/file.zip!/folderInZip/video.mp4"));
add(new Video("video", new FileSystemResourceReference(path)));
Example 2:
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.wicket.request.resource.ResourceReference
ResourceReference.Key, ResourceReference.LambdaResourceReference, ResourceReference.UrlAttributes
-
Constructor Summary
ConstructorDescriptionFileSystemResourceReference
(Class<?> scope, String name) Creates a file system resource reference based on the given scope and nameCreates 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
Modifier and TypeMethodDescriptionprotected FileSystemResource
Gets the file system resource to be used for the resource referencestatic Path
Creates a path and a file system (if required) based on the given URIstatic Path
Creates a path and a file system (if required) based on the given URICreates a newFileSystemResource
and 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 Details
-
FileSystemResourceReference
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
Creates a file system resource reference based on the given name- Parameters:
name
- the name of the resource reference
-
FileSystemResourceReference
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 Details
-
getResource
Creates a newFileSystemResource
and applies the path to it.- Specified by:
getResource
in classResourceReference
- Returns:
- resource instance
-
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
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
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
-