public class FileSystemResourceReference extends ResourceReference
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 webappsgetFileSystemResource()
to provide an inline mime type
detection, which is preferred to the default detection.
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);
}
};
};
}
});
ResourceReference.Key, ResourceReference.LambdaResourceReference, ResourceReference.UrlAttributes
Constructor and Description |
---|
FileSystemResourceReference(Class<?> scope,
String name)
Creates a file system resource reference based on the given scope and name
|
FileSystemResourceReference(String name)
Creates a file system resource reference based on the given name
|
FileSystemResourceReference(String name,
Path path)
Creates a file system resource reference based on the given path
|
Modifier and Type | Method and Description |
---|---|
protected FileSystemResource |
getFileSystemResource()
Gets the file system resource to be used for the resource reference
|
static Path |
getPath(URI uri)
Creates a path and a file system (if required) based on the given URI
|
static Path |
getPath(URI uri,
Map<String,String> env)
Creates a path and a file system (if required) based on the given URI
|
IResource |
getResource()
Creates a new
org.apache.wicket.markup.html.media.FileSystemResource and applies the
path to it. |
canBeRegistered, equals, getDependencies, getExtension, getKey, getLocale, getName, getScope, getStyle, getUrlAttributes, getVariation, hashCode, of, of, toString
public FileSystemResourceReference(String name, Path path)
name
- the name of the resource reference to expose datapath
- the path to create the resource referencepublic FileSystemResourceReference(String name)
name
- the name of the resource referencepublic IResource getResource()
org.apache.wicket.markup.html.media.FileSystemResource
and applies the
path to it.getResource
in class ResourceReference
protected FileSystemResource getFileSystemResource()
public static Path getPath(URI uri, Map<String,String> env)
uri
- the URI to create the file system and the path ofenv
- the environment parameter to create the file system withpublic static Path getPath(URI uri) throws IOException, URISyntaxException
uri
- the URI to create the file system and the path ofIOException
- if the file system could'nt be createdURISyntaxException
- if the URI has no valid syntaxCopyright © 2006–2022 Apache Software Foundation. All rights reserved.