/** 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;
* {@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));
}
/**
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;
+ }
+
}
public boolean isDefault();
/**
+ * Returns whether the content type setting is still the default.
+ *
+ * @return <code>true</code> if the content type has not been changed by
+ * the user, <code>false</code> 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.
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
entry.setPath(file.getPath());
entry.setDefaultInsert(!file.isHidden());
entry.setInsert(!file.isHidden());
+ String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
+ List<String> mimeTypes = MimeTypes.getMimeTypes(extension);
+ if (!mimeTypes.isEmpty()) {
+ entry.setDefaultContentType(mimeTypes.get(0));
+ entry.setContentType(mimeTypes.get(0));
+ }
entries.add(entry);
}
}