in app/src/main/java/org/apache/roller/weblogger/business/FileContentManagerImpl.java [274:361]
private boolean checkFileType(String[] allowFiles, String[] forbidFiles,
String fileName, String contentType) {
// TODO: Atom Publishing Protocol figure out how to handle file
// allow/forbid using contentType.
// TEMPORARY SOLUTION: In the allow/forbid lists we will continue to
// allow user to specify file extensions (e.g. gif, png, jpeg) but will
// now also allow them to specify content-type rules (e.g. */*, image/*,
// text/xml, etc.).
// if content type is invalid, reject file
if (contentType == null || contentType.indexOf('/') == -1) {
return false;
}
// default to false
boolean allowFile = false;
// if this person hasn't listed any allows, then assume they want
// to allow *all* filetypes, except those listed under forbid
if (allowFiles == null || allowFiles.length < 1) {
allowFile = true;
}
// First check against what is ALLOWED
// check file against allowed file extensions
if (allowFiles != null && allowFiles.length > 0) {
for (int y = 0; y < allowFiles.length; y++) {
// oops, this allowed rule is a content-type, skip it
if (allowFiles[y].indexOf('/') != -1) {
continue;
}
if (fileName.toLowerCase()
.endsWith(allowFiles[y].toLowerCase())) {
allowFile = true;
break;
}
}
}
// check file against allowed contentTypes
if (allowFiles != null && allowFiles.length > 0) {
for (int y = 0; y < allowFiles.length; y++) {
// oops, this allowed rule is NOT a content-type, skip it
if (allowFiles[y].indexOf('/') == -1) {
continue;
}
if (matchContentType(allowFiles[y], contentType)) {
allowFile = true;
break;
}
}
}
// First check against what is FORBIDDEN
// check file against forbidden file extensions, overrides any allows
if (forbidFiles != null && forbidFiles.length > 0) {
for (int x = 0; x < forbidFiles.length; x++) {
// oops, this forbid rule is a content-type, skip it
if (forbidFiles[x].indexOf('/') != -1) {
continue;
}
if (fileName.toLowerCase().endsWith(
forbidFiles[x].toLowerCase())) {
allowFile = false;
break;
}
}
}
// check file against forbidden contentTypes, overrides any allows
if (forbidFiles != null && forbidFiles.length > 0) {
for (int x = 0; x < forbidFiles.length; x++) {
// oops, this forbid rule is NOT a content-type, skip it
if (forbidFiles[x].indexOf('/') == -1) {
continue;
}
if (matchContentType(forbidFiles[x], contentType)) {
allowFile = false;
break;
}
}
}
return allowFile;
}