Hi,
As you said, I wrote a Java batch using XWikiXmlRpcClient witch is very
helpfull.
Everythings is working fine to copy :
- page
- attachments
- objects
But I have a problem to copy an XWikiPage witch is an XWikiClass (having
Properties); from one Wiki to another one using this API. (For exemple
XWiki.XWikiSkins)
I don't find the way to do this using XWikiXmlRpcClient .
Here is my code : the class containing all information of a Wiki Page :
package com.afklm.iwiki.batch.xmlrpc;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlrpc.XmlRpcException;
import org.codehaus.swizzle.confluence.Attachment;
import org.xwiki.xmlrpc.XWikiXmlRpcClient;
import org.xwiki.xmlrpc.model.XWikiObject;
import org.xwiki.xmlrpc.model.XWikiObjectSummary;
import org.xwiki.xmlrpc.model.XWikiPage;
import com.afklm.iwiki.exceptions.AFWikiAccessException;
/**
* Page Wiki contenant les divers partie d'une page XWiki à
accéder via xmlRpc :
* <ul>
* <li>Contenu</li>
* <li>Liste d'object</li>
* <li>Liste d'attachements</li>
* <li>Properties de class</li>
* </ul>
*
* @author M328624
*
*/
public class XmlRpcWikiPage {
/**
* Logger.
*/
private static Log logger = LogFactory.getFactory
().getInstance(XmlRpcWikiPage.class);
/**
* FullName XWiki de la page.
*/
String fullName;
/**
* XWiki current page.
*/
XWikiPage page;
/**
* Si la page courante est une class XWiki.
*/
//XWikiClass xwikiClass;
/**
* Objects present in the current page.
*/
List<XWikiObject> lObj = new ArrayList<XWikiObject>();
/**
* Attachments present to a current page.
*/
List<Attachment> lAttach = new ArrayList<Attachment>();
public XmlRpcWikiPage(AFURLWikiAccess awa, String fullName)
throws AFWikiAccessException {
try {
logger.debug("-> Tentative de recuperation page : '"
+
fullName + "' (" + awa.getWikiURL() + ")...");
XWikiXmlRpcClient curClient = awa.getXmlRpcClient();
this.fullName = fullName;
// Récupération de la page elle même
this.page = curClient.getPage(fullName);
// Récupération des objects
List<XWikiObjectSummary> lObjSum =
curClient.getObjects(this.page);
for (XWikiObjectSummary curObj : lObjSum) {
getLObj().add(curClient.getObject(curObj));
}
// Récupération des attachements
this.lAttach = curClient.getAttachments(page);
// Récupération de la classe (Pour les pages de type
classe)
//this.xwikiClass = curClient.getClass(this.fullName);
logger.debug("-> Recuperation page : '" + fullName
+
"' (" + awa.getWikiURL() + ") ok.");
curClient.logout();
} catch (XmlRpcException e) {
logger.error((new StringBuilder("o !!! Pb lors de la
création de la page '")).append(fullName).append("' avec
'"
).append(awa.getWikiURL()).append("' : ").append(e.getMessage())
.toString());
e.printStackTrace();
}
}
/**
* @return FullName XWiki de la page.
*/
public String getFullName() {
return fullName;
}
public List<Attachment> getLAttach() {
return lAttach;
}
public List<XWikiObject> getLObj() {
return lObj;
}
public XWikiPage getPage() {
return page;
}
// public XWikiClass getXWikiClass() {
// return xwikiClass;
// }
/**
* Permet de renommer une page.
* @param targetSpace Nouvel espace.
* @param targetName Nouveau nom de page.
*/
public void rename(String targetSpace, String targetName) {
this.fullName = targetSpace + "." + targetName;
this.getPage().setId(this.fullName);
this.getPage().setSpace(targetSpace);
this.getPage().setTitle(targetName);
for (XWikiObject curObj : this.getLObj()) {
curObj.setPageId(this.fullName);
}
for (Attachment curAttach : this.getLAttach()) {
curAttach.setPageId(this.fullName);
}
}
}
And here is the method used to copy page (page + objects + attachment but
not 'properties of a class') :
public void storeXmlRcpWikiPage(XmlRpcWikiPage curPage) throws
AFWikiAccessException {
try {
logger.debug("-> Tentative d'installation page : '" +
curPage.getFullName() + "' (" + this.getWikiURL() + ")...");
XWikiXmlRpcClient curClient = this.getXmlRpcClient();
// Store de la page elle même (title + content + ...)
curClient.storePage(curPage.getPage());
// Store des différents object
for (XWikiObject curObj : curPage.getLObj()) {
curClient.storeObject(curObj);
}
// Put Attachments
for (Attachment curAttach : curPage.getLAttach()) {
byte[] curAttachData =
curClient.getAttachmentData(curAttach);
curClient.addAttachment(0, curAttach, curAttachData);
}
// Class properties
// if (!curPage.getXWikiClass().getProperties().isEmpty()) {
// logger.debug("ooo Class !!! '" + curPage.fullName +
"'
:" + curPage.getXWikiClass().toString());
// logger.debug("ooo Class
curClient.getClass(curPage.fullName) (avant) :" +
curClient.getClass(curPage.fullName).toString());
//
curClient.getClass(curPage.fullName).setId(curPage.getFullName());
//
curClient.getClass(curPage.fullName).setPropertyToAttributesMap(curPage.getXWikiClass().toMap());
// logger.debug("ooo Class
curClient.getClass(curPage.fullName) (apres) :" +
curClient.getClass(curPage.fullName).toString());
// }
logger.debug("-> Installation page : '" +
curPage.getFullName() + "' (" + this.getWikiURL() + ") ok.");
curClient.logout();
} catch (XmlRpcException e) {
logger.error("o !!! Pb lors de l'intallation de la page
'" +
curPage + "' : " + e.getMessage());
e.printStackTrace();
}
}
Thanks,
Julien
Sergiu Dumitriu
<sergiu(a)xwiki.com
A
Envoyé par : XWiki Developers <devs(a)xwiki.org>
devs-bounces@xwik cc
i.org
Objet
Re: [xwiki-devs] Acces to xwiki
11/02/2009 09:33 1.7.1 in Batch mode
Veuillez répondre
à
XWiki Developers
<devs(a)xwiki.org>
Julien Revert wrote:
Hi,
I wrote a java batch allowing to acces XWIKI.
This batch was okay with 1.5.2 XWiki release but it's not working with
1.7.1 XWiki release.
I don't understand where is my problem and need your help...
I have a runtime error while execute line :
wiki = new com.xpn.xwiki.XWiki(conf, new XWikiContext());
A stack trace would be useful...
If someone has a better way to access XWIKI in batch
mode; it good to !
It depends on what you're trying to do.
You can always use your favorite scripting language with an XmlRpc
connection to a running wiki. Or, in Java, you can use Swizzle to do
this, which makes things easier.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs