misc
[phpeclipse.git] / archive / org.plog4u.wiki / src / org / plog4u / wiki / macro / MacroListMacro.java
1 /*
2  * This file is part of "SnipSnap Radeox Rendering Engine".
3  * 
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel All Rights Reserved.
5  * 
6  * Please visit http://radeox.org/ for updates and contact.
7  * 
8  * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
9  * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any
10  * later version.
11  * 
12  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE--
17  */
18 package org.plog4u.wiki.macro;
19
20 import java.io.IOException;
21 import java.io.Writer;
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.List;
25
26
27 import org.plog4u.wiki.filter.ICachableMacro;
28 import org.plog4u.wiki.filter.IRenderResultMacro;
29 import org.radeox.macro.BaseLocaleMacro;
30 import org.radeox.macro.Macro;
31 import org.radeox.macro.MacroRepository;
32 import org.radeox.macro.parameter.MacroParameter;
33
34 /*
35  * MacroListMacro displays a list of all known macros of the EngineManager with their name, parameters and a description.
36  * 
37  * @author Matthias L. Jugel
38  * 
39  */
40
41 public class MacroListMacro extends BaseLocaleMacro implements IRenderResultMacro, ICachableMacro {
42   public String getLocaleKey() {
43     return "macro.macrolist";
44   }
45
46   public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException {
47     if (params.getLength() == 0) {
48       appendTo(writer);
49     } else {
50       throw new IllegalArgumentException("MacroListMacro: number of arguments does not match");
51     }
52   }
53
54   public Writer appendTo(Writer writer) throws IOException {
55     List macroList = MacroRepository.getInstance().getPlugins();
56     Collections.sort(macroList);
57     Iterator iterator = macroList.iterator();
58     writer.write("{table}\n");
59     writer.write("Macro|Description|Parameters\n");
60     while (iterator.hasNext()) {
61       Macro macro = (Macro) iterator.next();
62       writer.write(macro.getName());
63       writer.write("|");
64       writer.write(macro.getDescription());
65       writer.write("|");
66       String[] params = macro.getParamDescription();
67       if (params.length == 0) {
68         writer.write("none");
69       } else {
70         for (int i = 0; i < params.length; i++) {
71           String description = params[i];
72           if (description.startsWith("?")) {
73             writer.write(description.substring(1));
74             writer.write(" (optional)");
75           } else {
76             writer.write(params[i]);
77           }
78           writer.write("\\\\");
79         }
80       }
81       writer.write("\n");
82     }
83     writer.write("{table}");
84     return writer;
85   }
86
87 }