X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FProject.java;h=59dcba96811a2ffd6e0fe1c9bdc93ae82fb73a47;hb=a0b445d7885312ba0c330474ce460dc4749c6e27;hp=484de85638fee75d726b5faa91b021cbb6e94050;hpb=38bdc433e50669e8244a63b5af59e597f88f1d29;p=jSite.git diff --git a/src/main/java/de/todesbaum/jsite/application/Project.java b/src/main/java/de/todesbaum/jsite/application/Project.java index 484de85..59dcba9 100644 --- a/src/main/java/de/todesbaum/jsite/application/Project.java +++ b/src/main/java/de/todesbaum/jsite/application/Project.java @@ -1,5 +1,5 @@ /* - * jSite - Project.java - Copyright © 2006–2012 David Roden + * jSite - Project.java - Copyright © 2006–2014 David Roden * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -19,8 +19,10 @@ 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; @@ -94,7 +96,9 @@ public class Project implements Comparable { lastInsertionTime = project.lastInsertionTime; alwaysForceInserts = project.alwaysForceInserts; ignoreHiddenFiles = project.ignoreHiddenFiles; - fileOptions = new HashMap(project.fileOptions); + for (Entry fileOption : fileOptions.entrySet()) { + fileOptions.put(fileOption.getKey(), new FileOption(fileOption.getValue())); + } } /** @@ -363,13 +367,33 @@ public class Project implements Comparable { */ 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 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 getSuffixes(String filename) { + List 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. * @@ -460,7 +484,7 @@ public class Project implements Comparable { if ((fileOption.getCurrentHash() != null) && (fileOption.getCurrentHash().length() > 0) && (!fileOption.getCurrentHash().equals(fileOption.getLastInsertHash()) || fileOption.isForceInsert())) { fileOption.setLastInsertEdition(edition); fileOption.setLastInsertHash(fileOption.getCurrentHash()); - fileOption.setLastInsertFilename(fileOption.hasChangedName() ? fileOption.getChangedName() : fileOptionEntry.getKey()); + fileOption.setLastInsertFilename(fileOption.getChangedName().orElse(fileOptionEntry.getKey())); } fileOption.setForceInsert(false); }