Posted on 6. Oktober 2011, 15:36 By malime
Das JSPWiki läßt sich recht einfach auch durch eigene Plugins erweitern. Hierzu ist es ausreichend eine jar zu Erstellen, diese und WEB.INF/lib abzulegen und unter den jspwiki.properties den Suchpath entsprechend zu erweitern. Anschließend kann mittels
[{ContextAndParameterPlugin parameter='true'}]
dass Plugin aufgerufen werden:
[{ContextAndParameterPlugin parameter='true'}]
Hier ist der Code zu dem Plugin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | package de.malime.jspwiki; import java.util.Iterator; import java.util.Map; import com.ecyrd.jspwiki.WikiContext; import com.ecyrd.jspwiki.WikiEngine; import com.ecyrd.jspwiki.WikiPage; import com.ecyrd.jspwiki.plugin.PluginException; import com.ecyrd.jspwiki.plugin.WikiPlugin; public class ContextAndParameterPlugin implements WikiPlugin { @SuppressWarnings("rawtypes") public String execute (WikiContext Context, Map ParameterMap) throws PluginException { String Result = "<h4>ContextAndParamterPlugin - examines the actual \"WikiContext\" and lists the given plugin parameters</h4>\n\n"; Result += "<table width=100%>"; /** * examine the actual wiki engine **/ WikiEngine Engine = Context.getEngine(); Result += " <tr valign=top>\n"; Result += " <td><b>Wiki Engine:</b></td>\n"; Result += " <td>" + Engine.getApplicationName() + " (" + Engine.getPageCount() + " pages, up since " + Engine.getStartTime() + ")</td>\n"; Result += " </tr>\n"; /** * examine the actual wiki page **/ WikiPage Page = Context.getPage(); String Author = Page.getAuthor(); Result += " <tr valign=top>\n"; Result += " <td><b>Wiki Page:</b></td>\n"; Result += " <td>" + Page.getName() + " (version " + Page.getVersion() + ", modified on " + Page.getLastModified() + ( Author == null ? "" : " by " + Author) + ")</td>\n"; Result += " </tr>\n"; /** * finally show the request context **/ Result += " <tr valign=top>\n"; Result += " <td><b>Request Context:</b></td>\n"; Result += " <td>" + Context.getRequestContext() + "</td>\n"; Result += " </tr>\n + </table>\n"; if (ParameterMap == null || ParameterMap.isEmpty()) { return Result; } Result += "<dl>"; for (Iterator ParameterInterator = ParameterMap.entrySet().iterator(); ParameterInterator.hasNext(); ) { Map.Entry Entry = (Map.Entry)ParameterInterator.next(); Object Key = Entry.getKey(); Result += "<dt>" + Key + (Key != null ? " (" + Key.getClass().getName() + ")" : "") + "\n"; Object Value = Entry.getValue(); if (Value == null) { Result += "<dd>(null)"; } else { if (Value instanceof String) { Result += "<dd>\"" + Value + "\""; } else { Result += "<dd>(" + Value.getClass().getName() + ") " + Value + "\n"; } } } return Result + "</dl>"; }; } |
No comments yet Categories: malime Schlagwörter: JSPWiki