Please note that installation and/or use of this feature on a public wiki is a security risk. This feature should only be used on a private or intranet wiki where the environment is entirely trusted.
This Contributed Plugin allows you to execute JavaScript code on the server. Useful for creating pages with dynamic content. This plugin is experimental at this stage; clearly better wiki integration and server safety issues need to be addressed.
- Groovy Plugin
- Tcl Plugin
The plugin's JavaScript implementation is Mozilla's Rhino
. The public discussion for Mozilla's JavaScript implementations is at netscape.public.mozilla.jseng
.
For more information please contact Andrew Gilmartin at andrewgilmartin at yahoo.com.
Building
To built you will need to add the following libraries to the project's lib directory:
- JSPWiki.jar (version 2.4.24 or better);
- servlet-api.jar from your Tomcat distribution;
- js.jar from Rhino 1.6R2 at http://www.mozilla.org/rhino/download.html
;
- xbean.jar from XMLBeans 2.20 at http://www.apache.org/dyn/closer.cgi/xmlbeans
.
Then run ant.
The code does not yet conform to the JSPWiki Coding Standard.
Installing
Copy the file build/jspwiki-js-plugin.jar, lib/js.jar, and lib/xbean.jar to JSPWiki's WEB-INF/lib directory.
Using
The plugin is called using
[{com.ingenta.jspwiki.plugin.js.JSPlugin scriptPage='wikiPage' scriptResult='text|xml|wiki' }]
[{com.ingenta.jspwiki.plugin.js.JSPlugin script='javascript' scriptResult='text|xml|wiki' }]
[{com.ingenta.jspwiki.plugin.js.JSPlugin scriptResult='text|xml|wiki'
.. javascript body content ..
}]
[{scriptPage scriptResult='text|xml|wiki'
.. data body content ..
}]
For most installations you need only refer to the plugin as JSPlugin as the installation will have added com.ingenta.jspwiki.plugin.js to the jspwiki.plugin.searchPath property.
The script and scriptPage parameter or body content selects the JavaScript code to execute. The scriptResult parameter determines how the script's result is further processed; xml result output is sent as is to the browser; text result output is send to the browser after escaping &, <, >, and " characters; wiki result output is send to the browser after first converting to HTML. The default scriptResult value is wiki.
Using the scriptPage as the name of the plugin only works for JSPWiki implementations using the modified com.ecyrd.jspwiki.plugin.PluginManager supporting the jspwiki.plugin.unknownPlugin property. For more information see ScriptedPlugin
.
During execution the following global variables are available to the script:
| wikiInfo | An instance of class JSWikiInfo |
| wikiPage | An instance of class JSWikiPage for the page containing the plugin |
| pluginArgs | An associative array containing the arguments to the plugin. For example format = pluginArgs[ "scriptResult" ];. |
| pluginBody | The content of the plugin body. This is only set if the body does not contain the script. |
See JSPluginScripts for examples of scripts.
Note that the current interpreter is not a safe one. Thus all event, file, socket, and use of Java classes is enabled.
Class and method detail
class JSWikiPage
| o.name | The name of the page. |
| o.author | The author name of the most recient version. |
| o.created | The creation date of the most recient version. |
| o.modified | The last modified date of the most recient version. |
| o.versionNumber | The version number of the most recient version. |
| o.versions | Returns a list of page's versions. See JSWikiPageVersionInfo |
| o.attachments | Returns a list of the page's attachments. See JSWikiPageAttachmentInfo |
| o.content | Returns the content of the page. |
| o.setContent( pageContent ) | Sets the content of the page (and creates a new version) |
class JSWikiPageVersionInfo
| o.author | The name of the author. |
| o.modified | The last modified date. |
| o.versionNumber | The version number. |
class JSWikePageAttachmentInfo
| method | description |
|---|---|
| o.fileName | The attachment's file name. |
| o.fileSize | The attachment's file size in bytes. |
class JSWikiInfo
| method | description |
|---|---|
| o.pluginVersion | The version number of this plugin. |
| o.pages | Returns a list of the pages. |
| o.hasPage( pageName ) | Returns true if the named page exists. |
| o.getPage( pageName ) | Returns the named page. It is an error if the page does not exist. |
| o.createPage( pageName, pageContent ) | Creates a new page with the given name and content. It is an error if the page already exists. |
| o.deletePage( pageName ) | Deletes the named page. It is an error if the page does not exist. |
Comments
Q: I can't get the JSPlugin compiled yet. Is it possible to post the .jar on this page.
My compiler complains about the call to wikiEngine.saveText(...) in JSWikiPage.java.
-- DF
A: Done. Note that this version works with JSPWIki 2.0.39. -- Andrew Gilmartin
Q: Help of how to use this plugin is not good enough. e.g. where do we neet to use scriptPage and why? in which cases is it suitable to use it and all things should be given properly. -- Kiran thakkar
A: There are a number of examples on the JSPluginScripts page. Perhaps these will answer your questions. Otherwise, please do send me email with some context of how you want to use the plugin and perhaps with all this information I can help. -- Andrew Gilmartin
Attached the source code and compiled jar file for a version od JSPlugin that was fixed to work with the latest versions of JSPWiki, Rhino and XMLBeans.
-- Nascif Abousalh-Neto, 26-Jul-2006
Add new attachment
List of attachments
| Kind | Attachment Name | Size | Version | Date Modified | Author | Change note |
|---|---|---|---|---|---|---|
jsp |
browse.jsp | 66.9 kB | 1 | 04-Feb-2006 07:19 | 148.221.80.109 | |
jar |
jspwiki-js-plugin-26Jul2006.ja... | 13.5 kB | 1 | 26-Jul-2006 22:47 | Nascif Abousalh-Neto | |
zip |
jspwiki-js-plugin-src-26Jul200... | 9.4 kB | 1 | 26-Jul-2006 22:47 | Nascif Abousalh-Neto | |
jar |
jspwiki-js-plugin.jar | 13.2 kB | 1 | 03-Mar-2005 23:46 | 68.9.19.21 | |
gz |
jspwiki-js-plugin.tar.gz | 6.0 kB | 1 | 21-Feb-2005 21:39 | 216.41.98.254 |