From: David ‘Bombe’ Roden Date: Wed, 28 May 2008 06:59:37 +0000 (+0200) Subject: add default content type notion X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=095c0cfc66f3c18285c618c278e3be8f22003018;p=jSite2.git add default content type notion --- diff --git a/src/net/pterodactylus/jsite/project/AbstractEntry.java b/src/net/pterodactylus/jsite/project/AbstractEntry.java index 41449b0..6e0c9d4 100644 --- a/src/net/pterodactylus/jsite/project/AbstractEntry.java +++ b/src/net/pterodactylus/jsite/project/AbstractEntry.java @@ -51,6 +51,9 @@ public abstract class AbstractEntry extends AbstractBean implements Entry { /** Whether to insert the file. */ private boolean insert; + /** The default content type of this entry. */ + private String defaultContentType; + /** The content type of the file. */ private String contentType; @@ -76,7 +79,14 @@ public abstract class AbstractEntry extends AbstractBean implements Entry { * {@inheritDoc} */ public boolean isDefault() { - return (insert == defaultInsert) && (contentType == null); + return (insert == defaultInsert) && isDefaultContentType(); + } + + /** + * {@inheritDoc} + */ + public boolean isDefaultContentType() { + return ((defaultContentType != null) ? defaultContentType.equals(contentType) : (contentType == null)); } /** @@ -139,4 +149,15 @@ public abstract class AbstractEntry extends AbstractBean implements Entry { fireIfPropertyChanged(PROPERTY_CONTENT_TYPE, oldContentType, contentType); } + /** + * Sets the default content type of the entry. The default content type is + * derived from its extension. + * + * @param defaultContentType + * The default content type + */ + void setDefaultContentType(String defaultContentType) { + this.defaultContentType = defaultContentType; + } + } diff --git a/src/net/pterodactylus/jsite/project/Entry.java b/src/net/pterodactylus/jsite/project/Entry.java index 8f3783b..86b5904 100644 --- a/src/net/pterodactylus/jsite/project/Entry.java +++ b/src/net/pterodactylus/jsite/project/Entry.java @@ -47,6 +47,14 @@ public interface Entry { public boolean isDefault(); /** + * Returns whether the content type setting is still the default. + * + * @return true if the content type has not been changed by + * the user, false otherwise + */ + public boolean isDefaultContentType(); + + /** * Returns the name of the file. The name can contain multiple path * components, separated by the platform’s {@link File#separatorChar}. It * will never start with a separator, though. diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 5c58763..36a27f9 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; import net.pterodactylus.util.beans.AbstractBean; +import net.pterodactylus.util.io.MimeTypes; /** * Container for project information. A Project is capable of notifying @@ -299,6 +300,12 @@ public class Project extends AbstractBean { entry.setPath(file.getPath()); entry.setDefaultInsert(!file.isHidden()); entry.setInsert(!file.isHidden()); + String extension = fileName.substring(fileName.lastIndexOf('.') + 1); + List mimeTypes = MimeTypes.getMimeTypes(extension); + if (!mimeTypes.isEmpty()) { + entry.setDefaultContentType(mimeTypes.get(0)); + entry.setContentType(mimeTypes.get(0)); + } entries.add(entry); } }