2 * This file is part of "SnipSnap Radeox Rendering Engine".
4 * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel All Rights Reserved.
6 * Please visit http://radeox.org/ for updates and contact.
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
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.
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--
18 package org.plog4u.wiki.macro;
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;
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;
35 * MacroListMacro displays a list of all known macros of the EngineManager with their name, parameters and a description.
37 * @author Matthias L. Jugel
41 public class MacroListMacro extends BaseLocaleMacro implements IRenderResultMacro, ICachableMacro {
42 public String getLocaleKey() {
43 return "macro.macrolist";
46 public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException {
47 if (params.getLength() == 0) {
50 throw new IllegalArgumentException("MacroListMacro: number of arguments does not match");
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());
64 writer.write(macro.getDescription());
66 String[] params = macro.getParamDescription();
67 if (params.length == 0) {
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)");
76 writer.write(params[i]);
83 writer.write("{table}");