Fix copyright line.
[jFCPlib.git] / src / net / pterodactylus / fcp / FCPPluginReply.java
index 84faa54..c3b5281 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * jSite2 - FCPPluginReply.java -
- * Copyright © 2008 David Roden
+ * jFCPlib - FCPPluginReply.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
 package net.pterodactylus.fcp;
 
 import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * The “FCPPluginReply” is sent by a plugin as a response to a
  * {@link FCPPluginMessage} message.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class FCPPluginReply extends BaseMessage {
@@ -34,7 +36,7 @@ public class FCPPluginReply extends BaseMessage {
 
        /**
         * Creates a new “FCPPluginReply” message that wraps the received message.
-        * 
+        *
         * @param receivedMessage
         *            The received message
         * @param payloadInputStream
@@ -47,7 +49,7 @@ public class FCPPluginReply extends BaseMessage {
 
        /**
         * Returns the name of the plugin.
-        * 
+        *
         * @return The name of the plugin
         */
        public String getPluginName() {
@@ -56,7 +58,7 @@ public class FCPPluginReply extends BaseMessage {
 
        /**
         * Returns the identifier of the request.
-        * 
+        *
         * @return The identifier of the request
         */
        public String getIdentifier() {
@@ -65,7 +67,7 @@ public class FCPPluginReply extends BaseMessage {
 
        /**
         * Returns the length of the optional payload.
-        * 
+        *
         * @return The length of the payload, or <code>-1</code> if there is no
         *         payload or the length could not be parsed
         */
@@ -75,7 +77,7 @@ public class FCPPluginReply extends BaseMessage {
 
        /**
         * Returns a reply from the plugin.
-        * 
+        *
         * @param key
         *            The name of the reply
         * @return The value of the reply
@@ -85,8 +87,26 @@ public class FCPPluginReply extends BaseMessage {
        }
 
        /**
+        * Returns all replies from the plugin. The plugin sends replies as normal
+        * message fields prefixed by “Replies.”. The keys of the returned map do
+        * not contain this prefix!
+        *
+        * @return All replies from the plugin
+        */
+       public Map<String, String> getReplies() {
+               Map<String, String> fields = getFields();
+               Map<String, String> replies = new HashMap<String, String>();
+               for (Entry<String, String> field : fields.entrySet()) {
+                       if (field.getKey().startsWith("Replies.")) {
+                               replies.put(field.getKey().substring(8), field.getValue());
+                       }
+               }
+               return replies;
+       }
+
+       /**
         * Returns the optional payload.
-        * 
+        *
         * @return The payload of the reply, or <code>null</code> if there is no
         *         payload
         */