Search in sources :

Example 1 with AsyncCallback

use of org.apache.xmlrpc.AsyncCallback in project jspwiki by apache.

the class PingWeblogsComFilter method postSave.

/**
 *  {@inheritDoc}
 */
public void postSave(WikiContext context, String pagecontent) {
    String blogName = context.getPage().getName();
    WikiEngine engine = context.getEngine();
    int blogentryTxt = blogName.indexOf("_blogentry_");
    if (blogentryTxt == -1) {
        // This is not a weblog entry.
        return;
    }
    blogName = blogName.substring(0, blogentryTxt);
    if (blogName.equals(engine.getFrontPage())) {
        blogName = null;
    }
    try {
        XmlRpcClient xmlrpc = new XmlRpcClient(m_pingURL);
        Vector<String> params = new Vector<String>();
        // FIXME: Must be settable
        params.addElement("The Butt Ugly Weblog");
        params.addElement(engine.getURL(WikiContext.VIEW, blogName, null, true));
        if (log.isDebugEnabled())
            log.debug("Pinging weblogs.com with URL: " + engine.getURL(WikiContext.VIEW, blogName, null, true));
        xmlrpc.executeAsync("weblogUpdates.ping", params, new AsyncCallback() {

            public void handleError(Exception ex, URL url, String method) {
                log.error("Unable to execute weblogs.com ping to URL: " + url.toString(), ex);
            }

            public void handleResult(Object result, URL url, String method) {
                Hashtable res = (Hashtable) result;
                Boolean flerror = (Boolean) res.get("flerror");
                String msg = (String) res.get("message");
                if (flerror.booleanValue()) {
                    log.error("Failed to ping: " + msg);
                }
                log.info("Weblogs.com has been pinged.");
            }
        });
    } catch (MalformedURLException e) {
        log.error("Malformed URL", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcClient(org.apache.xmlrpc.XmlRpcClient) Hashtable(java.util.Hashtable) AsyncCallback(org.apache.xmlrpc.AsyncCallback) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) WikiEngine(org.apache.wiki.WikiEngine) Vector(java.util.Vector)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 WikiEngine (org.apache.wiki.WikiEngine)1 AsyncCallback (org.apache.xmlrpc.AsyncCallback)1 XmlRpcClient (org.apache.xmlrpc.XmlRpcClient)1