<dependency>
<groupId>net.pterodactylus</groupId>
<artifactId>utils</artifactId>
- <version>0.12.1</version>
+ <version>0.13</version>
</dependency>
<dependency>
<groupId>junit</groupId>
package de.todesbaum.jsite.application;
import java.io.File;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
*/
public FileOption getFileOption(String filename) {
FileOption fileOption = fileOptions.get(filename);
+ String defaultMimeType = "application/octet-stream";
if (fileOption == null) {
- fileOption = new FileOption(MimeTypes.getMimeType(filename.substring(filename.lastIndexOf('.') + 1)));
- fileOptions.put(filename, fileOption);
+ List<String> suffixes = getSuffixes(filename);
+ for (String suffix : suffixes) {
+ String mimeType = MimeTypes.getMimeType(suffix);
+ if (!mimeType.equals(defaultMimeType)) {
+ defaultMimeType = mimeType;
+ break;
+ }
+ }
+ fileOption = new FileOption(defaultMimeType);
}
+ fileOptions.put(filename, fileOption);
return fileOption;
}
+ private List<String> getSuffixes(String filename) {
+ List<String> suffixes = new ArrayList<>();
+ int dot = filename.lastIndexOf(".");
+ while (dot > -1) {
+ String suffix = filename.substring(dot + 1);
+ suffixes.add(0, suffix);
+ dot = filename.lastIndexOf(".", dot - 1);
+ }
+ return suffixes;
+ }
+
/**
* Sets options for a file.
*
--- /dev/null
+package de.todesbaum.jsite.application;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ProjectTest}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ProjectTest {
+
+ @Test
+ public void mimeTypeForTarBz2IsRecognizedCorrectly() {
+ Project project = new Project();
+ FileOption fileOption = project.getFileOption("foo.tar.bz2");
+ assertThat(fileOption.getMimeType(), is("application/x-gtar"));
+ }
+
+}