2 * jSite - FcpPluginMessage.java - Copyright © 2012–2019 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.InputStream;
23 import java.io.Writer;
24 import java.util.HashMap;
26 import java.util.Map.Entry;
29 * Implementation of the <code>FCPPluginMessage</code> command.
31 * TODO: Implement passing of data as an {@link InputStream}.
33 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
35 public class FcpPluginMessage extends Command {
37 /** The name of the plugin to talk to. */
38 private String pluginName;
40 /** The parameters to send to the plugin. */
41 private final Map<String, String> parameters = new HashMap<String, String>();
44 * Creates a new FCPPluginMessage command.
47 * The identifier of the command
49 public FcpPluginMessage(String identifier) {
50 super("FCPPluginMessage", identifier);
58 * Sets the name of the plugin to talk to.
61 * The name of the plugin to talk to
62 * @return This command
64 public FcpPluginMessage setPluginName(String pluginName) {
65 this.pluginName = pluginName;
70 * Sets a parameter to send to the plugin.
73 * The name of the parameter
75 * The value of the parameter
76 * @return This command
78 public FcpPluginMessage setParameter(String name, String value) {
79 parameters.put(name, value);
91 protected void write(Writer writer) throws IOException {
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));