/*
- * jSite - Project.java - Copyright © 2006–2014 David Roden
+ * jSite - Project.java - Copyright © 2006–2019 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
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;
lastInsertionTime = project.lastInsertionTime;
alwaysForceInserts = project.alwaysForceInserts;
ignoreHiddenFiles = project.ignoreHiddenFiles;
- fileOptions = new HashMap<String, FileOption>(project.fileOptions);
+ for (Entry<String, FileOption> fileOption : fileOptions.entrySet()) {
+ fileOptions.put(fileOption.getKey(), new FileOption(fileOption.getValue()));
+ }
}
/**
*/
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.
*
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.getChangedName().or(fileOptionEntry.getKey()));
+ fileOption.setLastInsertFilename(fileOption.getChangedName().orElse(fileOptionEntry.getKey()));
}
fileOption.setForceInsert(false);
}