01: /*
02: * This file is part of "SnipSnap Radeox Rendering Engine".
03: *
04: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
05: * All Rights Reserved.
06: *
07: * Please visit http://radeox.org/ for updates and contact.
08: *
09: * --LICENSE NOTICE--
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: * --LICENSE NOTICE--
22: */
23: package org.radeox.macro;
24:
25: import java.io.IOException;
26: import java.io.Writer;
27: import java.util.Collections;
28: import java.util.Iterator;
29: import java.util.List;
30:
31: import org.radeox.Messages;
32: import org.radeox.api.macro.Macro;
33: import org.radeox.api.macro.MacroParameter;
34:
35: /*
36: * MacroListMacro displays a list of all known macros of the EngineManager with
37: * their name, parameters and a description. @author Matthias L. Jugel
38: *
39: * @version $Id: MacroListMacro.java 7707 2006-04-12 17:30:19Z
40: * ian@caret.cam.ac.uk $
41: */
42:
43: public class MacroListMacro extends BaseLocaleMacro {
44: public String getLocaleKey() {
45: return Messages.getString("MacroListMacro.0"); //$NON-NLS-1$
46: }
47:
48: public void execute(Writer writer, MacroParameter params)
49: throws IllegalArgumentException, IOException {
50: if (params.getLength() == 0) {
51: appendTo(writer);
52: } else {
53: throw new IllegalArgumentException(
54: "MacroListMacro: number of arguments does not match"); //$NON-NLS-1$
55: }
56: }
57:
58: public Writer appendTo(Writer writer) throws IOException {
59: List macroList = MacroRepository.getInstance().getPlugins();
60: Collections.sort(macroList);
61: Iterator iterator = macroList.iterator();
62: writer.write(Messages.getString("MacroListMacro.2")); //$NON-NLS-1$
63: writer.write("Macro|Description|Parameters\n"); //$NON-NLS-1$
64: while (iterator.hasNext()) {
65: Macro macro = (Macro) iterator.next();
66: writer.write(macro.getName());
67: writer.write(Messages.getString("MacroListMacro.4")); //$NON-NLS-1$
68: writer.write(macro.getDescription());
69: writer.write(Messages.getString("MacroListMacro.5")); //$NON-NLS-1$
70: String[] params = macro.getParamDescription();
71: if (params.length == 0) {
72: writer.write("none"); //$NON-NLS-1$
73: } else {
74: for (int i = 0; i < params.length; i++) {
75: String description = params[i];
76: if (description.startsWith(Messages
77: .getString("MacroListMacro.7"))) //$NON-NLS-1$
78: {
79: writer.write(description.substring(1));
80: writer.write(" (optional)"); //$NON-NLS-1$
81: } else {
82: writer.write(params[i]);
83: }
84: writer
85: .write(Messages
86: .getString("MacroListMacro.9")); //$NON-NLS-1$
87: }
88: }
89: writer.write(Messages.getString("MacroListMacro.10")); //$NON-NLS-1$
90: }
91: writer.write(Messages.getString("MacroListMacro.11")); //$NON-NLS-1$
92: return writer;
93: }
94:
95: }
|