01: // /xml/config_p.java
02: // -------------------------------
03: // (C) 2006 Alexander Schier
04: // part of YaCy
05: //
06: // last major change: 06.02.2006
07: // this file is contributed by Alexander Schier
08: //
09: // This program is free software; you can redistribute it and/or modify
10: // it under the terms of the GNU General Public License as published by
11: // the Free Software Foundation; either version 2 of the License, or
12: // (at your option) any later version.
13: //
14: // This program is distributed in the hope that it will be useful,
15: // but WITHOUT ANY WARRANTY; without even the implied warranty of
16: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: // GNU General Public License for more details.
18: //
19: // You should have received a copy of the GNU General Public License
20: // along with this program; if not, write to the Free Software
21: // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US
22:
23: package xml;
24:
25: import java.util.ArrayList;
26: import java.util.Collections;
27: import java.util.Iterator;
28: import java.util.List;
29:
30: import de.anomic.http.httpHeader;
31: import de.anomic.server.serverObjects;
32: import de.anomic.server.serverSwitch;
33:
34: public class config_p {
35:
36: public static serverObjects respond(httpHeader header,
37: serverObjects post, serverSwitch env) {
38: // return variable that accumulates replacements
39: //plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
40: serverObjects prop = new serverObjects();
41: String key;
42:
43: //change a Key
44: if (post != null && post.containsKey("key")
45: && post.containsKey("value")) {
46: key = (String) post.get("key");
47: final String value = (String) post.get("value");
48: if (!key.equals("")) {
49: env.setConfig(key, value);
50: }
51: }
52:
53: Iterator<String> keys = env.configKeys();
54:
55: List<String> list = new ArrayList<String>(250);
56: while (keys.hasNext()) {
57: list.add(keys.next());
58: }
59: Collections.sort(list);
60: keys = list.iterator();
61:
62: int count = 0;
63: while (keys.hasNext()) {
64: key = (String) keys.next();
65: prop.putHTML("options_" + count + "_key", key);
66: prop.putHTML("options_" + count + "_value", env.getConfig(
67: key, "ERROR"));
68: count++;
69: }
70: prop.put("options", count);
71:
72: // return rewrite properties
73: return prop;
74: }
75:
76: }
|