<
From version < 17.5 >
edited by Caleb James DeLisle
on 2010/01/02
To version < 18.1 >
edited by Caleb James DeLisle
on 2010/01/03
>
Change comment: Use a Groovy example which works.

Summary

Details

Page properties
Content
... ... @@ -60,17 +60,18 @@
60 60  
61 61  == Groovy Example
62 62  
63 -The following example demonstrates how to use a groovy script directly inside your page. This example performs a reverse DNS lookup from the velocity variable ##$address## and store the result into the variable ##$hostname##.
63 +The following example demonstrates how to use a groovy script to interact with velocity code in your page. This example performs a DNS lookup from the velocity variable ##$hostname## and stores the result in the variable ##$address##.
64 64  
65 +Using XWiki Syntax 1.0:
65 65  {{code}}
66 -#set ($address = "172.20.12.61")
67 -IP Address: $address
67 +#set ($hostname = "www.xwiki.org")
68 +Host Name: $hostname
68 68  <%
69 69  import java.net.InetAddress;
70 70  vcontext = context.get("vcontext");
71 -hostname = vcontext.get("address");
72 -InetAddress addr = InetAddress.getByName(hostname);
73 -hostname = addr.getHostName().toLowerCase();
72 +host = vcontext.get("hostname");
73 +InetAddress addr = InetAddress.getByName(host);
74 +String address = addr.getHostAddress();
74 74  %>
75 -Hostname: $hostname
76 +IP Address: $address
76 76  {{/code}}

Get Connected