XWiki API Guide
This guide covers the main XWiki APIs. It's not meant to be comprehensive. For that you'll need to check the XWiki Reference API page.Querying documents
See the HQL Velocity Examples page.Getting external content
You can use the following APIs to get content located at external URLs:public String getURLContent(String surl, String username, String password) throws IOException public String getURLContent(String surl) throws IOException public String getURLContent(String surl, String username, String password, int timeout) throws IOException public String getURLContent(String surl, int timeout) throws IOException public byte[] getURLContentAsBytes(String surl, String username, String password) public byte[] getURLContentAsBytes(String surl) throws IOException
$xwiki.getURLContent("http://teamcity.xwiki.org/externalStatus.html")Add objects to a page
Here a piece of code to show how is possible to store a new object in one page:## Create an object #set($obj = $doc.newObject("XWiki.SomeClass")) $obj.set("field1",$value1) $obj.set("field2",$value2) ## Save the object in the page $doc.save()
Access objects in a page
Here is a piece of code to show how it is possible to access an object attached to the page, and read its fields :## Retrieve the first object (index [0]) among all objects attached to this page and of a certain class #set($obj = $doc.getObject("SomeSpace.SomeClass")) ## Retrieve the value of the propertty "field1" for this object, provided a property called "field1" is actually defined in the class of this object #set($field1 = $obj.get("field1")) SomeSpace.SomeClass[0] : field1 = "$field1"
#set($class = $obj.xWikiClass) ## access the class object representing SomeSpace.SomeClass
#foreach($prop in $class.properties) ## go through all properties
<dt> *${prop.prettyName}* </dt>
<dd>$doc.display($prop.getName())</dd>
#end$doc.display(propertyName)
display(propertyName) method to access properties of an object attached to the including page, you have to use the includeForm() Velocity macro in the including script :
#includeForm("spacename.docname")includeForm() macro.
Include a Velocity page into another Velocity page
See Include In Velocity.
Version 2.2 last modified by VincentMassol on 17/05/2008 at 12:59
Document data
Attachments:
No attachments for this document
Comments: 0