add PersistentPutDir
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 13:33:12 +0000 (13:33 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 13:33:12 +0000 (13:33 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@725 c3eda9e8-030b-0410-8277-bc7414b0a119

TODO
src/net/pterodactylus/util/fcp/FcpAdapter.java
src/net/pterodactylus/util/fcp/FcpConnection.java
src/net/pterodactylus/util/fcp/FcpListener.java
src/net/pterodactylus/util/fcp/PersistentPutDir.java [new file with mode: 0644]

diff --git a/TODO b/TODO
index 8965128..7c5fc9e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -6,7 +6,6 @@ GetPluginInfo (since 1075)
 GetRequestStatus
 ModifyConfig (since 1027)
 ModifyPersistentRequest
-PersistentPutDir
 PersistentRequestModified (since 1016)
 PersistentRequestRemoved (since 1016)
 PluginInfo (since 1075)
index 59cfae5..e7afce4 100644 (file)
@@ -200,6 +200,13 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir) {
+               /* empty. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
                /* empty. */
        }
index e3ddf7c..fa3673d 100644 (file)
@@ -488,6 +488,18 @@ public class FcpConnection {
        }
 
        /**
+        * Notifies all listeners that an “PersistentPutDir” message was received.
+        * 
+        * @param persistentPutDir
+        *            The “PersistentPutDir” message
+        */
+       private void fireReceivedPersistentPutDir(PersistentPutDir persistentPutDir) {
+               for (FcpListener fcpListener: fcpListeners) {
+                       fcpListener.receivedPersistentPutDir(this, persistentPutDir);
+               }
+       }
+
+       /**
         * Notifies all listeners that a “ProtocolError” message was received.
         * 
         * @param protocolError
@@ -582,6 +594,8 @@ public class FcpConnection {
                        fireReceivedPersistentGet(new PersistentGet(fcpMessage));
                } else if ("PersistentPut".equals(messageName)) {
                        fireReceivedPersistentPut(new PersistentPut(fcpMessage));
+               } else if ("PersistentPutDir".equals(messageName)) {
+                       fireReceivedPersistentPutDir(new PersistentPutDir(fcpMessage));
                } else if ("URIGenerated".equals(messageName)) {
                        fireReceivedURIGenerated(new URIGenerated(fcpMessage));
                } else if ("EndListPersistentRequests".equals(messageName)) {
index e07bc6d..b4b1094 100644 (file)
@@ -291,6 +291,16 @@ public interface FcpListener extends EventListener {
        public void receivedIdentifierCollision(FcpConnection fcpConnection, IdentifierCollision identifierCollision);
 
        /**
+        * Notifies a listener that a “PersistentPutDir” message was received.
+        * 
+        * @param fcpConnection
+        *            The connection that received the message
+        * @param persistentPutDir
+        *            The “PersistentPutDir” message
+        */
+       public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir);
+
+       /**
         * Notifies a listener that a “ProtocolError” was received.
         * 
         * @param fcpConnection
diff --git a/src/net/pterodactylus/util/fcp/PersistentPutDir.java b/src/net/pterodactylus/util/fcp/PersistentPutDir.java
new file mode 100644 (file)
index 0000000..412bd3d
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * jSite2 - PersistentPutDir.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.util.fcp;
+
+/**
+ * A “PersistentPutDir” is the response to a {@link ClientPutDir} message. It is
+ * also sent as a possible response to a {@link ListPersistentRequests} message.
+ * 
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class PersistentPutDir extends BaseMessage {
+
+       /**
+        * Creates a new “PersistentPutDir” message that wraps the received message.
+        * 
+        * @param receivedMessage
+        *            The received message
+        */
+       PersistentPutDir(FcpMessage receivedMessage) {
+               super(receivedMessage);
+       }
+
+       /**
+        * Returns the identifier of the request.
+        * 
+        * @return The identifier of the request
+        */
+       public String getIdentifier() {
+               return getField("Identifier");
+       }
+
+       /**
+        * Returns the URI of the request.
+        * 
+        * @return The URI of the request
+        */
+       public String getURI() {
+               return getField("URI");
+       }
+
+       /**
+        * Returns the verbosity of the request.
+        * 
+        * @return The verbosity of the request
+        */
+       public Verbosity getVerbosity() {
+               return Verbosity.valueOf(getField("Verbosity"));
+       }
+
+       /**
+        * Returns the priority of the request.
+        * 
+        * @return The priority of the request
+        */
+       public Priority getPriority() {
+               return Priority.valueOf(getField("PriorityClass"));
+       }
+
+       /**
+        * Returns whether the request is on the global queue.
+        * 
+        * @return <code>true</code> if the request is on the global queue,
+        *         <code>false</code> if it is on the client-local queue
+        */
+       public boolean isGlobal() {
+               return Boolean.valueOf(getField("Global"));
+       }
+
+       /**
+        * Returns the maximum number of retries for failed blocks.
+        * 
+        * @return The maximum number of retries, or <code>-1</code> for endless
+        *         retries, or <code>-2</code> if the number could not be parsed
+        */
+       public int getMaxRetries() {
+               return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
+       }
+
+       /**
+        * Returns the number of files in the request.
+        * 
+        * @return The number of files in the request
+        */
+       public int getFileCount() {
+               int fileCount = -1;
+               while (getField("Files." + ++fileCount + ".UploadFrom") != null) { /*
+                                                                                                                                                        * do
+                                                                                                                                                        * nothing.
+                                                                                                                                                        */
+               }
+               return fileCount;
+       }
+
+       /**
+        * Returns the name of the file at the given index. The index is counted
+        * from <code>0</code>.
+        * 
+        * @param fileIndex
+        *            The index of the file
+        * @return The name of the file at the given index
+        */
+       public String getFileName(int fileIndex) {
+               return getField("Files." + fileIndex + ".Name");
+       }
+
+       /**
+        * Returns the length of the file at the given index. The index is counted
+        * from <code>0</code>.
+        * 
+        * @param fileIndex
+        *            The index of the file
+        * @return The length of the file at the given index
+        */
+       public long getFileDataLength(int fileIndex) {
+               return FcpUtils.safeParseLong(getField("Files." + fileIndex + ".DataLength"));
+       }
+
+       /**
+        * Returns the upload source of the file at the given index. The index is
+        * counted from <code>0</code>.
+        * 
+        * @param fileIndex
+        *            The index of the file
+        * @return The upload source of the file at the given index
+        */
+       public UploadFrom getFileUploadFrom(int fileIndex) {
+               return UploadFrom.valueOf(getField("Files." + fileIndex + ".UploadFrom"));
+       }
+
+       /**
+        * Returns the content type of the file at the given index. The index is
+        * counted from <code>0</code>.
+        * 
+        * @param fileIndex
+        *            The index of the file
+        * @return The content type of the file at the given index
+        */
+       public String getFileMetadataContentType(int fileIndex) {
+               return getField("Files." + fileIndex + ".Metadata.ContentType");
+       }
+
+       /**
+        * Returns the filename of the file at the given index. This value is only
+        * returned if {@link #getFileUploadFrom(int)} is returning
+        * {@link UploadFrom#disk}. The index is counted from <code>0</code>.
+        * 
+        * @param fileIndex
+        *            The index of the file
+        * @return The filename of the file at the given index
+        */
+       public String getFileFilename(int fileIndex) {
+               return getField("Files." + fileIndex + ".Filename");
+       }
+
+}