cogA script to help with the delicate task for created the right XML for a Refactoring Job for non Java clients
Developed by

Thomas Mortagne

0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents


The following example create a move request in a groovy script that you can execute in any wiki page (provided you have programming right):

import org.xwiki.model.reference.*;

// Create a request to move a page using the standard API
// That's generally the only part you need to customize for your own request need
var source = new SpaceReference("xwiki", "MyParentPage", "MyPage");
var destination = new SpaceReference("xwiki", "MyPageNewLocaltion", "MyPageNewName");
var jobRequest = services.component.getInstance(org.xwiki.refactoring.script.RequestFactory.class).createMoveRequest(source, destination)

/////////// SERIALIZATION ////////////////////

// cleanup the request from properties which make sense for a script but are pretty much useless in the case of a REST request

// Convert the standard move request into a REST job request
var restJobRequest = services.component.getInstance(;

// Serialize the REST job request into an XML content
var writer = new;
var context = javax.xml.bind.JAXBContext.newInstance("");
var marshaller = context.createMarshaller();
// Format the XML to make the example more readable but the XML obviously does not need to be formatter in the request
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(restJobRequest, writer);

println "{{code language='xml'}}"
println writer.toString()
println "{{/code}}"

You can find various other examples of what the refactoring API can do on Refactoring Module.


Get Connected