📄 Update year in copyright line
[jSite.git] / src / main / java / de / todesbaum / util / freenet / fcp2 / FcpPluginMessage.java
1 /*
2  * jSite - FcpPluginMessage.java - Copyright Â© 2012–2019 David Roden
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package de.todesbaum.util.freenet.fcp2;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.Writer;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Map.Entry;
27
28 /**
29  * Implementation of the <code>FCPPluginMessage</code> command.
30  * <p>
31  * TODO: Implement passing of data as an {@link InputStream}.
32  *
33  * @author David â€˜Bombe’ Roden &lt;bombe@freenetproject.org&gt;
34  */
35 public class FcpPluginMessage extends Command {
36
37         /** The name of the plugin to talk to. */
38         private String pluginName;
39
40         /** The parameters to send to the plugin. */
41         private final Map<String, String> parameters = new HashMap<String, String>();
42
43         /**
44          * Creates a new FCPPluginMessage command.
45          *
46          * @param identifier
47          *            The identifier of the command
48          */
49         public FcpPluginMessage(String identifier) {
50                 super("FCPPluginMessage", identifier);
51         }
52
53         //
54         // ACCESSORS
55         //
56
57         /**
58          * Sets the name of the plugin to talk to.
59          *
60          * @param pluginName
61          *            The name of the plugin to talk to
62          * @return This command
63          */
64         public FcpPluginMessage setPluginName(String pluginName) {
65                 this.pluginName = pluginName;
66                 return this;
67         }
68
69         /**
70          * Sets a parameter to send to the plugin.
71          *
72          * @param name
73          *            The name of the parameter
74          * @param value
75          *            The value of the parameter
76          * @return This command
77          */
78         public FcpPluginMessage setParameter(String name, String value) {
79                 parameters.put(name, value);
80                 return this;
81         }
82
83         //
84         // COMMAND METHODS
85         //
86
87         /**
88          * {@inheritDoc}
89          */
90         @Override
91         protected void write(Writer writer) throws IOException {
92                 super.write(writer);
93                 writer.write("PluginName=" + pluginName + LINEFEED);
94                 for (Entry<String, String> parameter : parameters.entrySet()) {
95                         writer.write(String.format("Param.%s=%s%s", parameter.getKey(), parameter.getValue(), LINEFEED));
96                 }
97         }
98
99 }