001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.filters;
021:
022: import com.ecyrd.jspwiki.WikiContext;
023: import com.ecyrd.jspwiki.WikiEngine;
024: import org.apache.xmlrpc.*;
025: import java.net.URL;
026: import java.net.MalformedURLException;
027: import java.util.*;
028: import org.apache.log4j.Logger;
029:
030: /**
031: * A very dumb class that pings weblogs.com on each save. INTERNAL USE ONLY SO FAR!
032: * Look, but don't use as-is.
033: */
034: // FIXME: Needs to figure out when only weblogs have been saved.
035: // FIXME: rpc endpoint must be configurable
036: // FIXME: Should really be settable per-page.
037: // FIXME: Weblog name has been set to stone
038: public class PingWeblogsComFilter extends BasicPageFilter {
039: static Logger log = Logger.getLogger(PingWeblogsComFilter.class);
040:
041: public String m_pingURL;
042:
043: public static final String PROP_PINGURL = "pingurl";
044:
045: public void initialize(WikiEngine engine, Properties props) {
046: m_pingURL = props.getProperty(PROP_PINGURL,
047: "http://rpc.weblogs.com/RPC2");
048: }
049:
050: public void postSave(WikiContext context, String pagecontent) {
051: String blogName = context.getPage().getName();
052: WikiEngine engine = context.getEngine();
053:
054: int blogentryTxt = blogName.indexOf("_blogentry_");
055: if (blogentryTxt == -1) {
056: return; // This is not a weblog entry.
057: }
058:
059: blogName = blogName.substring(0, blogentryTxt);
060:
061: if (blogName.equals(engine.getFrontPage())) {
062: blogName = null;
063: }
064:
065: try {
066: XmlRpcClient xmlrpc = new XmlRpcClient(m_pingURL);
067: Vector params = new Vector();
068: params.addElement("The Butt Ugly Weblog"); // FIXME: Must be settable
069: params.addElement(engine.getURL(WikiContext.VIEW, blogName,
070: null, true));
071:
072: if (log.isDebugEnabled())
073: log.debug("Pinging weblogs.com with URL: "
074: + engine.getURL(WikiContext.VIEW, blogName,
075: null, true));
076:
077: xmlrpc.executeAsync("weblogUpdates.ping", params,
078: new AsyncCallback() {
079: public void handleError(Exception ex, URL url,
080: String method) {
081: log.error(
082: "Unable to execute weblogs.com ping to URL: "
083: + url.toString(), ex);
084: }
085:
086: public void handleResult(Object result,
087: URL url, String method) {
088: Hashtable res = (Hashtable) result;
089:
090: Boolean flerror = (Boolean) res
091: .get("flerror");
092: String msg = (String) res.get("message");
093:
094: if (flerror.booleanValue()) {
095: log.error("Failed to ping: " + msg);
096: }
097:
098: log.info("Weblogs.com has been pinged.");
099: }
100: });
101: } catch (MalformedURLException e) {
102: log.error("Malformed URL", e);
103: }
104: }
105: }
|