org.ceryle.wiki.plugin
Class InterWikiPlugin

java.lang.Object
  extended by org.ceryle.wiki.plugin.InterWikiPlugin
All Implemented Interfaces:
WikiPlugin
Direct Known Subclasses:
InterWikiDiff, RecentNearChanges

public class InterWikiPlugin
extends Object
implements WikiPlugin

Provides access to most of the XML-RPC features within a plugin. This currently also implements a RecentNearChanges feature. Because this potentially works across time zones, all times are processed as and displayed in UTC.

In the works is a plugin for synchronizing the contents of an external wiki with the current wiki via XML-RPC. The synchronization only happens in one direction (from the source wiki, which is not altered, to the wiki containing the page calling for synchronization). This plugin does not need to be installed on the source wiki, but XML-RPC must be enabled on both.

Parameters:

href='[InterWiki:Page]'
This is the interwiki link to the source wiki. The InterWiki value must be defined in the calling wiki's configuration. The Page value is ignored, but is generally recommended as the value "Main".
command='[string]'
The remote XML-RPC command to run. See Commands below for the list of commands. Not all are supported.
page='[string]'
Some remote commands require a page name.
version='[int]'
Some remote commands require a page version number.
since='[int]'
An optional parameter used with the "recentChanges" command. When provided, only the changes from the number of days specified by the 'since' value are included in the result.
format='compact'
When this parameter is present and the command outputs a table, the generated table is smaller and does not include all fields.
timeformat='[format]'
When this parameter is present, the modification date is presented in this format, which should be a Java Date format suitable for displaying timestamps. The default is "HH:mm:ss".
dateformat='[dd:MM:yyyy]'
When this parameter is present, the modification date is presented in this format, which should be a Java Date format suitable for displaying dates. The default is "dd:MM:yyyy".

Values for the timeformat and dateformat parameters are specified using the syntax as described in SimpleDateFormat

This currently produces only a synchronization list.

Commands

The following XML-RPC commands (case-insensitive) are supported:

"timezone"
returns the time zone from the remote wiki. No parameters required.
"page"
returns the wiki page text from the remote wiki. The page parameter is required. The version parameter is optional.
"pagehtml"
returns the HTML page text from the remote wiki. The page parameter is required. The version parameter is optional.
"pageinfo"
returns the page info from the remote wiki. The page parameter is required. The version parameter is optional.
"appname"
returns the application name of the remote wiki. No parameters required.
"baseurl"
returns the base URL of the remote wiki. No parameters required.
"viewurl"
returns the view URL of the specified page on the remote wiki. The page parameter is required.
"allpages"
returns a list of all the page names from the remote wiki. No parameters required.
"recentchanges"
returns the recent changes list from the remote wiki. No parameters required. If the optional since parameter is provided the returned list will only include that number of days' changes.
"listlinks"
returns the list of links of the specified page from the remote wiki. The page parameter is required.
"diff"
returns a diff between the specified page and the same-named page on the current wiki. The page parameter is required. The version parameter is optional.
TODO: This is not actually an XML-RPC feature, but uses the 'page' or 'pageversion' command to provide the content which is then passed to the diff utility.
Currently unsupported.

Author:
Murray Altheim

Nested Class Summary
protected  class InterWikiPlugin.PageRecord
           
 
Field Summary
static String CLASS_XMLRPC
          The CSS style class used for the output <div> element.
static String COMMAND_ALLPAGES
          A user-entered command string.
static String COMMAND_APPNAME
          A user-entered command string.
static String COMMAND_BASEURL
          A user-entered command string.
static String COMMAND_LISTLINKS
          A user-entered command string.
static String COMMAND_PAGE
          A user-entered command string.
static String COMMAND_PAGEHTML
          A user-entered command string.
static String COMMAND_PAGEINFO
          A user-entered command string.
static String COMMAND_RECENTCHANGES
          A user-entered command string.
static String COMMAND_TIMEZONE
          A user-entered command string.
static String COMMAND_VIEWURL
          A user-entered command string.
protected  String default_dateformat
          The default date format.
static int DEFAULT_DAYS
          How many days we show in recent changes lists by default.
protected static int DEFAULT_MODE
          Default mode, in absence of command parameter.
protected  String default_timeformat
          The default time format.
static String KEY_AUTHOR
          A key used in the values returned by the XML-RPC command.
static String KEY_HREF
          A key used in the values returned by the XML-RPC command.
static String KEY_LASTMODIFIED
          A key used in the values returned by the XML-RPC command.
static String KEY_NAME
          A key used in the values returned by the XML-RPC command.
static String KEY_PAGE
          A key used in the values returned by the XML-RPC command.
static String KEY_TYPE
          A key used in the values returned by the XML-RPC command.
static String KEY_VERSION
          A key used in the values returned by the XML-RPC command.
static boolean linkBack
          When true, creates a link back to the origin of the transcluded content.
protected  int m_cellpadding
          The value used for the amount of cell padding in generated tables.
protected  boolean m_compact
           
protected  boolean m_debug
          When true, generates debugging (noisy) output.
protected  DateFormat m_dfmt
          A DateFormat used to format times and dates in generated output.
protected  WikiEngine m_engine
           
protected  DateFormat m_rem_tfmt
          A DateFormat used to format times and dates in generated output.
protected  DateFormat m_utc_tfmt
          A DateFormat used to format times and dates in generated output.
protected  String m_xmlrpcURL
           
static int MODE_ALLPAGES
          A plugin mode.
static int MODE_APPNAME
          A plugin mode.
static int MODE_BASEURL
          A plugin mode.
static int MODE_LISTLINKS
          A plugin mode.
static int MODE_PAGE
          A plugin mode.
static int MODE_PAGEHTML
          A plugin mode.
static int MODE_PAGEHTMLVERSION
          A plugin mode.
static int MODE_PAGEINFO
          A plugin mode.
static int MODE_PAGEINFOVERSION
          A plugin mode.
static int MODE_PAGEVERSION
          A plugin mode.
static int MODE_RECENTCHANGES
          A plugin mode.
static int MODE_TIMEZONE
          A plugin mode.
static int MODE_UNKNOWN
          A plugin mode.
static int MODE_VIEWURL
          A plugin mode.
static String pagenameMain
          The value used for the Main page.
static String pagenameRecentChanges
          The value used for the RecentChanges page.
static String PARAM_COMMAND
          A plugin parameter String.
static String PARAM_DATE_FORMAT
          A plugin parameter String.
static String PARAM_FORMAT
          A plugin parameter String.
static String PARAM_HREF
          A plugin parameter String.
static String PARAM_PAGE
          A plugin parameter String.
static String PARAM_SINCE
          A plugin parameter String.
static String PARAM_TIME_FORMAT
          A plugin parameter String.
static String PARAM_VERSION
          A plugin parameter String.
protected  boolean prohibitDirectCalls
          When true, no direct calls to this plugin are permitted.
static boolean reverseSort
          When true, dates in recent changes are sorted in reverse order (the default).
static boolean showRemoteTime
          When true, times are displayed in the remote time zone, otherwise in UTC.
static boolean wrapWikiText
          When true, wraps returned wiki text content in an HTML <pre> element.
 
Fields inherited from interface com.ecyrd.jspwiki.plugin.WikiPlugin
CORE_PLUGINS_RESOURCEBUNDLE
 
Constructor Summary
InterWikiPlugin()
           
 
Method Summary
protected  void error(StringBuffer out, Exception e, String message)
          Process an error by clearing the existing buffer and populating it with an error message.
 String execute(WikiContext context, Map params)
           
protected  Calendar getRemoteCalendar()
          Returns the Calendar of the remote time zone based on the time zone ID returned via XML-RPC.
protected  String getRemoteTimeZoneID()
          Returns the timezone ID of the remote server as a String.
protected  String getViewURL(String pagename)
          Returns a remote view URL for the page name.
protected  void handleOutput(int mode, StringBuffer out, String pagename, int version, Object o)
          Populates the StringBuffer out provided with the mode, page and version names (required or optional depending on command), and the Object o returned from the XML-RPC client.
protected  void handleRecentChanges(StringBuffer out, Vector in)
           
protected  boolean isSameDay(Date d1, Date d2)
           
protected  void processAllPages(StringBuffer out, Vector in, String viewURL)
           
protected  InterWikiPlugin.PageRecord processHashtable(Hashtable ht)
          Processes a Hashtable value, returning a PageRecord.
protected  void processListLinks(StringBuffer out, Vector list)
           
protected  void processPageInfo(StringBuffer out, Hashtable ht)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_UNKNOWN

public static final int MODE_UNKNOWN
A plugin mode.

See Also:
Constant Field Values

MODE_TIMEZONE

public static final int MODE_TIMEZONE
A plugin mode.

See Also:
Constant Field Values

MODE_PAGE

public static final int MODE_PAGE
A plugin mode.

See Also:
Constant Field Values

MODE_PAGEHTML

public static final int MODE_PAGEHTML
A plugin mode.

See Also:
Constant Field Values

MODE_PAGEVERSION

public static final int MODE_PAGEVERSION
A plugin mode.

See Also:
Constant Field Values

MODE_PAGEHTMLVERSION

public static final int MODE_PAGEHTMLVERSION
A plugin mode.

See Also:
Constant Field Values

MODE_PAGEINFO

public static final int MODE_PAGEINFO
A plugin mode.

See Also:
Constant Field Values

MODE_PAGEINFOVERSION

public static final int MODE_PAGEINFOVERSION
A plugin mode.

See Also:
Constant Field Values

MODE_APPNAME

public static final int MODE_APPNAME
A plugin mode.

See Also:
Constant Field Values

MODE_BASEURL

public static final int MODE_BASEURL
A plugin mode.

See Also:
Constant Field Values

MODE_VIEWURL

public static final int MODE_VIEWURL
A plugin mode.

See Also:
Constant Field Values

MODE_ALLPAGES

public static final int MODE_ALLPAGES
A plugin mode.

See Also:
Constant Field Values

MODE_RECENTCHANGES

public static final int MODE_RECENTCHANGES
A plugin mode.

See Also:
Constant Field Values

MODE_LISTLINKS

public static final int MODE_LISTLINKS
A plugin mode.

See Also:
Constant Field Values

COMMAND_TIMEZONE

public static final String COMMAND_TIMEZONE
A user-entered command string.

See Also:
Constant Field Values

COMMAND_PAGE

public static final String COMMAND_PAGE
A user-entered command string.

See Also:
Constant Field Values

COMMAND_PAGEHTML

public static final String COMMAND_PAGEHTML
A user-entered command string.

See Also:
Constant Field Values

COMMAND_PAGEINFO

public static final String COMMAND_PAGEINFO
A user-entered command string.

See Also:
Constant Field Values

COMMAND_APPNAME

public static final String COMMAND_APPNAME
A user-entered command string.

See Also:
Constant Field Values

COMMAND_BASEURL

public static final String COMMAND_BASEURL
A user-entered command string.

See Also:
Constant Field Values

COMMAND_VIEWURL

public static final String COMMAND_VIEWURL
A user-entered command string.

See Also:
Constant Field Values

COMMAND_ALLPAGES

public static final String COMMAND_ALLPAGES
A user-entered command string.

See Also:
Constant Field Values

COMMAND_RECENTCHANGES

public static final String COMMAND_RECENTCHANGES
A user-entered command string.

See Also:
Constant Field Values

COMMAND_LISTLINKS

public static final String COMMAND_LISTLINKS
A user-entered command string.

See Also:
Constant Field Values

KEY_LASTMODIFIED

public static final String KEY_LASTMODIFIED
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

KEY_NAME

public static final String KEY_NAME
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

KEY_AUTHOR

public static final String KEY_AUTHOR
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

KEY_VERSION

public static final String KEY_VERSION
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

KEY_PAGE

public static final String KEY_PAGE
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

KEY_HREF

public static final String KEY_HREF
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

KEY_TYPE

public static final String KEY_TYPE
A key used in the values returned by the XML-RPC command.

See Also:
Constant Field Values

PARAM_COMMAND

public static final String PARAM_COMMAND
A plugin parameter String.

See Also:
Constant Field Values

PARAM_HREF

public static final String PARAM_HREF
A plugin parameter String.

See Also:
Constant Field Values

PARAM_SINCE

public static final String PARAM_SINCE
A plugin parameter String.

See Also:
Constant Field Values

PARAM_PAGE

public static final String PARAM_PAGE
A plugin parameter String.

See Also:
Constant Field Values

PARAM_VERSION

public static final String PARAM_VERSION
A plugin parameter String.

See Also:
Constant Field Values

PARAM_FORMAT

public static final String PARAM_FORMAT
A plugin parameter String.

See Also:
Constant Field Values

PARAM_TIME_FORMAT

public static final String PARAM_TIME_FORMAT
A plugin parameter String.

See Also:
Constant Field Values

PARAM_DATE_FORMAT

public static final String PARAM_DATE_FORMAT
A plugin parameter String.

See Also:
Constant Field Values

CLASS_XMLRPC

public static final String CLASS_XMLRPC
The CSS style class used for the output <div> element. The value is "xmlrpc".

See Also:
Constant Field Values

pagenameMain

public static String pagenameMain
The value used for the Main page. While this can vary wiki-to-wiki, hopefully it still exists and is aliased to whatever is the actual wiki home page.


pagenameRecentChanges

public static String pagenameRecentChanges
The value used for the RecentChanges page. While this can vary wiki-to-wiki, hopefully it still exists and is aliased to whatever is the actual RecentChanges page.


wrapWikiText

public static boolean wrapWikiText
When true, wraps returned wiki text content in an HTML <pre> element.


linkBack

public static boolean linkBack
When true, creates a link back to the origin of the transcluded content. The default is true.


reverseSort

public static boolean reverseSort
When true, dates in recent changes are sorted in reverse order (the default).


showRemoteTime

public static boolean showRemoteTime
When true, times are displayed in the remote time zone, otherwise in UTC. The default is true.


prohibitDirectCalls

protected boolean prohibitDirectCalls
When true, no direct calls to this plugin are permitted. The default is true, as the InterWikiPlugin is not meant to be called directly, only by subclasses.

If this plugin is being used on a public wiki it's probably safer to have this set true to keep its features from being abused.


DEFAULT_MODE

protected static int DEFAULT_MODE
Default mode, in absence of command parameter.


m_dfmt

protected DateFormat m_dfmt
A DateFormat used to format times and dates in generated output.


m_utc_tfmt

protected DateFormat m_utc_tfmt
A DateFormat used to format times and dates in generated output.


m_rem_tfmt

protected DateFormat m_rem_tfmt
A DateFormat used to format times and dates in generated output.


m_debug

protected boolean m_debug
When true, generates debugging (noisy) output.


m_cellpadding

protected int m_cellpadding
The value used for the amount of cell padding in generated tables.


DEFAULT_DAYS

public static final int DEFAULT_DAYS
How many days we show in recent changes lists by default.

See Also:
Constant Field Values

default_dateformat

protected String default_dateformat
The default date format.


default_timeformat

protected String default_timeformat
The default time format.


m_engine

protected WikiEngine m_engine

m_xmlrpcURL

protected String m_xmlrpcURL

m_compact

protected boolean m_compact
Constructor Detail

InterWikiPlugin

public InterWikiPlugin()
Method Detail

execute

public String execute(WikiContext context,
                      Map params)
               throws PluginException
Specified by:
execute in interface WikiPlugin
Throws:
PluginException

getViewURL

protected String getViewURL(String pagename)
Returns a remote view URL for the page name.


handleOutput

protected void handleOutput(int mode,
                            StringBuffer out,
                            String pagename,
                            int version,
                            Object o)
                     throws PluginException,
                            org.apache.xmlrpc.XmlRpcException,
                            IOException
Populates the StringBuffer out provided with the mode, page and version names (required or optional depending on command), and the Object o returned from the XML-RPC client.

Throws:
a - PluginException if the mode is not supported by this plugin.
PluginException
org.apache.xmlrpc.XmlRpcException
IOException

getRemoteTimeZoneID

protected String getRemoteTimeZoneID()
Returns the timezone ID of the remote server as a String.


getRemoteCalendar

protected Calendar getRemoteCalendar()
                              throws PluginException
Returns the Calendar of the remote time zone based on the time zone ID returned via XML-RPC. This also sets the member variable for the time zone offset from UTC.

Throws:
PluginException

processPageInfo

protected void processPageInfo(StringBuffer out,
                               Hashtable ht)
                        throws PluginException
Throws:
PluginException

processHashtable

protected InterWikiPlugin.PageRecord processHashtable(Hashtable ht)
                                               throws PluginException
Processes a Hashtable value, returning a PageRecord. Hashtables are returned by the pageinfo and recentchanges commands.

Throws:
PluginException

handleRecentChanges

protected void handleRecentChanges(StringBuffer out,
                                   Vector in)
                            throws PluginException
Throws:
PluginException

processAllPages

protected void processAllPages(StringBuffer out,
                               Vector in,
                               String viewURL)
                        throws PluginException,
                               IOException,
                               org.apache.xmlrpc.XmlRpcException
Throws:
PluginException
IOException
org.apache.xmlrpc.XmlRpcException

processListLinks

protected void processListLinks(StringBuffer out,
                                Vector list)
                         throws PluginException,
                                IOException,
                                org.apache.xmlrpc.XmlRpcException
Throws:
PluginException
IOException
org.apache.xmlrpc.XmlRpcException

isSameDay

protected boolean isSameDay(Date d1,
                            Date d2)

error

protected void error(StringBuffer out,
                     Exception e,
                     String message)
Process an error by clearing the existing buffer and populating it with an error message.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.