<
From version < 30.2 >
edited by Vincent Massol
on 2010/12/09
To version < 31.1 >
edited by coffeemug13
on 2011/03/24
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.VincentMassol
1 +XWiki.coffeemug13
Content
... ... @@ -6,17 +6,17 @@
6 6  
7 7  XWiki integrates [[jsr-223>>http://scripting.dev.java.net/]] scripting. You can script using several available languages by using one of the following macros:
8 8  
9 -* [[Velocity Macro>>code:Macros.VelocityMacro]] (installed by default in XWiki Enterprise)
10 -* [[Groovy Macro>>code:Macros.GroovyMacro]] (installed by default in XWiki Enterprise)
11 -* [[Python Macro>>code:Macros.PythonMacro]] (installed by default in XWiki Enterprise)
12 -* [[Ruby Macro>>code:Macros.RubyMacro]] (not installed by default in XWiki Enterprise)
13 -* [[PHP Macro>>code:Macros.PHPMacro]] (not installed by default in XWiki Enterprise)
9 +* [[Velocity Macro>>extensions:Extension.Velocity Macro]] (installed by default in XWiki Enterprise)
10 +* [[Groovy Macro>>extensions:Extension.Groovy Macro]] (installed by default in XWiki Enterprise)
11 +* [[Python Macro>>extensions:Extension.Python Macro]] (installed by default in XWiki Enterprise)
12 +* [[Ruby Macro>>extensions:Extension.Ruby Macro]] (not installed by default in XWiki Enterprise)
13 +* [[PHP Macro>>extensions:Extension.PHP Macro]] (not installed by default in XWiki Enterprise)
14 14  
15 15  = XWiki Scripting API =
16 16  
17 -The API is documented in Javadoc format and can be accessed here: [[XWiki API Javadoc>>DevGuide.API]]. If you are not familiar with Java or object oriented programming, you will probably be confused by the API documentation. It is not within the scope of our documentation to teach you all the details about Java, or object oriented programming. You can find all of that information already online. You can also explore the page code found throughout the [[Code Zone>>code:Main.WebHome]] area to see how others have figured out how to achieve a variety of results.
17 +The API is documented in Javadoc format and can be accessed here: [[XWiki API Javadoc>>DevGuide.API]]. If you are not familiar with Java or object oriented programming, you will probably be confused by the API documentation. It is not within the scope of our documentation to teach you all the details about Java, or object oriented programming. You can find all of that information already online. You can also explore the page code found throughout the [[Extensions wiki>>extensions:Main.WebHome]] area to see how others have figured out how to achieve a variety of results.
18 18  
19 -== [[Bindings>>code:Macros.ScriptMacro#HBindings]] ==
19 +== [[Bindings>>extensions:Extension.Script Macro#HBindings]] ==
20 20  
21 21  These objects are available to you in scripting languages.
22 22  
... ... @@ -25,27 +25,32 @@
25 25  * [[The Request object>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/web/XWikiRequest.html]]: **##request##**
26 26  * [[The Response object>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/web/XWikiResponse.html]]: **##response##**
27 27  * [[The XWiki object>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/api/XWiki.html]]: **##xwiki##**
28 +* [[The XWiki utils>>http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/com/xpn/xwiki/platform/xwiki-core/2.7/xwiki-core-2.7-javadoc.jar/!/com/xpn/xwiki/api/Util.html]]: **##util##**
28 28  
29 -== [[XWiki Component>>code:Modules.ComponentModule]] Access ==
30 +== [[XWiki Component>>extensions:Extension.Component Module]] Access ==
30 30  
31 31  You can also gain direct access to XWiki components using the following code snippet:
32 32  Also see: [[Accessing components from Groovy>>DevGuide.WritingComponents#HAccessingacomponentfromgroovy]]
33 33  Note: This snippet is written in Groovy and will have to be converted to your scripting language.
34 34  
35 -{{code language="java"}}{{groovy}}
36 +{{code language="java"}}
37 +{{groovy}}
36 36  def greeter = com.xpn.xwiki.web.Utils.getComponent(org.xwiki.component.HelloWorld.class);
37 37  println greeter.sayHello();
38 -{{/groovy}}{{/code}}
40 +{{/groovy}}
41 +{{/code}}
39 39  
40 40  == XWiki Core Access ==
41 41  
42 42  Sometimes the XWiki Api doesn't provide the methods which you need for your application. you can gain raw access the core of XWiki but it presents an increased security risk and requires programming rights to run. Using the core should be avoided if at all possible.
43 43  
44 -{{code language="java"}}{{groovy}}
47 +{{code language="java"}}
48 +{{groovy}}
45 45  def xc = xcontext.getContext();
46 46  def wiki = xc.getWiki();
47 47  def xdoc = doc.getDocument();
48 -{{/groovy}}{{/code}}
52 +{{/groovy}}
53 +{{/code}}
49 49  
50 50  After using this snippet, you will have 3 new objects:
51 51  
... ... @@ -137,12 +137,14 @@
137 137  
138 138  Example:
139 139  
140 -{{code}}{{velocity}}
145 +{{code}}
146 +{{velocity}}
141 141  #if ($hasAdmin)
142 142   ## This link will only be visible to users that have admin rights on this document
143 143   [[Do some admin action>>Some.Document]]
144 144  #end
145 -{{/velocity}}{{/code}}
151 +{{/velocity}}
152 +{{/code}}
146 146  
147 147  
148 148  === Information about the current wiki ===
... ... @@ -157,7 +157,7 @@
157 157  
158 158  Currently all non Velocity scripting languages are only allowed for administrators of a wiki (or users having the 'programming' right).
159 159  
160 -* See Groovy examples in the [[Code Zone>>code:Main.WebHome]], more specifically in the [[Code Snippets area>>code:Snippets.WebHome]]
167 +* See Groovy examples in the [[Extensions wiki>>extensions:Main.WebHome]]
161 161  * [[Feeling Groovy>>http://www-128.ibm.com/developerworks/java/library/j-alj08034.html]]
162 162  * [[MVC programming with Groovy templates>>http://www-128.ibm.com/developerworks/java/library/j-pg02155/]]
163 163  
... ... @@ -168,7 +168,8 @@
168 168  Using XWiki Syntax 2.0:
169 169  Objects can be passed back and forth between scripting languages by storing them in commonly available objects. One such commonly available object which only lasts the length of the request is the context object, known as xcontext.
170 170  
171 -{{code}}{{velocity}}
178 +{{code}}
179 +{{velocity}}
172 172  #set($hostname = "www.xwiki.org")
173 173  Host Name: $hostname
174 174  $xcontext.put("hostname", $hostname)
... ... @@ -182,12 +182,14 @@
182 182  {{/groovy}}
183 183  {{velocity}}
184 184  IP Address: $xcontext.get("address")
185 -{{/velocity}}{{/code}}
193 +{{/velocity}}
194 +{{/code}}
186 186  
187 187  Using XWiki Syntax 1.0:
188 188  Because Groovy and Velocity code are parsed together, variables defined in Groovy can be used directly in velocity without storing in and retrieving from the context.
189 189  
190 -{{code}}#set ($hostname = "www.xwiki.org")
199 +{{code}}
200 +#set ($hostname = "www.xwiki.org")
191 191  Host Name: $hostname
192 192  <%
193 193  import java.net.InetAddress;
... ... @@ -196,18 +196,21 @@
196 196  InetAddress addr = InetAddress.getByName(host);
197 197  String address = addr.getHostAddress();
198 198  %>
199 -IP Address: $address{{/code}}
209 +IP Address: $address
210 +{{/code}}
200 200  
201 201  = Python Specific Information =
202 202  
203 203  You can run python code in XWiki just like velocity or groovy.
204 204  
205 -{{code language="python"}}{{python}}
216 +{{code language="python"}}
217 +{{python}}
206 206  print "The full name of this document is " + doc.getFullName()
207 -{{/python}}{{/code}}
219 +{{/python}}
220 +{{/code}}
208 208  
209 209  {{warning}}
210 -Versions prior to [[XWiki Enterprise 2.4>>xwiki:ReleaseNotes.ReleaseNotesXWikiEnterprise24]] have a bug which prevents you from having access to the default objects (doc, xcontext, request, etc.) a [[workaround is available in the code zone>>code:Snippets.AccessToBindingsInPythonSnippet]]
223 +Versions prior to [[XWiki Enterprise 2.4>>xwiki:ReleaseNotes.ReleaseNotesXWikiEnterprise24]] have a bug which prevents you from having access to the default objects (doc, xcontext, request, etc.) a [[workaround is available in the Extensions wiki>>extensions:Extension.Access To Bindings In Python]]
211 211  {{/warning}}
212 212  
213 213  = Scripting In XWiki Syntax 1.0 =
... ... @@ -216,7 +216,7 @@
216 216  
217 217  * The only scripting languages available to you are Velocity and Groovy.
218 218  * In Groovy, the context is known as: **##context##** not **##xcontext##**
219 -* The beginning and end of Groovy scripts are denoted by <% and %> rather than through the [[code:Macros.GroovyMacro]] (using ~{~{groovy}} and ~{~{/groovy}})
220 -* Velocity is parsed in a page no matter what (there is no need to invoke the [[code:Macros.VelocityMacro]] using ~{~{velocity}} and ~{~{/velocity}})
232 +* The beginning and end of Groovy scripts are denoted by <% and %> rather than through the [[extensions:Extension.Groovy Macro]] (using ~{~{groovy}} and ~{~{/groovy}})
233 +* Velocity is parsed in a page no matter what (there is no need to invoke the [[extensions:Extension.Velocity Macro]] using ~{~{velocity}} and ~{~{/velocity}})
221 221  
222 222  The last part is important because it means you need to be careful of using $ and # in your document. This is still true inside of <% and %> so you have to be careful writing Groovy.

Get Connected