in src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java [33:68]
public String extract(String name) {
// If the name is a URL, skip the trailing query and fragment parts
int question = name.indexOf('?');
if (question != -1) {
name = name.substring(0, question);
}
int hash = name.indexOf('#');
if (hash != -1) {
name = name.substring(0, hash);
}
// If the name is a URL or a path, skip all but the last component
int slash = name.lastIndexOf('/');
if (slash != -1) {
name = name.substring(slash + 1);
}
int backslash = name.lastIndexOf('\\');
if (backslash != -1) {
name = name.substring(backslash + 1);
}
// Decode any potential URL encoding
int percent = name.indexOf('%');
if (percent != -1) {
final String encoding = getDefaultEncoding();
try {
name = URLDecoder.decode(name, encoding);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(encoding + " not supported??", e);
}
}
// Skip any leading or trailing whitespace
name = name.trim();
return name;
}