Thinking about it, I'm not sure why I felt XML-RPC was necessary. :) Here's a simpler example that does it all over straight http get/post. Requires the apache commons httpclient lib, which requires commons logging and commons codec. ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-- package org.soal.XWikiPost; import java.io.IOException; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; public class XWikiPoster { //----( Configuration [change me!] )---- static final String SERVER = "http://my.xwiki.com"; static final String USERNAME = "myName"; // exactly how you'd enter static final String PASSWORD = "myPass"; // them in the web login form static final String SPACE = "Sandbox"; static final String DYNAMIC = "Dynamic"; static final String STATIC = "Static"; //-------------------------------------- static HttpClient client = new HttpClient(); public static void main(String[] args) throws HttpException, IOException { client.getParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); login(); String renderedContent = getRenderedContent(SPACE, DYNAMIC); postContent(SPACE, STATIC, renderedContent); } private static void login() throws HttpException, IOException { String url = String.format("%s/xwiki/bin/login/XWiki/XWikiLogin", SERVER); PostMethod method = new PostMethod(url); method.addParameter("j_username", USERNAME); method.addParameter("j_password", PASSWORD); method.addParameter("j_rememberme", "false"); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Login response (redirect is normal): " + method.getStatusLine()); } } private static String getRenderedContent(String space, String page) throws IOException, HttpException { String template="xpage=plain"; String url = String.format("%s/xwiki/bin/view/%s/%s?%s", SERVER, space, page, template); GetMethod method = new GetMethod(url); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Get response: " + method.getStatusLine()); } String responseBody = new String(method.getResponseBody()); return responseBody; } private static void postContent(String space, String page, String content) throws HttpException, IOException { String url = String.format("%s/xwiki/bin/save/%s/%s", SERVER, space, page); PostMethod method = new PostMethod(url); method.addParameter("content", content); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Save response (redirect is normal): " + method.getStatusLine()); } } } ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-- Regards, Robin. On 12/10/06, Robin Fernandes <[email protected]> wrote:
Hi,
There's probably several ways to do this... the first one that comes to my mind is to write an XML-RPC client to grab the rendered content from one page and save it back into another. Then set up a cron job to kick off your XML-RPC client periodically. A simple implementation of the XML-RPC client is below.
Alternatively you could write the code to do the copy in a groovy script in another XWiki document and hit it periodically.
---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--
package com.ibm.robinf.xwikixmlrpcclient;
import java.io.IOException; import java.net.MalformedURLException; import java.util.Hashtable; import java.util.Vector;
import org.apache.xmlrpc.XmlRpcClient; import org.apache.xmlrpc.XmlRpcException;
/** * @author Robin */ public class XWikiRPCTest { //----( Configuration [change me!] )---- protected final static String XMLRPC_SERVER_URL = "http://mywiki.blah.com/xwiki/bin/xmlrpc/confluence"; protected final static String DYNAMIC = "Play.Dynamic"; protected final static String STATIC = "Play.Static"; protected final static String WIKI_NAME = "robin_fernandesatukibmcom"; protected final static String PASSWORD = "WXYZ"; //--------------------------------------
protected XmlRpcClient client;
public XWikiRPCTest() throws MalformedURLException { client = new XmlRpcClient(XMLRPC_SERVER_URL); }
public static void main(String[] args) throws XmlRpcException, IOException { XWikiRPCTest myRPCTest = new XWikiRPCTest(); String token = myRPCTest.login(); String renderedContent = myRPCTest.getRenderedContent(DYNAMIC, token); Hashtable<String, String> staticPage = myRPCTest.getPage(STATIC, token); staticPage.put("content", renderedContent); myRPCTest.putPage(staticPage, token); myRPCTest.logout(token); }
private String getRenderedContent(String pageName, String token) throws XmlRpcException, IOException { Hashtable<String, String> dynamicPage = getPage(DYNAMIC, token); String rawContent = dynamicPage.get("content");
Vector<String> params = new Vector<String>(4); params.add(token); params.add("Play"); params.add(pageName); params.add(rawContent);
String renderedContent = (String) client.execute("confluence1.renderContent", params); return renderedContent; }
protected String login() throws XmlRpcException, IOException { String loginToken; Vector<String> loginParams = new Vector<String>(2); loginParams.add(WIKI_NAME); loginParams.add(PASSWORD); loginToken = (String) client.execute ("confluence1.login", loginParams); System.out.println("Login: " + loginToken); return loginToken; }
protected void logout(String loginToken) throws XmlRpcException, IOException { Vector<String> logoutParams = new Vector<String>(1); logoutParams.add(loginToken); System.out.println("Logout: " + client.execute ("confluence1.logout", logoutParams)); }
private Hashtable<String, String> getPage(String pageName, String token) throws XmlRpcException, IOException { Vector<String> params = new Vector<String>(); params.add(token); params.add(pageName); Hashtable<String, String> page = (Hashtable<String, String>) client.execute("confluence1.getPage", params); return page; }
private void putPage(Hashtable page, String token) throws XmlRpcException, IOException { Vector<Object> params = new Vector<Object>(); params.add(token); params.add(page); client.execute ("confluence1.storePage", params); }
} ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--
Cheers, Robin
On 12/10/06, [email protected] <[email protected]> wrote:
All, Here is what I am wanting to do. I have a page that generates some dynamic data via a plug-in and every so often I was to "snap-shot" it to a static page. Mean, take the dynamic page data and create a static xwiki page from it.
1) Is it possible to do? 2) If so, how do I do it.
Thanks,
Tony Nuzzi
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws