2 * jSite - ClientPutDir.java - Copyright © 2006–2012 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.util.freenet.fcp2;
21 import java.io.IOException;
22 import java.io.Writer;
25 * Abstract base class for all put requests that insert a directory.
28 * The type of the “ClientPutDir” command
29 * @author David Roden <droden@gmail.com>
31 public class ClientPutDir<C extends ClientPutDir<?>> extends ClientPut {
34 * All possible manifest putters. Manifest putters are used to distribute
35 * files of a directory insert to different containers, depending on size,
36 * type, and other factors.
38 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
40 public enum ManifestPutter {
43 * Use the “simple” manifest putter. Despite its name this is currently
44 * the default manifest putter.
48 /** Use the “default” manifest putter. */
51 /** The name of the manifest putter. */
52 private final String name;
55 * Creates a new manifest putter.
58 * The name of the manifest putter
60 private ManifestPutter(String name) {
65 * Returns the name of the manifest putter.
67 * @return The name of the manifest putter
69 public String getName() {
81 public String toString() {
82 return name.substring(0, 1).toUpperCase() + name.substring(1);
87 /** The default file of the directory. */
88 protected String defaultName;
90 /** The manifest putter to use. */
91 private ManifestPutter manifestPutter;
94 * Creates a new request with the specified name, identifier, and URI.
97 * The name of the request
99 * The identifier of the request
101 * The URI of the request
103 public ClientPutDir(String name, String identifier, String uri) {
104 super(name, identifier, uri);
108 * Returns the default name of the directory.
110 * @return The default name of the directory
112 public String getDefaultName() {
117 * Sets the default name of the directory. The default name of a directory
118 * is the name of the file that will be delivered if the directory was
119 * requested without a filename. It's about the same as the
120 * <code>index.html</code> file that gets delivered if you only request a
121 * directory from a webserver.
124 * The default name of the directory
126 public void setDefaultName(String defaultName) {
127 this.defaultName = defaultName;
131 * Returns the current manifest putter.
133 * @return The current manifest putter (may be {@code null})
135 public ManifestPutter getManifestPutter() {
136 return manifestPutter;
140 * Sets the manifest putter for the “ClientPutDir” command. If {@code null}
141 * is given the node will choose a manifest putter.
143 * @param manifestPutter
144 * The manifest putter to use for the command (may be
146 * @return This ClientPutDir command
148 @SuppressWarnings("unchecked")
149 public C setManifestPutter(ManifestPutter manifestPutter) {
150 this.manifestPutter = manifestPutter;
158 protected void write(Writer writer) throws IOException {
160 if (defaultName != null)
161 writer.write("DefaultName=" + defaultName + LINEFEED);
162 if (manifestPutter != null) {
163 writer.write("ManifestPutter=" + manifestPutter.getName() + LINEFEED);