01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2007 JSPWiki Developer Group
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.plugin;
21:
22: import java.util.Map;
23:
24: import com.ecyrd.jspwiki.TextUtil;
25: import com.ecyrd.jspwiki.WikiContext;
26: import com.ecyrd.jspwiki.WikiEngine;
27:
28: /**
29: * Outputs an image with the supplied text as the <tt>title</tt> which is shown as a tooltip by
30: * most browsers. This is intended for short one line comments.
31: * <p>
32: * See http://www.456bereastreet.com/archive/200412/the_alt_and_title_attributes/ for discussion on
33: * alt and title attributes.
34: * <p>
35: * Adaption of the CommentPlugin written by Scott Hulbert, cleaned up and generalized, but basically
36: * his concept.
37: * <p>
38: *
39: * @author John Volkar
40: * @author Scott Hulbert
41: */
42: public class Note implements WikiPlugin {
43: public static final String PROP_NOTE_IMAGE = "notePlugin.imageName";
44: public static final String DEFAULT_NOTE_IMAGE = "note.png";
45:
46: public String execute(WikiContext context, Map params)
47: throws PluginException {
48: String commandline = (String) params
49: .get(PluginManager.PARAM_CMDLINE);
50: if (commandline == null || commandline.length() == 0) {
51: return "Unable to obtain plugin command line from parameter'"
52: + PluginManager.PARAM_CMDLINE + "'"; // I18N
53: }
54:
55: String commentImage = imageUrl(context);
56:
57: String commentText = clean(commandline);
58:
59: return "<img src='" + commentImage + "' alt=\"Comment: "
60: + commentText + "\" title=\"" + commentText + "\"/>";
61: }
62:
63: private String imageUrl(WikiContext ctx) {
64: WikiEngine engine = ctx.getEngine();
65: String commentImage = engine.getWikiProperties().getProperty(
66: PROP_NOTE_IMAGE, DEFAULT_NOTE_IMAGE);
67:
68: commentImage = "images/" + commentImage;
69:
70: String resource = engine.getTemplateManager().findResource(ctx,
71: engine.getTemplateDir(), commentImage);
72:
73: return ctx.getURL(WikiContext.NONE, resource);
74: }
75:
76: /**
77: * Cleans the side.
78: *
79: * @param commandline
80: * @return
81: */
82: private String clean(String commandline) {
83: return TextUtil.replaceEntities(commandline);
84: }
85:
86: }
|