add default content type notion
[jSite2.git] / src / net / pterodactylus / jsite / project / Project.java
index ab0b363..36a27f9 100644 (file)
@@ -25,13 +25,13 @@ 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
  * {@link PropertyChangeListener}s if any of the contained properties change.
  * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
  */
 public class Project extends AbstractBean {
 
@@ -78,6 +78,28 @@ public class Project extends AbstractBean {
        private List<Entry> virtualEntries = new ArrayList<Entry>();
 
        /**
+        * Creates a new project.
+        */
+       public Project() {
+               /* do nothing. */
+       }
+
+       /**
+        * Clones the given project.
+        * 
+        * @param project
+        */
+       Project(Project project) {
+               this.name = project.name;
+               this.description = project.description;
+               this.publicKey = project.publicKey;
+               this.privateKey = project.privateKey;
+               this.basePath = project.basePath;
+               this.basePathEntries.addAll(project.basePathEntries);
+               this.virtualEntries.addAll(project.virtualEntries);
+       }
+
+       /**
         * Returns the internal ID.
         * 
         * @return The internal ID
@@ -276,7 +298,14 @@ public class Project extends AbstractBean {
                        PhysicalEntry entry = new PhysicalEntry();
                        entry.setName(fileName);
                        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);
                }
        }