Scripting library — This page is a collection of community-submitted scripts.
Documentation
Help available in the notation guide.
Common parameters
output - Determines how the output is formated:
html - Data is output as a HTML table (default).
wiki - Data is output as a Confluence wiki table. Use this option if you want data within the table to be formated by the Confluence wiki renderer.
script - Location of source code. Default is the macro body only. If a location of data is specified, the included data will follow the body data.
#filename - Data is read from the file located in confluence home directory/script/filename. Subdirectories can be specified.
global page template name - Data is read from a global page template.
space:page template name - Data is read from a space template.
^attachment - Data is read from an attachment to the current page.
page^attachment - Data is read from an attachment to the page name provided.
space:page^attachment - Data is read from an attachment to the page name provided in the space indicated.
errorMessage - If specified, error information for running the script will be suppressed and only this error message will be displayed in an error box. Use this parameter to provide a more user friendly display.
showErrorOutput - Default is false, error output from the script will be discarded. Set to true to have error output from the script displayed as unformated text. Error output is generated with something like err.print("xxxxx").
showCode - Default is false if the script was successfully run and true if the script had an error. Set to true to always show a panel with the script code and false to never show the script code. Formerly was the showJava parameter which is still valid for source compatibility.
Pre-defined variables
out - stdout. It is a java.io.PrintWriter. Use to output macro result.
err - stderr. It is a java.io.PrintWriter. It can be used to debug script running variable.
context - PageContext. Current confluence's PageContext.
request - http servlet request.
session - http servlet session.
contextPath - string representing the context path.
confluenceHome - string representing path to confluence home directory.
Macro parameters
All macro parameters are passed to the intepreters as Strings variable for use in the script. These should not overlap with pre-defined variables.
Thanks for producing this plugin, I find it very useful. If I could add a coupl...
Thanks for producing this plugin, I find it very useful.
If I could add a couple of feature requests:
1. Add the most common confluence manager objects, such as PageManager and SpaceManager etc as default scripting objects. This would save a line of nasty code in just about every script I write looking up these objects.
2. Cache the compiled version of groovy scripts, based on the hash of the script string
3. Add an admin console to run ad hoc scripts through the admin interface. This would just be a screen with a text box and a go button, with the output of the script printed below. Combined with #1 this would be extremely useful.
You should take a look at Scriptix it does the first already (and allows many mo...
You should take a look at Scriptix – it does the first already (and allows many more scripting objects), it could compile scripts to byte code quite easily, and the admin console will soon have a "run" button to run scripts as well as hopefully a "console" for interactivity.
It can be done from scripts. I've only done it from scriptix, via JavaScript, bu...
It can be done from scripts. I've only done it from scriptix, via JavaScript, but here's the general idea.
First, you have to realize there are (at least) two sorts of metadata to deal with. One is managed by the metadata plugin. This is unversioned, and managed by the contentPropertyManager component. Scriptix provides a getComponent method to obtain references to Confluence components; otherwise you'll have to figure out how to get it yourself. There's nothing to list the available properties, but the metadata macro maintains a list of keys in a key named metadatakeys, with a format like:
The actual keys passed to the property manager would be named "metadata.size", "metadata.iterationid", etc. The property manager also manages things like page excerpts, the flags whether you are showing page children, editing locations and labels, etc. etc.. The best way to see it in action is to look at the os_propertyentry table in the database.
The other is the metadata maintained by he scaffold macro. This is versioned! The scaffolding code maintains its metadata in XML data that it stores in metadata with a key named ~metadata.<pageversion> -- well, actually getting all the versioning right would be a bit more complicated than that -- you definitely do not want to try to maintain this yourself.
Here's my code to obtain the the MetadataManager instance. You must have the Scaffolding plugin installed; this particular code also depends on scriptix:
function getMetadataManager() {
// This illustrates where the data actually lives.
// var propmgr = scriptix.getComponent("contentPropertyManager");
// var xml = propmgr.getTextProperty(macro.entity, "~metadata.45");
// This is the real code:
var pluginMgr = scriptix.getComponent("pluginAccessor");
var scaffold = pluginMgr.getPlugin("net.customware.confluence.plugin.scaffolding");
var mdClassName = "org.randombits.confluence.metadata.MetadataManager";
var metadataManagerClass = scaffold.getClassLoader().loadClass(mdClassName);
var getInstance = metadataManagerClass.getMethod("getInstance", null);
return getInstance.invoke(null, []);
}
var metadataManager = getMetadataManager();
I stick this into a library loaded via the scriptExecutor execution vector, so I can reuse it.
Once you have the MetadataManager, you have to realize it returns a MetadataStorage object that you then have to locate the source for, and its superclasses. It's not hard to use, actually – just hard to discover.
This was WAY, WAY, too hard to figure out! This really should be a basic facility available to any script or plugin code. Metadata is too important to be left to third-party macros and their own conventions, undocumented interfaces, etc. This shouldn't be a major reverse-engineering project!
Also note that scripts can really do most anything at all. If a Confluence user can supply some script, they efectively have complete access to the server, as whatever user the Confluence container runs under. Be sure you understand the security implications of enabling scripts. Scriptix lets you create scripts that are locked down — i.e. only run administrator-supplied code, so it's possible to have some scripting on your site an still be secure, but as with all things powerful with security implications, you have to keep your wits about you.
Perhaps from beanshell the casting from the SQL results to an appropriately size...
Perhaps from beanshell the casting from the SQL results to an appropriately sized array is handled differently then when running as a compiled standalone Java program. From Java I do not see an error and it runs fine as seen in the following output:
# java phsTest phs_srvy.props
Connecting to //host/name-server
Connected to //host/name-server (PHS 20.0)
survey_status;measured_depth;
survey_status = final
measured_depth array length = 131
measured_depth[0]=0.0
measured_depth[1]=1884.0
measured_depth[2]=1985.0
measured_depth[3]=2298.0
measured_depth[4]=2335.0
.
.
.
Ideally what I'm trying to do is find a quick and simple method for SQL skilled data managers to publish their knowledge of data without becoming programmers. They like the SQL macro and it is working very well be I haven't noticed a way of casting the array data. Any thoughts?
This runs in the JVM of the server, therefore, all classes must be available via...
This runs in the JVM of the server, therefore, all classes must be available via the classpath defined for your server. For instance, with Tomcat, the shared (classes and lib) directory is suppose to be included in the Tomcat classpath. Also .../WEB-INF/classes or for jars in .../WEB-INF/lib. I haven't done this for jython, but I have used /WEB-INF/classes for beanshell successfully.
Comments (15)
Jul 06, 2007
Jon Nermut says:
Thanks for producing this plugin, I find it very useful. If I could add a coupl...Thanks for producing this plugin, I find it very useful.
If I could add a couple of feature requests:
1. Add the most common confluence manager objects, such as PageManager and SpaceManager etc as default scripting objects. This would save a line of nasty code in just about every script I write looking up these objects.
2. Cache the compiled version of groovy scripts, based on the hash of the script string
3. Add an admin console to run ad hoc scripts through the admin interface. This would just be a screen with a text box and a go button, with the output of the script printed below. Combined with #1 this would be extremely useful.
Thanks,
Jon
Jul 06, 2007
Bob Swift says:
Good suggestions. Please write up an issueGood suggestions. Please write up an issue for each of them. At least 1) should be easy to do.
Jul 07, 2007
Dan Hardiker says:
You should take a look at Scriptix it does the first already (and allows many mo...You should take a look at Scriptix – it does the first already (and allows many more scripting objects), it could compile scripts to byte code quite easily, and the admin console will soon have a "run" button to run scripts as well as hopefully a "console" for interactivity.
Jul 11, 2007
Jon Nermut says:
Where's the groovy support in Scriptx?Where's the groovy support in Scriptx?
Jul 11, 2007
Guy Fraser says:
You can install any of the libraries listed on this page for use with Scriptix: ...You can install any of the libraries listed on this page for use with Scriptix:
https://scripting.dev.java.net/
Aug 14, 2007
Andrew Miller says:
Any possibility of having Groovy support as standard in upcoming versions? We d...Any possibility of having Groovy support as standard in upcoming versions?
We definitely use it here and I'd prefer not to contact various people to migrate to Scriptix (presuming what they're doing will work).
Thanks.
Aug 26, 2007
Ki Alam says:
Can you access Metadata from the scripts? Thanks\!Can you access Metadata from the scripts?
Thanks!
Mar 24
Bob Kerns says:
It can be done from scripts. I've only done it from scriptix, via JavaScript, bu...It can be done from scripts. I've only done it from scriptix, via JavaScript, but here's the general idea.
First, you have to realize there are (at least) two sorts of metadata to deal with. One is managed by the metadata plugin. This is unversioned, and managed by the contentPropertyManager component. Scriptix provides a getComponent method to obtain references to Confluence components; otherwise you'll have to figure out how to get it yourself. There's nothing to list the available properties, but the metadata macro maintains a list of keys in a key named metadatakeys, with a format like:
The actual keys passed to the property manager would be named "metadata.size", "metadata.iterationid", etc. The property manager also manages things like page excerpts, the flags whether you are showing page children, editing locations and labels, etc. etc.. The best way to see it in action is to look at the os_propertyentry table in the database.
The other is the metadata maintained by he scaffold macro. This is versioned! The scaffolding code maintains its metadata in XML data that it stores in metadata with a key named ~metadata.<pageversion> -- well, actually getting all the versioning right would be a bit more complicated than that -- you definitely do not want to try to maintain this yourself.
Here's my code to obtain the the MetadataManager instance. You must have the Scaffolding plugin installed; this particular code also depends on scriptix:
I stick this into a library loaded via the scriptExecutor execution vector, so I can reuse it.
Once you have the MetadataManager, you have to realize it returns a MetadataStorage object that you then have to locate the source for, and its superclasses. It's not hard to use, actually – just hard to discover.
This was WAY, WAY, too hard to figure out! This really should be a basic facility available to any script or plugin code. Metadata is too important to be left to third-party macros and their own conventions, undocumented interfaces, etc. This shouldn't be a major reverse-engineering project!
I hope this info helps someone!
Oct 28, 2007
Quent Chalmers says:
Is the square bracket array notation supported with the beanshell? Getting parse...Is the square bracket array notation supported with the beanshell? Getting parse error:
Error parsing script Error information Parse error at line 47, column 38. Encountered: [ Source . . . ResultSet result = select.executeQuery( "select Fld1, Fld2 from Tbl where Fld1 = '608174'"); System.out.println("got results:"); while (result.next()) { String survey_status = result.getString(1); System.out.println("survey_status = " +survey_status); Object mdObject = result.getObject(2); float mdFloatArray[] = (float [])mdObject; int arrayLength = mdFloatArray.length; System.out.println("measured_depth array length = " + arrayLength); for (int index = 0; index < arrayLength; index++) { System.out.println("measured_depth[" + index +"]=" + mdFloatArray[index]); } . . .Oct 28, 2007
Bob Swift says:
Yes it does, you just have an error in your array specification. Here is an exam...Yes it does, you just have an error in your array specification. Here is an example that works:
{beanshell} int[] test= new int[4]; test[0] = 12; out.println("test[0] = " + test[0]); {beanshell}Oct 29, 2007
Quent Chalmers says:
Perhaps from beanshell the casting from the SQL results to an appropriately size...Perhaps from beanshell the casting from the SQL results to an appropriately sized array is handled differently then when running as a compiled standalone Java program. From Java I do not see an error and it runs fine as seen in the following output:
Ideally what I'm trying to do is find a quick and simple method for SQL skilled data managers to publish their knowledge of data without becoming programmers. They like the SQL macro and it is working very well be I haven't noticed a way of casting the array data. Any thoughts?
Oct 29, 2007
Bob Swift says:
Does this work? float mdFloatArray = ... . Anyway, I would suggest going to the...Does this work?
float[] mdFloatArray = ...Oct 29, 2007
Quent Chalmers says:
Thanks for all the help Bob, that fixed it. Now to do it without the beanshell.....Thanks for all the help Bob, that fixed it. Now to do it without the beanshell...
Feb 21, 2008
Jen Tang says:
First of all, great plugin\! A question: How do I import another jython class? ...First of all, great plugin!
A question: How do I import another jython class?
Say I've got an X.py file:
class X: def hello(): print "Hello"And a Y.py file:
from X import X x = X.X() x.hello()Then in Confluence:
{jython:output=wiki|script=#Y.py} {jython}I get an error of Unknow module X. How do I get something like this to work? (Currently both files are in the same directory "script".) Thanks.
Feb 21, 2008
Bob Swift says:
This runs in the JVM of the server, therefore, all classes must be available via...This runs in the JVM of the server, therefore, all classes must be available via the classpath defined for your server. For instance, with Tomcat, the shared (classes and lib) directory is suppose to be included in the Tomcat classpath. Also .../WEB-INF/classes or for jars in .../WEB-INF/lib. I haven't done this for jython, but I have used /WEB-INF/classes for beanshell successfully.