2 * This file is part of "SnipSnap Radeox Rendering Engine".
4 * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
7 * Please visit http://radeox.org/ for updates and contact.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library 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 GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 package org.plog4u.wiki.macro;
27 import java.io.IOException;
28 import java.io.Writer;
31 import org.plog4u.wiki.filter.ICachableMacro;
32 import org.radeox.api.engine.ImageRenderEngine;
33 import org.radeox.api.engine.RenderEngine;
34 import org.radeox.api.engine.context.RenderContext;
35 import org.radeox.macro.BaseLocaleMacro;
36 import org.radeox.macro.parameter.MacroParameter;
37 import org.radeox.util.Encoder;
40 * Macro for displaying external links with a name. The normal UrlFilter
41 * takes the url as a name.
47 public class LinkMacro extends BaseLocaleMacro implements ICachableMacro {
48 public String getLocaleKey() {
52 public void execute(Writer writer, MacroParameter params)
53 throws IllegalArgumentException, IOException {
55 RenderContext context = params.getContext();
56 RenderEngine engine = context.getRenderEngine();
58 String text = params.get("text", 0);
59 String url = params.get("url", 1);
60 String img = params.get("img", 2);
62 // check for single url argument (text == url)
63 if(params.getLength() == 1) {
65 text = Encoder.toEntity(text.charAt(0)) + Encoder.escape(text.substring(1));
68 if (url != null && text != null) {
69 writer.write("<span class=\"nobr\">");
70 if (!"none".equals(img) && engine instanceof ImageRenderEngine) {
71 writer.write(((ImageRenderEngine) engine).getExternalImageLink());
73 writer.write("<a href=\"");
74 writer.write(Encoder.escape(url));
77 writer.write("</a></span>");
79 throw new IllegalArgumentException("link needs a name and a url as argument");