-
Notifications
You must be signed in to change notification settings - Fork 6
/
PathAndQueryStringFileResolver.java
49 lines (41 loc) · 1.51 KB
/
PathAndQueryStringFileResolver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - info@scireum.de
*/
package sirius.biz.storage.layer3;
import sirius.kernel.commons.Strings;
import sirius.kernel.commons.Tuple;
import sirius.kernel.di.std.Register;
import java.io.IOException;
import java.net.URI;
import java.util.Set;
import java.util.function.Predicate;
/**
* Resolves files by using the path and query parameters of the given URI.
* <p>
* If the path ends with a valid file extension, we use it as our virtual path. Otherwise, we check every query string
* parameter and use the first one that has a valid file extension.
*/
@Register
public class PathAndQueryStringFileResolver extends RemoteFileResolver {
@Override
public Tuple<VirtualFile, Boolean> resolve(VirtualFile parent,
URI uri,
FetchFromUrlMode mode,
Predicate<String> fileExtensionVerifier,
Set<Options> options) throws IOException {
String path = parsePathFromUri(uri, fileExtensionVerifier);
if (Strings.isFilled(path)) {
VirtualFile file = resolveVirtualFile(parent, path, uri.getHost(), options);
return Tuple.create(file, file.performLoadFromUri(uri, mode));
}
return null;
}
@Override
public int getPriority() {
return 200;
}
}