2 * jSite2 - AbstractEntry.java -
3 * Copyright © 2008 David Roden
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.
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.
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.
20 package net.pterodactylus.jsite.project;
24 import net.pterodactylus.util.beans.AbstractBean;
27 * Abstract base implementation of a {@link Entry}.
29 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31 public abstract class AbstractEntry extends AbstractBean implements Entry {
33 /** The name of the “name” property. */
34 public static final String PROPERTY_NAME = "name";
36 /** The name of the “insert” property. */
37 public static final String PROPERTY_INSERT = "insert";
39 /** The name of the “content type” property. */
40 public static final String PROPERTY_CONTENT_TYPE = "contentType";
42 /** Whether this entry is virtual. */
43 private final boolean virtual;
45 /** The name of the file. */
48 /** The default insert flag for this entry. */
49 private boolean defaultInsert;
51 /** Whether to insert the file. */
52 private boolean insert;
54 /** The default content type of this entry. */
55 private String defaultContentType;
57 /** The content type of the file. */
58 private String contentType;
61 * Creates a new entry.
64 * <code>true</code> if this entry is virtual,
65 * <code>false</code> otherwise
67 protected AbstractEntry(boolean virtual) {
68 this.virtual = virtual;
74 public boolean isVirtual() {
81 public boolean isDefault() {
82 return (insert == defaultInsert) && isDefaultContentType();
88 public boolean isDefaultContentType() {
89 return ((defaultContentType != null) ? defaultContentType.equals(contentType) : (contentType == null));
93 * Sets the default insert flag for this entry. The default insert flag is
94 * derived from {@link File#isHidden()}.
96 * @param defaultInsert
97 * <code>true</code> if the default for this entry is to insert
98 * it, <code>false</code> otherwise
100 void setDefaultInsert(boolean defaultInsert) {
101 this.defaultInsert = defaultInsert;
107 public String getName() {
114 public void setName(String name) {
115 String oldName = this.name;
117 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
123 public boolean isInsert() {
130 public void setInsert(boolean insert) {
131 boolean oldInsert = this.insert;
132 this.insert = insert;
133 fireIfPropertyChanged(PROPERTY_INSERT, oldInsert, insert);
139 public String getContentType() {
146 public void setContentType(String contentType) {
147 String oldContentType = this.contentType;
148 this.contentType = contentType;
149 fireIfPropertyChanged(PROPERTY_CONTENT_TYPE, oldContentType, contentType);
153 * Sets the default content type of the entry. The default content type is
154 * derived from its extension.
156 * @param defaultContentType
157 * The default content type
159 void setDefaultContentType(String defaultContentType) {
160 this.defaultContentType = defaultContentType;
166 public void restoreDefaultContentType() {
167 this.contentType = defaultContentType;