add default insert flag
[jSite2.git] / src / net / pterodactylus / jsite / project / AbstractEntry.java
1 /*
2  * jSite2 - AbstractEntry.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.jsite.project;
21
22 import java.io.File;
23
24 import net.pterodactylus.util.beans.AbstractBean;
25
26 /**
27  * Abstract base implementation of a {@link Entry}.
28  * 
29  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
30  */
31 public abstract class AbstractEntry extends AbstractBean implements Entry {
32
33         /** The name of the “name” property. */
34         public static final String PROPERTY_NAME = "name";
35
36         /** The name of the “insert” property. */
37         public static final String PROPERTY_INSERT = "insert";
38
39         /** The name of the “content type” property. */
40         public static final String PROPERTY_CONTENT_TYPE = "contentType";
41
42         /** Whether this entry is virtual. */
43         private final boolean virtual;
44
45         /** The name of the file. */
46         private String name;
47
48         /** The default insert flag for this entry. */
49         private boolean defaultInsert;
50
51         /** Whether to insert the file. */
52         private boolean insert;
53
54         /** The content type of the file. */
55         private String contentType;
56
57         /**
58          * Creates a new entry.
59          * 
60          * @param virtual
61          *            <code>true</code> if this entry is virtual,
62          *            <code>false</code> otherwise
63          */
64         protected AbstractEntry(boolean virtual) {
65                 this.virtual = virtual;
66         }
67
68         /**
69          * {@inheritDoc}
70          */
71         public boolean isVirtual() {
72                 return virtual;
73         }
74
75         /**
76          * {@inheritDoc}
77          */
78         public boolean isDefault() {
79                 return (insert == defaultInsert) && (contentType == null);
80         }
81
82         /**
83          * Sets the default insert flag for this entry. The default insert flag is
84          * derived from {@link File#isHidden()}.
85          * 
86          * @param defaultInsert
87          *            <code>true</code> if the default for this entry is to insert
88          *            it, <code>false</code> otherwise
89          */
90         void setDefaultInsert(boolean defaultInsert) {
91                 this.defaultInsert = defaultInsert;
92         }
93
94         /**
95          * {@inheritDoc}
96          */
97         public String getName() {
98                 return name;
99         }
100
101         /**
102          * {@inheritDoc}
103          */
104         public void setName(String name) {
105                 String oldName = this.name;
106                 this.name = name;
107                 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
108         }
109
110         /**
111          * {@inheritDoc}
112          */
113         public boolean isInsert() {
114                 return insert;
115         }
116
117         /**
118          * {@inheritDoc}
119          */
120         public void setInsert(boolean insert) {
121                 boolean oldInsert = this.insert;
122                 this.insert = insert;
123                 fireIfPropertyChanged(PROPERTY_INSERT, oldInsert, insert);
124         }
125
126         /**
127          * {@inheritDoc}
128          */
129         public String getContentType() {
130                 return contentType;
131         }
132
133         /**
134          * {@inheritDoc}
135          */
136         public void setContentType(String contentType) {
137                 String oldContentType = this.contentType;
138                 this.contentType = contentType;
139                 fireIfPropertyChanged(PROPERTY_CONTENT_TYPE, oldContentType, contentType);
140         }
141
142 }