KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > render > macro > FieldMacro


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25
26 package org.snipsnap.render.macro;
27
28 import org.snipsnap.render.macro.parameter.SnipMacroParameter;
29 import org.snipsnap.snip.SnipLink;
30 import org.radeox.util.i18n.ResourceManager;
31
32 import java.io.IOException JavaDoc;
33 import java.io.Writer JavaDoc;
34 import java.util.ResourceBundle JavaDoc;
35
36 /*
37  * Macro that creates (HTML) input fields with forms.
38  *
39  * @author stephan
40  * @team sonicteam
41  * @version $Id: FieldMacro.java 1606 2004-05-17 10:56:18Z leo $
42  */

43
44 public class FieldMacro extends SnipMacro {
45   public String JavaDoc getName() {
46     return "field";
47   }
48
49   public String JavaDoc getDescription() {
50     return ResourceManager.getString("i18n.messages", "macro.field.description");
51   }
52
53   public String JavaDoc[] getParamDescription() {
54     return ResourceManager.getString("i18n.messages", "macro.field.params").split(";");
55   }
56
57   /**
58    * {field:id|value|target|button}
59    */

60   public void execute(Writer JavaDoc writer, SnipMacroParameter params)
61       throws IllegalArgumentException JavaDoc, IOException JavaDoc {
62
63     if (params.getLength() > 0) {
64       writer.write("<form class=\"form\" action=\"");
65       if (params.getLength() >= 3) {
66         SnipLink.appendUrl(writer, params.get("2"));
67       } else {
68         SnipLink.appendUrl(writer, params.getSnipRenderContext().getSnip().getName());
69       }
70       writer.write("\" method=\"get\">");
71       writer.write("<input size=\"18\" name=\"");
72       writer.write(params.get("0"));
73       writer.write("\"");
74       if (params.getLength() >= 2) {
75         writer.write(" value=\"");
76         writer.write(params.get("1"));
77         writer.write("\"");
78       }
79       writer.write("/>");
80       if (params.getLength() >= 4) {
81         writer.write(" <input type=\"submit\" name=\"submit\" value=\"");
82         writer.write(params.get("3"));
83         writer.write("\"/>");
84       }
85       writer.write("</form>");
86       return;
87     } else {
88       throw new IllegalArgumentException JavaDoc("Number of arguments does not match");
89     }
90   }
91 }
Popular Tags