add GetConfig and ConfigData
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 10:06:54 +0000 (10:06 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 10:06:54 +0000 (10:06 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@717 c3eda9e8-030b-0410-8277-bc7414b0a119

TODO
src/net/pterodactylus/util/fcp/ConfigData.java [new file with mode: 0644]
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/GetConfig.java [new file with mode: 0644]

diff --git a/TODO b/TODO
index 8863f31..db7dee8 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,9 +1,7 @@
 ClientPutComplexDir
 ClientPutDiskDir
-ConfigData (since 1027)
 FCPPluginMessage (since 1075)
 FCPPluginReply (since 1075)
-GetConfig (since 1027)
 GetFailed
 GetPluginInfo (since 1075)
 GetRequestStatus
diff --git a/src/net/pterodactylus/util/fcp/ConfigData.java b/src/net/pterodactylus/util/fcp/ConfigData.java
new file mode 100644 (file)
index 0000000..aa8ea6f
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * jSite2 - ConfigData.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 “ConfigData” message contains various aspects of the node’s configuration.
+ * 
+ * @see GetConfig
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class ConfigData extends BaseMessage {
+
+       /**
+        * Creates a new “ConfigData” message that wraps the received message.
+        * 
+        * @param receivedMessage
+        *            The received message
+        */
+       ConfigData(FcpMessage receivedMessage) {
+               super(receivedMessage);
+       }
+
+       /**
+        * Returns the current value of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The current value of the option
+        */
+       public String getCurrent(String option) {
+               return getField("current." + option);
+       }
+
+       /**
+        * Returns the short description of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The short description of the option
+        */
+       public String getShortDescription(String option) {
+               return getField("shortDescription." + option);
+       }
+
+       /**
+        * Returns the long description of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The long description of the option
+        */
+       public String getLongDescription(String option) {
+               return getField("longDescription." + option);
+       }
+
+       /**
+        * Returns the data type of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The data type of the option
+        */
+       public String getDataType(String option) {
+               return getField("dataType." + option);
+       }
+
+       /**
+        * Returns the default value of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The default value of the option
+        */
+       public String getDefault(String option) {
+               return getField("default." + option);
+       }
+
+       /**
+        * Returns the sort order of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The sort order of the option, or <code>-1</code> if the sort
+        *         order could not be parsed
+        */
+       public int getSortOrder(String option) {
+               return FcpUtils.safeParseInt(getField("sortOrder." + option));
+       }
+
+       /**
+        * Returns the expert flag of the given option.
+        * 
+        * @param option
+        *            The name of the option
+        * @return The expert flag of the option
+        */
+       public boolean getExpertFlag(String option) {
+               return Boolean.valueOf(getField("expertFlag." + option));
+       }
+
+       /**
+        * Returns the force-write flag of the given option
+        * 
+        * @param option
+        *            The name of the option
+        * @return The force-write flag of the given option
+        */
+       public boolean getForceWriteFlag(String option) {
+               return Boolean.valueOf(getField("forceWriteFlag." + option));
+       }
+
+}
index 37fd77f..0402045 100644 (file)
@@ -177,6 +177,13 @@ public class FcpAdapter implements FcpListener {
        }
 
        /**
+        * @see FcpListener#receivedConfigData(FcpConnection, ConfigData)
+        */
+       public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData) {
+               /* empty. */
+       }
+
+       /**
         * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError)
         */
        public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
index cc48dfb..a57a823 100644 (file)
@@ -439,6 +439,18 @@ public class FcpConnection {
        }
 
        /**
+        * Notifies all listeners that a “ConfigData” message was received.
+        * 
+        * @param configData
+        *            The “ConfigData” message
+        */
+       private void fireReceivedConfigData(ConfigData configData) {
+               for (FcpListener fcpListener: fcpListeners) {
+                       fcpListener.receivedConfigData(this, configData);
+               }
+       }
+
+       /**
         * Notifies all listeners that a “ProtocolError” message was received.
         * 
         * @param protocolError
@@ -580,6 +592,8 @@ public class FcpConnection {
                        fireReceivedTestDDAReply(new TestDDAReply(fcpMessage));
                } else if ("TestDDAComplete".equals(messageName)) {
                        fireReceivedTestDDAComplete(new TestDDAComplete(fcpMessage));
+               } else if ("ConfigData".equals(messageName)) {
+                       fireReceivedConfigData(new ConfigData(fcpMessage));
                } else if ("NodeHello".equals(messageName)) {
                        fireReceivedNodeHello(new NodeHello(fcpMessage));
                } else if ("CloseConnectionDuplicateClientName".equals(messageName)) {
index 9b75bdb..ad1205d 100644 (file)
@@ -251,6 +251,16 @@ public interface FcpListener extends EventListener {
        public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection, UnknownNodeIdentifier unknownNodeIdentifier);
 
        /**
+        * Notifies a listener that a “ConfigData” message was received.
+        * 
+        * @param fcpConnection
+        *            The connection that received the message
+        * @param configData
+        *            The “ConfigData” message
+        */
+       public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData);
+
+       /**
         * Notifies a listener that a “ProtocolError” was received.
         * 
         * @param fcpConnection
diff --git a/src/net/pterodactylus/util/fcp/GetConfig.java b/src/net/pterodactylus/util/fcp/GetConfig.java
new file mode 100644 (file)
index 0000000..53c8555
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * jSite2 - GetConfig.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;
+
+/**
+ * The “GetConfig” command tells the node to send its configuration to the
+ * client.
+ * 
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class GetConfig extends FcpMessage {
+
+       /**
+        * Creates a new “GetConfig” command.
+        */
+       public GetConfig() {
+               super("GetConfig");
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the
+        * current values.
+        * 
+        * @param withCurrent
+        *            <code>true</code> to include current values in the result,
+        *            <code>false</code> otherwise
+        */
+       public void setWithCurrent(boolean withCurrent) {
+               setField("WithCurrent", String.valueOf(withCurrent));
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the
+        * short descriptions.
+        * 
+        * @param withShortDescription
+        *            <code>true</code> to include the short descriptions in the
+        *            result, <code>false</code> otherwise
+        */
+       public void setWithShortDescription(boolean withShortDescription) {
+               setField("WithShortDescription", String.valueOf(withShortDescription));
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the long
+        * descriptions.
+        * 
+        * @param withLongDescription
+        *            <code>true</code> to include the long descriptions in the
+        *            result, <code>false</code> otherwise
+        */
+       public void setWithLongDescription(boolean withLongDescription) {
+               setField("WithLongDescription", String.valueOf(withLongDescription));
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the data
+        * types.
+        * 
+        * @param withDataTypes
+        *            <code>true</code> to include the data types in the result,
+        *            <code>false</code> otherwise
+        */
+       public void setWithDataTypes(boolean withDataTypes) {
+               setField("WithDataTypes", String.valueOf(withDataTypes));
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the
+        * defaults.
+        * 
+        * @param setWithDefaults
+        *            <code>true</code> to include the defaults in the result,
+        *            <code>false</code> otherwise
+        */
+       public void setWithDefaults(boolean setWithDefaults) {
+               setField("WithDefaults", String.valueOf(setWithDefaults));
+       }
+
+       /**
+        * Sets whether the {@ConfigData} result message shall include the sort
+        * order.
+        * 
+        * @param withSortOrder
+        *            <code>true</code> to include the sort order in the result,
+        *            <code>false</code> otherwise
+        */
+       public void setWithSortOrder(boolean withSortOrder) {
+               setField("WithSortOrder", String.valueOf(withSortOrder));
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the
+        * expert flag.
+        * 
+        * @param withExpertFlag
+        *            <code>true</code> to include the expert flag in the result,
+        *            <code>false</code> otherwise
+        */
+       public void setWithExpertFlag(boolean withExpertFlag) {
+               setField("WithExpertFlag", String.valueOf(withExpertFlag));
+       }
+
+       /**
+        * Sets whether the {@link ConfigData} result message shall include the
+        * force-write flag.
+        * 
+        * @param withForceWriteFlag
+        *            <code>true</code> to include the force-write flag in the
+        *            result, <code>false</code> otherwise
+        */
+       public void setWithForceWriteFlag(boolean withForceWriteFlag) {
+               setField("WithForceWriteFlag", String.valueOf(withForceWriteFlag));
+       }
+
+}