You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/02/13 06:54:24 UTC
svn commit: r627255 [20/41] - in
/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src: ./ com/ com/ecyrd/
com/ecyrd/jspwiki/ com/ecyrd/jspwiki/action/ com/ecyrd/jspwiki/attachment/
com/ecyrd/jspwiki/auth/ com/ecyrd/jspwiki/auth/acl/ com/ecyrd/jspwiki...
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiEventUtils.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiEventUtils.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiEventUtils.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiEventUtils.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,161 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2006 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package com.ecyrd.jspwiki.event;
+
+import com.ecyrd.jspwiki.WikiEngine;
+
+/**
+ * A utility class that adds some JSPWiki-specific functionality to the
+ * WikiEventManager (which is really a general-purpose event manager).
+ *
+ * @author Murray Altheim
+ * @since 2.4.20
+ */
+public class WikiEventUtils
+{
+ /**
+ * This ungainly convenience method adds a WikiEventListener to the
+ * appropriate component of the provided client Object, to listen
+ * for events of the provided type (or related types, see the table
+ * below).
+ * <p>
+ * If the type value is valid but does not match any WikiEvent type
+ * known to this method, this will just attach the listener to the
+ * client Object. This may mean that the Object never fires events
+ * of the desired type; type-to-client matching is left to you to
+ * guarantee. Silence is golden, but not if you want those events.
+ * </p>
+ * <p>
+ * Most event types expect a WikiEngine as the client, with the rest
+ * attaching the listener directly to the supplied source object, as
+ * described below:
+ * </p>
+ * <table border="1" cellpadding="4">
+ * <tr><th>WikiEvent Type(s) </th><th>Required Source Object </th><th>Actually Attached To </th>
+ * </tr>
+ * <tr><td>any WikiEngineEvent </td><td>WikiEngine </td><td>WikiEngine </td></tr>
+ * <tr><td>WikiPageEvent.PAGE_LOCK,
+ * WikiPageEvent.PAGE_UNLOCK </td><td>WikiEngine or
+ * PageManager </td><td>PageManager </td></tr>
+ * <tr><td>WikiPageEvent.PAGE_REQUESTED,
+ * WikiPageEvent.PAGE_DELIVERED </td>
+ * <td>WikiServletFilter </td>
+ * <td>WikiServletFilter </td></tr>
+ * <tr><td>WikiPageEvent (<a href="#pbeTypes">phase boundary event</a>)</td>
+ * <td>WikiEngine </td><td>FilterManager </td></tr>
+ * <tr><td>WikiPageEvent (<a href="#ipeTypes">in-phase event</a>)</td>
+ * <tr><td>WikiPageEvent (in-phase event)</td>
+ * <td>any </td><td>source object </td></tr>
+ * <tr><td>WikiSecurityEvent </td><td>any </td><td>source object </td></tr>
+ * <tr><td>any other valid type </td><td>any </td><td>source object </td></tr>
+ * <tr><td>any invalid type </td><td>any </td><td>nothing </td></tr>
+ * </table>
+ *
+ * <p id="pbeTypes"><small><b>phase boundary event types:</b>
+ * <tt>WikiPageEvent.PRE_TRANSLATE_BEGIN</tt>, <tt>WikiPageEvent.PRE_TRANSLATE_END</tt>,
+ * <tt>WikiPageEvent.POST_TRANSLATE_BEGIN</tt>, <tt>WikiPageEvent.POST_TRANSLATE_END</tt>,
+ * <tt>WikiPageEvent.PRE_SAVE_BEGIN</tt>, <tt>WikiPageEvent.PRE_SAVE_END</tt>,
+ * <tt>WikiPageEvent.POST_SAVE_BEGIN</tt>, and <tt>WikiPageEvent.POST_SAVE_END</tt>.
+ * </small></p>
+ * <p id="ipeTypes"><small><b>in-phase event types:</b>
+ * <tt>WikiPageEvent.PRE_TRANSLATE</tt>, <tt>WikiPageEvent.POST_TRANSLATE</tt>,
+ * <tt>WikiPageEvent.PRE_SAVE</tt>, and <tt>WikiPageEvent.POST_SAVE</tt>.
+ * </small></p>
+ *
+ * <p>
+ * <b>Note:</b> The <i>Actually Attached To</i> column may also be considered as the
+ * class(es) that fire events of the type(s) shown in the <i>WikiEvent Type</i> column.
+ * </p>
+ *
+ * @see com.ecyrd.jspwiki.event.WikiEvent
+ * @see com.ecyrd.jspwiki.event.WikiEngineEvent
+ * @see com.ecyrd.jspwiki.event.WikiPageEvent
+ * @see com.ecyrd.jspwiki.event.WikiSecurityEvent
+ * @throws ClassCastException if there is a type mismatch between certain event types and the client Object
+ */
+ public static synchronized void addWikiEventListener(
+ Object client, int type, WikiEventListener listener )
+ {
+ // Make sure WikiEventManager exists
+ WikiEventManager.getInstance();
+
+ // first, figure out what kind of event is expected to be generated this does
+ // tie us into known types, but WikiEvent.isValidType() will return true so
+ // long as the type was set to any non-ERROR or non-UNKNOWN value
+
+ if ( WikiEngineEvent.isValidType(type) ) // add listener directly to WikiEngine
+ {
+ WikiEventManager.addWikiEventListener( client, listener );
+ }
+ else if ( WikiPageEvent.isValidType(type) ) // add listener to one of several options
+ {
+ if( type == WikiPageEvent.PAGE_LOCK
+ || type == WikiPageEvent.PAGE_UNLOCK ) // attach to PageManager
+ {
+ if( client instanceof WikiEngine )
+ {
+ WikiEventManager.addWikiEventListener( ((WikiEngine)client).getPageManager(), listener );
+ }
+ else // if ( client instanceof PageManager ) // no filter?
+ {
+ WikiEventManager.addWikiEventListener( client, listener );
+ }
+ }
+ else if( type == WikiPageEvent.PAGE_REQUESTED
+ || type == WikiPageEvent.PAGE_DELIVERED ) // attach directly to WikiServletFilter
+ {
+ WikiEventManager.addWikiEventListener( client, listener );
+ }
+ else if( type == WikiPageEvent.PRE_TRANSLATE_BEGIN
+ || type == WikiPageEvent.PRE_TRANSLATE_END
+ || type == WikiPageEvent.POST_TRANSLATE_BEGIN
+ || type == WikiPageEvent.POST_TRANSLATE_END
+ || type == WikiPageEvent.PRE_SAVE_BEGIN
+ || type == WikiPageEvent.PRE_SAVE_END
+ || type == WikiPageEvent.POST_SAVE_BEGIN
+ || type == WikiPageEvent.POST_SAVE_END ) // attach to FilterManager
+ {
+ WikiEventManager.addWikiEventListener( ((WikiEngine)client).getFilterManager(), listener );
+ }
+ else //if ( type == WikiPageEvent.PRE_TRANSLATE
+ // || type == WikiPageEvent.POST_TRANSLATE
+ // || type == WikiPageEvent.PRE_SAVE
+ // || type == WikiPageEvent.POST_SAVE ) // attach to client
+ {
+ WikiEventManager.addWikiEventListener( client, listener );
+ }
+ }
+ else if( WikiSecurityEvent.isValidType(type) ) // add listener to the client
+ {
+ // currently just attach it to the client (we are ignorant of other options)
+ WikiEventManager.addWikiEventListener( client, listener );
+ }
+ else if( WikiEvent.isValidType(type) ) // we don't know what to do
+ {
+ WikiEventManager.addWikiEventListener( client, listener );
+ }
+ else // is error or unknown
+ {
+ // why are we being called with this?
+ }
+ }
+
+} // end com.ecyrd.jspwiki.event.WikiEventUtils
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageEvent.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageEvent.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageEvent.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageEvent.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,296 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2006 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package com.ecyrd.jspwiki.event;
+
+
+/**
+ * WikiPageEvent indicates a change in the state or processing of a WikiPage.
+ * There are basically two types of page events:
+ * <dl>
+ * <dt><b>Phase Boundary Events</b></dt>
+ * <dd>Those considered as "beginning-of-phase", and those as "end-of-phase"
+ * events (as designated by <tt>*_BEGIN</tt> and <tt>*_END</tt>), as
+ * generated by the WikiEngine. The phases include pre-save, post-save,
+ * pre-translate, and post-translate.
+ * </dd>
+ * <dt><b>In-Phase Events</b></dt>
+ * <dd>In-phase events are generated as specific events from the
+ * PageEventFilter (or elsewhere), on a per-listener basis. There may
+ * be many such events during a particular phase.
+ * </dd>
+ * </dl>
+ * <p>
+ * E.g., a typical event sequence for the pre-translate phase would be:
+ * </p>
+ * <ol>
+ * <li>PRE_TRANSLATE_BEGIN</li>
+ * <li>PRE_TRANSLATE</li>
+ * <li>PRE_TRANSLATE</li>
+ * <li>...</li>
+ * <li>PRE_TRANSLATE_END</li>
+ * </ol>
+ *
+ * <h2>Notes</h2>
+ *
+ * <h3>Page Requested and Delivered Events</h3>
+ * <p>
+ * These two events are fired once per page request, at the beginning
+ * and after delivery of the page (respectively). They are generated
+ * by the {@link com.ecyrd.jspwiki.ui.WikiServletFilter}.
+ * </p>
+ *
+ * <h3>Page Lock and Unlock Events</h3>
+ * <p>
+ * Page lock and unlock events occur only once during an editing session,
+ * so there are no begin and end events. They are generated
+ * by the {@link com.ecyrd.jspwiki.PageManager}.
+ * </p>
+ *
+ * <h3>WikiPageEvents</h3>
+ * <p>
+ * Other WikiPageEvents include both <i>phase boundary</i> and <i>in-phase</i>
+ * events for saving, pre- and post-translating content. These are very noisy
+ * event types, but are not fired unless a listener is available. They are
+ * generated by the {@link com.ecyrd.jspwiki.filters.FilterManager},
+ * {@link com.ecyrd.jspwiki.event.PageEventFilter}, and potentially other
+ * implementing classes.
+ * </p>
+ *
+ * <h3>Firing Order and Phase Boundaries</h3>
+ * <p>
+ * Note that due to the asynchronous nature of event processing, any threads
+ * spawned by such events will not necessarily have completed during their
+ * specific phase; we can assume only that no more events of that phase will
+ * be fired after its <tt>*_END</tt> event has been fired.
+ * </p>
+ *
+ * @author Murray Altheim
+ * @see com.ecyrd.jspwiki.event.WikiEvent
+ * @since 2.4.20
+ */
+public class WikiPageEvent extends WikiEvent
+{
+ // PAGE LOCKING EVENTS ...
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Indicates a page lock event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.PageManager}. */
+ public static final int PAGE_LOCK = 10;
+
+ /** Indicates a page unlock event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.PageManager}. */
+ public static final int PAGE_UNLOCK = 11;
+
+ // PRE_TRANSLATE .........
+
+ /** Indicates the beginning of all wiki pre-translate page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int PRE_TRANSLATE_BEGIN = 12;
+
+ /** Indicates a wiki pre-translate page event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.event.PageEventFilter}. */
+ public static final int PRE_TRANSLATE = 13;
+
+ /** Indicates the end of all wiki pre-translate page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int PRE_TRANSLATE_END = 14;
+
+ // POST_TRANSLATE ........
+
+ /** Indicates the beginning of all wiki post-translate page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int POST_TRANSLATE_BEGIN = 15;
+
+ /** Indicates a wiki post-translate page event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.event.PageEventFilter}. */
+ public static final int POST_TRANSLATE = 16;
+
+ /** Indicates the end of all wiki post-translate page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int POST_TRANSLATE_END = 17;
+
+ // PRE_SAVE ..............
+
+ /** Indicates the beginning of all wiki pre-save page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int PRE_SAVE_BEGIN = 18;
+
+ /** Indicates a wiki pre-save page event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.event.PageEventFilter}. */
+ public static final int PRE_SAVE = 19;
+
+ /** Indicates the end of all wiki pre-save page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int PRE_SAVE_END = 20;
+
+ // POST_SAVE .............
+
+ /** Indicates the beginning of all wiki post-save page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int POST_SAVE_BEGIN = 21;
+
+ /** Indicates a wiki post-save page event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.event.PageEventFilter}. */
+ public static final int POST_SAVE = 22;
+
+ /** Indicates the end of all wiki post-save page events. This is based
+ * on events generated by {@link com.ecyrd.jspwiki.filters.FilterManager}. */
+ public static final int POST_SAVE_END = 23;
+
+ // PAGE REQUESTS .........
+
+ /** Indicates a wiki page request event (the start of a request). This is based
+ * on events generated by {@link com.ecyrd.jspwiki.ui.WikiServletFilter}. */
+ public static final int PAGE_REQUESTED = 24;
+
+ /** Indicates a wiki page delivery event (the end of a request). This is based
+ * on events generated by {@link com.ecyrd.jspwiki.ui.WikiServletFilter}. */
+ public static final int PAGE_DELIVERED = 25;
+
+ /** Indicates a wiki page delete event (the beginning of a delete request).
+ * This is based on events generated by {@link com.ecyrd.jspwiki.ui.WikiServletFilter}.
+ * @since 2.4.65 */
+ public static final int PAGE_DELETE_REQUEST = 26;
+
+ /** Indicates a wiki page deleted event (after the delete has been completed).
+ * This is based on events generated by {@link com.ecyrd.jspwiki.ui.WikiServletFilter}.
+ * @since 2.4.65 */
+ public static final int PAGE_DELETED = 27;
+
+ private String m_pagename = null;
+
+ // ............
+
+
+ /**
+ * Constructs an instance of this event.
+ * @param src the Object that is the source of the event.
+ * @param type the type of the event (see the enumerated int values defined
+ * in {@link com.ecyrd.jspwiki.event.WikiEvent}).
+ * @param pagename the WikiPage being acted upon.
+ */
+ public WikiPageEvent( Object src, int type, String pagename )
+ {
+ super( src, type );
+ m_pagename = pagename;
+ }
+
+
+ /**
+ * Returns the Wiki page name associated with this event.
+ * This may be null if unavailable.
+ *
+ * @return the Wiki page name associated with this WikiEvent, or null.
+ */
+ public String getPageName()
+ {
+ return m_pagename;
+ }
+
+
+ /**
+ * Returns true if the int value is a WikiPageEvent type.
+ */
+ public static boolean isValidType( int type )
+ {
+ return type >= PAGE_LOCK && type <= PAGE_DELETED;
+ }
+
+
+ /**
+ * Returns a textual representation of the event type.
+ * @return a String representation of the type
+ */
+ public String eventName()
+ {
+ switch ( getType() )
+ {
+ case PAGE_LOCK: return "PAGE_LOCK";
+ case PAGE_UNLOCK: return "PAGE_UNLOCK";
+
+ case PRE_TRANSLATE_BEGIN: return "PRE_TRANSLATE_BEGIN";
+ case PRE_TRANSLATE: return "PRE_TRANSLATE";
+ case PRE_TRANSLATE_END: return "PRE_TRANSLATE_END";
+
+ case POST_TRANSLATE_BEGIN: return "POST_TRANSLATE_BEGIN";
+ case POST_TRANSLATE: return "POST_TRANSLATE";
+ case POST_TRANSLATE_END: return "POST_TRANSLATE_END";
+
+ case PRE_SAVE_BEGIN: return "PRE_SAVE_BEGIN";
+ case PRE_SAVE: return "PRE_SAVE";
+ case PRE_SAVE_END: return "PRE_SAVE_END";
+
+ case POST_SAVE_BEGIN: return "POST_SAVE_BEGIN";
+ case POST_SAVE: return "POST_SAVE";
+ case POST_SAVE_END: return "POST_SAVE_END";
+
+ case PAGE_REQUESTED: return "PAGE_REQUESTED";
+ case PAGE_DELIVERED: return "PAGE_DELIVERED";
+
+ case PAGE_DELETE_REQUEST: return "PAGE_DELETE_REQUEST";
+ case PAGE_DELETED: return "PAGE_DELETED";
+
+ default: return super.eventName();
+ }
+ }
+
+
+ /** Returns a human-readable description of the event type.
+ * @return a String description of the type
+ */
+ public String getTypeDescription()
+ {
+ switch ( getType() )
+ {
+ case PAGE_LOCK: return "page lock event";
+ case PAGE_UNLOCK: return "page unlock event";
+
+ case PRE_TRANSLATE_BEGIN: return "begin page pre-translate events";
+ case PRE_TRANSLATE: return "page pre-translate event";
+ case PRE_TRANSLATE_END: return "end of page pre-translate events";
+
+ case POST_TRANSLATE_BEGIN: return "begin page post-translate events";
+ case POST_TRANSLATE: return "page post-translate event";
+ case POST_TRANSLATE_END: return "end of page post-translate events";
+
+ case PRE_SAVE_BEGIN: return "begin page pre-save events";
+ case PRE_SAVE: return "page pre-save event";
+ case PRE_SAVE_END: return "end of page pre-save events";
+
+ case POST_SAVE_BEGIN: return "begin page post-save events";
+ case POST_SAVE: return "page post-save event";
+ case POST_SAVE_END: return "end of page post-save events";
+
+ case PAGE_REQUESTED: return "page requested event";
+ case PAGE_DELIVERED: return "page delivered event";
+
+ case PAGE_DELETE_REQUEST: return "page delete request event";
+ case PAGE_DELETED: return "page deleted event";
+
+ default: return super.getTypeDescription();
+ }
+ }
+
+} // end class com.ecyrd.jspwiki.event.WikiPageEvent
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageRenameEvent.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageRenameEvent.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageRenameEvent.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiPageRenameEvent.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,123 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2006 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package com.ecyrd.jspwiki.event;
+
+/**
+ * WikiPageRenameEvent extends WikiPageEvent to indicate a change in
+ * the name of a WikiPage.
+ * <p>
+ * This reuses {@link #getPageName()} to return the new name of the
+ * page, with {@link #getOldPageName()} returning the old name.
+ *
+ * @author Murray Altheim
+ * @see com.ecyrd.jspwiki.event.WikiPageEvent
+ * @since 2.5.108
+ */
+public class WikiPageRenameEvent extends WikiPageEvent
+{
+ private static final long serialVersionUID = 1L;
+
+ /** Indicates a page rename event. This is based on events
+ * generated by {@link com.ecyrd.jspwiki.PageRenamer}. */
+ public static final int PAGE_RENAMED = 28;
+
+ private String m_oldpagename = null;
+
+ // ............
+
+
+ /**
+ * Constructs an instance of this event.
+ *
+ * @param src the Object that is the source of the event.
+ * @param oldname the old name of the WikiPage being acted upon.
+ * @param newname the new name of the WikiPage being acted upon.
+ */
+ public WikiPageRenameEvent( Object src, String oldname, String newname )
+ {
+ super( src, PAGE_RENAMED, newname );
+ m_oldpagename = oldname;
+ }
+
+
+ /**
+ * Returns the old Wiki page name associated with this event.
+ * This may be null if unavailable.
+ *
+ * @return the old Wiki page name associated with this WikiEvent, or null.
+ */
+ public String getOldPageName()
+ {
+ return m_oldpagename;
+ }
+
+
+ /**
+ * Returns the new Wiki page name associated with this event. This
+ * returns the same value as the superclass' {@link #getPageName()}.
+ * This may be null if unavailable.
+ *
+ * @return the new Wiki page name associated with this WikiEvent, or null.
+ */
+ public String getNewPageName()
+ {
+ return super.getPageName();
+ }
+
+
+ /**
+ * Returns true if the int value is a WikiPageRenameEvent type.
+ */
+ public static boolean isValidType( int type )
+ {
+ return type >= PAGE_LOCK && type <= PAGE_RENAMED;
+ }
+
+
+ /**
+ * Returns a textual representation of the event type.
+ * @return a String representation of the type
+ */
+ public String eventName()
+ {
+ return "PAGE_RENAMED";
+ // switch ( getType() )
+ // {
+ // case PAGE_RENAMED: return "PAGE_RENAMED";
+ // default: return super.eventName();
+ // }
+ }
+
+
+ /** Returns a human-readable description of the event type.
+ * @return a String description of the type
+ */
+ public String getTypeDescription()
+ {
+ return "page renamed event";
+ // switch ( getType() )
+ // {
+ // case PAGE_RENAMED: return "page renamed event";
+ // default: return super.getTypeDescription();
+ // }
+ }
+
+} // end class com.ecyrd.jspwiki.event.WikiPageRenameEvent
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiSecurityEvent.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiSecurityEvent.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiSecurityEvent.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WikiSecurityEvent.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,275 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.event;
+
+import java.security.Principal;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.event.WikiEvent;
+
+/**
+ * <p>Event class for security events: login/logout, wiki group adds/changes, and
+ * authorization decisions. When a WikiSecurityEvent is constructed, the
+ * security logger {@link #log} is notified.</p>
+ * <p>These events are logged with priority <code>ERROR</code>:</p>
+ * <ul>
+ * <li>login failed - bad credential or password</li>
+ * </ul>
+ * <p>These events are logged with priority <code>WARN</code>:</p>
+ * <ul>
+ * <li>access denied</li>
+ * <li>login failed - credential expired</li>
+ * <li>login failed - account expired</li>
+ * </ul>
+ * <p>These events are logged with priority <code>INFO</code>:</p>
+ * <ul>
+ * <li>login succeeded</li>
+ * <li>logout</li>
+ * <li>user profile name changed</li>
+ * </ul>
+ * <p>These events are logged with priority <code>DEBUG</code>:</p>
+ * <ul>
+ * <li>access allowed</li>
+ * <li>add group</li>
+ * <li>remove group</li>
+ * <li>clear all groups</li>
+ * <li>add group member</li>
+ * <li>remove group member</li>
+ * <li>clear all members from group</li>
+ * </ul>
+ * @author Andrew Jaquith
+ * @since 2.3.79
+ */
+public final class WikiSecurityEvent extends WikiEvent
+{
+
+ private static final long serialVersionUID = -6751950399721334496L;
+
+ /** When a user's attempts to log in as guest, via cookies, using a password or otherwise. */
+ public static final int LOGIN_INITIATED = 30;
+
+ /** When a user first accesses JSPWiki, but before logging in or setting a cookie. */
+ public static final int LOGIN_ANONYMOUS = 31;
+
+ /** When a user sets a cookie to assert their identity. */
+ public static final int LOGIN_ASSERTED = 32;
+
+ /** When a user authenticates with a username and password, or via container auth. */
+ public static final int LOGIN_AUTHENTICATED = 40;
+
+ /** When a login fails due to account expiration. */
+ public static final int LOGIN_ACCOUNT_EXPIRED = 41;
+
+ /** When a login fails due to credential expiration. */
+ public static final int LOGIN_CREDENTIAL_EXPIRED = 42;
+
+ /** When a login fails due to wrong username or password. */
+ public static final int LOGIN_FAILED = 43;
+
+ /** When a user logs out. */
+ public static final int LOGOUT = 44;
+
+ /** When a session expires. */
+ public static final int SESSION_EXPIRED = 45;
+
+ /** When a new wiki group is added. */
+ public static final int GROUP_ADD = 46;
+
+ /** When a wiki group is deleted. */
+ public static final int GROUP_REMOVE = 47;
+
+ /** When all wiki groups are removed from GroupDatabase. */
+ public static final int GROUP_CLEAR_GROUPS = 48;
+
+ /** When access to a resource is allowed. */
+ public static final int ACCESS_ALLOWED = 51;
+
+ /** When access to a resource is allowed. */
+ public static final int ACCESS_DENIED = 52;
+
+ /** When a user profile is saved. */
+ public static final int PROFILE_SAVE = 53;
+
+ /** When a user profile name changes. */
+ public static final int PROFILE_NAME_CHANGED = 54;
+
+ /** The security logging service. */
+ protected static final Logger log = Logger.getLogger( "SecurityLog" );
+
+ private final Principal m_principal;
+
+ private final Object m_target;
+
+ private static final int[] ERROR_EVENTS = { LOGIN_FAILED };
+
+ private static final int[] WARN_EVENTS = { LOGIN_ACCOUNT_EXPIRED,
+ LOGIN_CREDENTIAL_EXPIRED };
+
+ private static final int[] INFO_EVENTS = { LOGIN_AUTHENTICATED,
+ SESSION_EXPIRED, LOGOUT, PROFILE_NAME_CHANGED };
+
+ /**
+ * Constructs a new instance of this event type, which signals a security
+ * event has occurred. The <code>source</code> parameter is required, and
+ * may not be <code>null</code>. When the WikiSecurityEvent is
+ * constructed, the security logger {@link #log} is notified.
+ * @param src the source of the event, which can be any object: a wiki
+ * page, group or authentication/authentication/group manager.
+ * @param type the type of event
+ * @param principal the subject of the event, which may be <code>null</code>
+ * @param target the changed Object, which may be <code>null</code>
+ */
+ public WikiSecurityEvent( Object src, int type, Principal principal, Object target )
+ {
+ super( src, type );
+ if ( src == null )
+ {
+ throw new IllegalArgumentException( "Argument(s) cannot be null." );
+ }
+ this.m_principal = principal;
+ this.m_target = target;
+ if ( log.isEnabledFor( Level.ERROR ) && ArrayUtils.contains( ERROR_EVENTS, type ) )
+ {
+ log.error( this );
+ }
+ else if ( log.isEnabledFor( Level.WARN ) && ArrayUtils.contains( WARN_EVENTS, type ) )
+ {
+ log.warn( this );
+ }
+ else if ( log.isEnabledFor( Level.INFO ) && ArrayUtils.contains( INFO_EVENTS, type ) )
+ {
+ log.info( this );
+ }
+ log.debug( this );
+ }
+
+ /**
+ * Constructs a new instance of this event type, which signals a security
+ * event has occurred. The <code>source</code> parameter is required, and
+ * may not be <code>null</code>. When the WikiSecurityEvent is
+ * constructed, the security logger {@link #log} is notified.
+ * @param src the source of the event, which can be any object: a wiki
+ * page, group or authentication/authentication/group manager.
+ * @param type the type of event
+ * @param target the changed Object, which may be <code>null</code>.
+ */
+ public WikiSecurityEvent( Object src, int type, Object target )
+ {
+ this( src, type, null, target );
+ }
+
+ /**
+ * Returns the principal to whom the opeation applied, if supplied. This
+ * method may return <code>null</code>
+ * <em>— and calling methods should check for this condition</em>.
+ * @return the changed object
+ */
+ public final Object getPrincipal()
+ {
+ return m_principal;
+ }
+
+ /**
+ * Returns the object that was operated on, if supplied. This method may
+ * return <code>null</code>
+ * <em>— and calling methods should check for this condition</em>.
+ * @return the changed object
+ */
+ public final Object getTarget()
+ {
+ return m_target;
+ }
+
+ /**
+ * Prints a String (human-readable) representation of this object.
+ * @see java.lang.Object#toString()
+ */
+ public final String toString()
+ {
+ StringBuffer msg = new StringBuffer();
+ msg.append( "WikiSecurityEvent." );
+ msg.append( eventName( getType() ) );
+ msg.append( " [source=" + getSource().toString() );
+ if( m_principal != null )
+ {
+ msg.append( ", princpal=" + m_principal.getClass().getName() );
+ msg.append( " " + m_principal.getName() );
+ }
+ msg.append( ", target=" + m_target );
+ msg.append( "]" );
+ return msg.toString();
+ }
+
+ /**
+ * Returns a textual representation of an event type.
+ * @param type the type
+ * @return the string representation
+ */
+ public final String eventName( int type )
+ {
+ switch( type )
+ {
+ case LOGIN_AUTHENTICATED: return "LOGIN_AUTHENTICATED";
+ case LOGIN_ACCOUNT_EXPIRED: return "LOGIN_ACCOUNT_EXPIRED";
+ case LOGIN_CREDENTIAL_EXPIRED: return "LOGIN_ACCOUNT_EXPIRED";
+ case LOGIN_FAILED: return "LOGIN_FAILED";
+ case LOGOUT: return "LOGOUT";
+ case SESSION_EXPIRED: return "SESSION_EXPIRED";
+ case GROUP_ADD: return "GROUP_ADD";
+ case GROUP_REMOVE: return "GROUP_REMOVE";
+ case GROUP_CLEAR_GROUPS: return "GROUP_CLEAR_GROUPS";
+ case ACCESS_ALLOWED: return "ACCESS_ALLOWED";
+ case ACCESS_DENIED: return "ACCESS_DENIED";
+ case PROFILE_NAME_CHANGED: return "PROFILE_NAME_CHANGED";
+ case PROFILE_SAVE: return "PROFILE_SAVE";
+ default: return super.eventName();
+ }
+ }
+
+ /**
+ * Returns a human-readable description of the event type.
+ *
+ * @return a String description of the type
+ */
+ public final String getTypeDescription()
+ {
+ switch ( getType() )
+ {
+ case LOGIN_AUTHENTICATED: return "login authenticated";
+ case LOGIN_ACCOUNT_EXPIRED: return "login failed: expired account";
+ case LOGIN_CREDENTIAL_EXPIRED: return "login failed: credential expired";
+ case LOGIN_FAILED: return "login failed";
+ case LOGOUT: return "user logged out";
+ case SESSION_EXPIRED: return "session expired";
+ case GROUP_ADD: return "new group added";
+ case GROUP_REMOVE: return "group removed";
+ case GROUP_CLEAR_GROUPS: return "all groups cleared";
+ case ACCESS_ALLOWED: return "access allowed";
+ case ACCESS_DENIED: return "access denied";
+ case PROFILE_NAME_CHANGED: return "user profile name changed";
+ case PROFILE_SAVE: return "user profile saved";
+ default: return super.getTypeDescription();
+ }
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WorkflowEvent.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WorkflowEvent.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WorkflowEvent.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/event/WorkflowEvent.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,145 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2006 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package com.ecyrd.jspwiki.event;
+
+import com.ecyrd.jspwiki.workflow.Workflow;
+
+/**
+ * <p>
+ * WorkflowEvent indicates that a state change to a Workflow: started, running,
+ * waiting, completed, aborted. These correspond exactly to the states described
+ * in the {@link com.ecyrd.jspwiki.workflow.Workflow}. All events are logged
+ * with priority INFO.
+ * </p>
+ *
+ * @author Andrew Jaquith
+ * @since 2.3.79
+ */
+public final class WorkflowEvent extends WikiEvent
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * After Workflow instantiation.
+ */
+ public static final int CREATED = 0;
+
+ /**
+ * After the Workflow has been instantiated, but before it has been started
+ * using the {@link com.ecyrd.jspwiki.workflow.Workflow#start()} method.
+ */
+ public static final int STARTED = 10;
+
+ /**
+ * fter the Workflow has been started (or re-started) using the
+ * {@link com.ecyrd.jspwiki.workflow.Workflow#start()} method,
+ * but before it has finished processing all Steps.
+ */
+ public static final int RUNNING = 20;
+
+ /**
+ * When the Workflow has temporarily paused, for example because of a
+ * pending Decision.
+ */
+ public static final int WAITING = 30;
+
+ /** After the Workflow has finished processing all Steps, without errors. */
+ public static final int COMPLETED = 40;
+
+ /** If a Step has elected to abort the Workflow. */
+ public static final int ABORTED = 50;
+
+ /**
+ * Constructs a new instance of this event type, which signals a security
+ * event has occurred. The <code>source</code> parameter is required, and
+ * may not be <code>null</code>. When the WikiSecurityEvent is
+ * constructed, the security logger {@link WikiSecurityEvent#log} is notified.
+ *
+ * @param src
+ * the source of the event, which can be any object: a wiki page,
+ * group or authentication/authentication/group manager.
+ * @param type
+ * the type of event
+ */
+ public WorkflowEvent(Object src, int type)
+ {
+ super(src, type);
+ if (src == null)
+ {
+ throw new IllegalArgumentException("Argument(s) cannot be null.");
+ }
+ }
+
+ /**
+ * Convenience method that returns the Workflow to which the event applied.
+ *
+ * @return the Workflow
+ */
+ public final Workflow getWorkflow()
+ {
+ return (Workflow) super.getSource();
+ }
+
+ /**
+ * Prints a String (human-readable) representation of this object.
+ *
+ * @see java.lang.Object#toString()
+ */
+ public final String toString()
+ {
+ StringBuffer msg = new StringBuffer();
+ msg.append("WorkflowEvent.");
+ msg.append(eventName(getType()));
+ msg.append(" [source=" + getSource().toString());
+ msg.append("]");
+ return msg.toString();
+ }
+
+ /**
+ * Returns a textual representation of an event type.
+ *
+ * @param type
+ * the type
+ * @return the string representation
+ */
+ public final String eventName(int type)
+ {
+ switch (type)
+ {
+ case CREATED:
+ return "CREATED";
+ case ABORTED:
+ return "ABORTED";
+ case COMPLETED:
+ return "COMPLETED";
+ case RUNNING:
+ return "RUNNING";
+ case STARTED:
+ return "STARTED";
+ case WAITING:
+ return "WAITING";
+ default:
+ return super.eventName();
+ }
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/BasicPageFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/BasicPageFilter.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/BasicPageFilter.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/BasicPageFilter.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,74 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+
+/**
+ * Provides a base implementation of a PageFilter. None of the callbacks
+ * do anything, so it is a good idea for you to extend from this class
+ * and implement only methods that you need.
+ *
+ * @author Janne Jalkanen
+ */
+public class BasicPageFilter
+ implements PageFilter
+{
+ protected WikiEngine m_engine;
+
+ /**
+ * If you override this, you should call super.initialize() first.
+ */
+ public void initialize( WikiEngine engine, Properties properties )
+ throws FilterException
+ {
+ m_engine = engine;
+ }
+
+ public String preTranslate( WikiContext wikiContext, String content )
+ throws FilterException
+ {
+ return content;
+ }
+
+ public String postTranslate( WikiContext wikiContext, String htmlContent )
+ throws FilterException
+ {
+ return htmlContent;
+ }
+
+ public String preSave( WikiContext wikiContext, String content )
+ throws FilterException
+ {
+ return content;
+ }
+
+ public void postSave( WikiContext wikiContext, String content )
+ throws FilterException
+ {
+ }
+
+ public void destroy( WikiEngine engine )
+ {
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/CreoleFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/CreoleFilter.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/CreoleFilter.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/CreoleFilter.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,106 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.filters.BasicPageFilter;
+import com.ecyrd.jspwiki.filters.FilterException;
+import com.ecyrd.jspwiki.parser.CreoleToJSPWikiTranslator;
+
+/**
+ * <p>Provides the Implementation for mixed mode creole: If you activate
+ * this filter, it will translate all markup that was saved as creole
+ * markup to JSPWiki markup. Therefore the files will be saved
+ * with mixed markup.
+ * <p>
+ * <b>WARNING</b>: There's no turning back after insalling this
+ * filter. Since your wiki pages are saved in Creole markup you can
+ * not deactivate it afterwards.
+ * <p>
+ * <b>WARNING</b>: This feature is completely experimental, and is known to be
+ * broken. Use at your own risk.
+ * <p>
+ * <b>WARNING</b>: The CreoleFilter feature is deprecated. JSPWiki is likely
+ * to implement a non-mixed mode Creole at some point, since turning on
+ * Creole will make new pages obsolete.
+ *
+ * @author Steffen Schramm
+ * @author Hanno Eichelberger
+ * @author Christoph Sauer
+ *
+ * @see <a href="http://www.wikicreole.org/wiki/MixedMode">[[WikiCreole:MixedMode]]</a>
+ */
+
+public class CreoleFilter extends BasicPageFilter
+{
+ /**
+ * {@inheritDoc}
+ */
+ public void initialize(WikiEngine engine, Properties props) throws FilterException
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String preSave( WikiContext wikiContext, String content )
+ throws FilterException
+ {
+ try
+ {
+ String username=wikiContext.getCurrentUser().getName();
+ Properties prop = wikiContext.getEngine().getWikiProperties();
+ return new CreoleToJSPWikiTranslator().translateSignature(prop, content,username);
+ }
+ catch(Exception e )
+ {
+ e.printStackTrace();
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+
+ public String preTranslate(WikiContext wikiContext, String content)
+ throws FilterException
+ {
+ try
+ {
+ Properties prop = wikiContext.getEngine().getWikiProperties();
+ return new CreoleToJSPWikiTranslator().translate(prop ,content);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return content
+ + "\n \n %%error \n"
+ + "[CreoleFilterError]: This page was not translated by the CreoleFilter due to "
+ + "the following error: " + e.getMessage() + "\n \n"
+ + "%%\n \n";
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterException.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterException.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterException.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,38 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2003 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import com.ecyrd.jspwiki.WikiException;
+
+/**
+ * A generic PageFilter exception.
+ *
+ * @since 2.1.112
+ */
+public class FilterException
+ extends WikiException
+{
+ private static final long serialVersionUID = 0L;
+
+ public FilterException( String msg )
+ {
+ super( msg );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterManager.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterManager.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/FilterManager.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,495 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2003 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.File;
+import java.net.URL;
+import java.util.*;
+
+import org.apache.log4j.Logger;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.xpath.XPath;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiException;
+import com.ecyrd.jspwiki.event.WikiEventManager;
+import com.ecyrd.jspwiki.event.WikiPageEvent;
+import com.ecyrd.jspwiki.modules.ModuleManager;
+import com.ecyrd.jspwiki.modules.WikiModuleInfo;
+import com.ecyrd.jspwiki.plugin.PluginManager.WikiPluginInfo;
+
+import com.ecyrd.jspwiki.util.PriorityList;
+import com.ecyrd.jspwiki.util.ClassUtil;
+
+
+/**
+ * Manages the page filters. Page filters are components that can be executed
+ * at certain places:
+ * <ul>
+ * <li>Before the page is translated into HTML.
+ * <li>After the page has been translated into HTML.
+ * <li>Before the page is saved.
+ * <li>After the page has been saved.
+ * </ul>
+ *
+ * Using page filters allows you to modify the page data on-the-fly, and do things like
+ * adding your own custom WikiMarkup.
+ *
+ * <p>
+ * The initial page filter configuration is kept in a file called "filters.xml". The
+ * format is really very simple:
+ * <pre>
+ * <?xml version="1.0"?>
+ *
+ * <pagefilters>
+ *
+ * <filter>
+ * <class>com.ecyrd.jspwiki.filters.ProfanityFilter</class>
+ * </filter>
+ *
+ * <filter>
+ * <class>com.ecyrd.jspwiki.filters.TestFilter</class>
+ *
+ * <param>
+ * <name>foobar</name>
+ * <value>Zippadippadai</value>
+ * </param>
+ *
+ * <param>
+ * <name>blatblaa</name>
+ * <value>5</value>
+ * </param>
+ *
+ * </filter>
+ * </pagefilters>
+ * </pre>
+ *
+ * The <filter> -sections define the filters. For more information, please see
+ * the PageFilterConfiguration page in the JSPWiki distribution.
+ *
+ * @author Janne Jalkanen
+ */
+public final class FilterManager extends ModuleManager
+{
+ private PriorityList m_pageFilters = new PriorityList();
+
+ private HashMap m_filterClassMap = new HashMap();
+
+ private static final Logger log = Logger.getLogger(WikiEngine.class);
+
+ public static final String PROP_FILTERXML = "jspwiki.filterConfig";
+
+ public static final String DEFAULT_XMLFILE = "/WEB-INF/filters.xml";
+
+ /** JSPWiki system filters are all below this value. */
+ public static final int SYSTEM_FILTER_PRIORITY = -1000;
+
+ /** The standard user level filtering. */
+ public static final int USER_FILTER_PRIORITY = 0;
+
+ public FilterManager( WikiEngine engine, Properties props )
+ throws WikiException
+ {
+ super( engine );
+ initialize( props );
+ }
+
+ /**
+ * Adds a page filter to the queue. The priority defines in which
+ * order the page filters are run, the highest priority filters go
+ * in the queue first.
+ * <p>
+ * In case two filters have the same priority, their execution order
+ * is the insertion order.
+ *
+ * @since 2.1.44.
+ * @param f PageFilter to add
+ * @param priority The priority in which position to add it in.
+ * @throws IllegalArgumentException If the PageFilter is null or invalid.
+ */
+ public void addPageFilter( PageFilter f, int priority )
+ {
+ if( f == null )
+ {
+ throw new IllegalArgumentException("Attempt to provide a null filter - this should never happen. Please check your configuration (or if you're a developer, check your own code.)");
+ }
+
+ m_pageFilters.add( f, priority );
+ }
+
+ private void initPageFilter( String className, Properties props )
+ {
+ try
+ {
+ PageFilterInfo info = (PageFilterInfo)m_filterClassMap.get( className );
+
+ if( info != null && !checkCompatibility(info) )
+ {
+ String msg = "Filter '"+info.getName()+"' not compatible with this version of JSPWiki";
+ log.warn(msg);
+ return;
+ }
+
+ int priority = 0; // FIXME: Currently fixed.
+
+ Class cl = ClassUtil.findClass( "com.ecyrd.jspwiki.filters",
+ className );
+
+ PageFilter filter = (PageFilter)cl.newInstance();
+
+ filter.initialize( m_engine, props );
+
+ addPageFilter( filter, priority );
+ log.info("Added page filter "+cl.getName()+" with priority "+priority);
+ }
+ catch( ClassNotFoundException e )
+ {
+ log.error("Unable to find the filter class: "+className);
+ }
+ catch( InstantiationException e )
+ {
+ log.error("Cannot create filter class: "+className);
+ }
+ catch( IllegalAccessException e )
+ {
+ log.error("You are not allowed to access class: "+className);
+ }
+ catch( ClassCastException e )
+ {
+ log.error("Suggested class is not a PageFilter: "+className);
+ }
+ catch( FilterException e )
+ {
+ log.error("Filter "+className+" failed to initialize itself.", e);
+ }
+ }
+
+
+ /**
+ * Initializes the filters from an XML file.
+ */
+ protected void initialize( Properties props )
+ throws WikiException
+ {
+ InputStream xmlStream = null;
+ String xmlFile = props.getProperty( PROP_FILTERXML );
+
+ try
+ {
+ registerFilters();
+
+ if( xmlFile == null )
+ {
+ if( m_engine.getServletContext() != null )
+ {
+ log.debug("Attempting to locate "+DEFAULT_XMLFILE+" from servlet context.");
+ xmlStream = m_engine.getServletContext().getResourceAsStream( DEFAULT_XMLFILE );
+ }
+
+ if( xmlStream == null )
+ {
+ //just a fallback element to the old behaviour prior to 2.5.8
+ log.debug("Attempting to locate filters.xml from class path.");
+ xmlStream = getClass().getResourceAsStream( "/filters.xml" );
+ }
+ }
+ else
+ {
+ log.debug("Attempting to load property file "+xmlFile);
+ xmlStream = new FileInputStream( new File(xmlFile) );
+ }
+
+ if( xmlStream == null )
+ {
+ log.info("Cannot find property file for filters (this is okay, expected to find it as: '"+ (xmlFile == null ? DEFAULT_XMLFILE : xmlFile ) +"')");
+ return;
+ }
+
+ parseConfigFile( xmlStream );
+ }
+ catch( IOException e )
+ {
+ log.error("Unable to read property file", e);
+ }
+ catch( JDOMException e )
+ {
+ log.error("Problem in the XML file",e);
+ }
+ }
+
+ /**
+ * Parses the XML filters configuration file.
+ *
+ * @param xmlStream
+ * @throws JDOMException
+ * @throws IOException
+ */
+ private void parseConfigFile( InputStream xmlStream )
+ throws JDOMException,
+ IOException
+ {
+ Document doc = new SAXBuilder().build( xmlStream );
+
+ XPath xpath = XPath.newInstance("/pagefilters/filter");
+
+ List nodes = xpath.selectNodes( doc );
+
+ for( Iterator i = nodes.iterator(); i.hasNext(); )
+ {
+ Element f = (Element) i.next();
+
+ String filterClass = f.getChildText("class");
+
+ Properties props = new Properties();
+
+ List params = f.getChildren("param");
+
+ for( Iterator par = params.iterator(); par.hasNext(); )
+ {
+ Element p = (Element) par.next();
+
+ props.setProperty( p.getChildText("name"), p.getChildText("value") );
+ }
+
+ initPageFilter( filterClass, props );
+ }
+
+ }
+
+
+ /**
+ * Does the filtering before a translation.
+ */
+ public String doPreTranslateFiltering( WikiContext context, String pageData )
+ throws FilterException
+ {
+ fireEvent( WikiPageEvent.PRE_TRANSLATE_BEGIN, context );
+
+ for( Iterator i = m_pageFilters.iterator(); i.hasNext(); )
+ {
+ PageFilter f = (PageFilter) i.next();
+
+ pageData = f.preTranslate( context, pageData );
+ }
+
+ fireEvent( WikiPageEvent.PRE_TRANSLATE_END, context );
+
+ return pageData;
+ }
+
+ /**
+ * Does the filtering after HTML translation.
+ */
+ public String doPostTranslateFiltering( WikiContext context, String pageData )
+ throws FilterException
+ {
+ fireEvent( WikiPageEvent.POST_TRANSLATE_BEGIN, context );
+
+ for( Iterator i = m_pageFilters.iterator(); i.hasNext(); )
+ {
+ PageFilter f = (PageFilter) i.next();
+
+ pageData = f.postTranslate( context, pageData );
+ }
+
+ fireEvent( WikiPageEvent.POST_TRANSLATE_END, context );
+
+ return pageData;
+ }
+
+ /**
+ * Does the filtering before a save to the page repository.
+ */
+ public String doPreSaveFiltering( WikiContext context, String pageData )
+ throws FilterException
+ {
+ fireEvent( WikiPageEvent.PRE_SAVE_BEGIN, context );
+
+ for( Iterator i = m_pageFilters.iterator(); i.hasNext(); )
+ {
+ PageFilter f = (PageFilter) i.next();
+
+ pageData = f.preSave( context, pageData );
+ }
+
+ fireEvent( WikiPageEvent.PRE_SAVE_END, context );
+
+ return pageData;
+ }
+
+ /**
+ * Does the page filtering after the page has been saved.
+ */
+ public void doPostSaveFiltering( WikiContext context, String pageData )
+ throws FilterException
+ {
+ fireEvent( WikiPageEvent.POST_SAVE_BEGIN, context );
+
+ for( Iterator i = m_pageFilters.iterator(); i.hasNext(); )
+ {
+ PageFilter f = (PageFilter) i.next();
+
+ // log.info("POSTSAVE: "+f.toString() );
+ f.postSave( context, pageData );
+ }
+
+ fireEvent( WikiPageEvent.POST_SAVE_END, context );
+ }
+
+ public List getFilterList()
+ {
+ return m_pageFilters;
+ }
+
+ /**
+ *
+ * Notifies PageFilters to clean up their ressources.
+ *
+ */
+ public void destroy()
+ {
+ for( Iterator i = m_pageFilters.iterator(); i.hasNext(); )
+ {
+ PageFilter f = (PageFilter) i.next();
+
+ f.destroy( m_engine );
+ }
+ }
+
+ // events processing .......................................................
+
+ /**
+ * Fires a WikiPageEvent of the provided type and WikiContext.
+ * Invalid WikiPageEvent types are ignored.
+ *
+ * @see com.ecyrd.jspwiki.event.WikiPageEvent
+ * @param type the WikiPageEvent type to be fired.
+ * @param context the WikiContext of the event.
+ */
+ public final void fireEvent( int type, WikiContext context )
+ {
+ if ( WikiEventManager.isListening(this) && WikiPageEvent.isValidType(type) )
+ {
+ WikiEventManager.fireEvent(this,
+ new WikiPageEvent(m_engine,type,context.getPage().getName()) );
+ }
+ }
+
+ public Collection modules()
+ {
+ ArrayList modules = new ArrayList();
+
+ modules.addAll( m_pageFilters );
+
+ return modules;
+ }
+
+ private void registerFilters()
+ {
+ log.info( "Registering filters" );
+
+ SAXBuilder builder = new SAXBuilder();
+
+ try
+ {
+ //
+ // Register all filters which have created a resource containing its properties.
+ //
+ // Get all resources of all plugins.
+ //
+
+ Enumeration resources = getClass().getClassLoader().getResources( PLUGIN_RESOURCE_LOCATION );
+
+ while( resources.hasMoreElements() )
+ {
+ URL resource = (URL) resources.nextElement();
+
+ try
+ {
+ log.debug( "Processing XML: " + resource );
+
+ Document doc = builder.build( resource );
+
+ List plugins = XPath.selectNodes( doc, "/modules/filter");
+
+ for( Iterator i = plugins.iterator(); i.hasNext(); )
+ {
+ Element pluginEl = (Element) i.next();
+
+ String className = pluginEl.getAttributeValue("class");
+
+ PageFilterInfo pluginInfo = PageFilterInfo.newInstance( className, pluginEl );
+
+ if( pluginInfo != null )
+ {
+ registerPlugin( pluginInfo );
+ }
+ }
+ }
+ catch( java.io.IOException e )
+ {
+ log.error( "Couldn't load " + PLUGIN_RESOURCE_LOCATION + " resources: " + resource, e );
+ }
+ catch( JDOMException e )
+ {
+ log.error( "Error parsing XML for filter: "+PLUGIN_RESOURCE_LOCATION );
+ }
+ }
+ }
+ catch( java.io.IOException e )
+ {
+ log.error( "Couldn't load all " + PLUGIN_RESOURCE_LOCATION + " resources", e );
+ }
+ }
+
+ private void registerPlugin(PageFilterInfo pluginInfo)
+ {
+ m_filterClassMap.put( pluginInfo.getName(), pluginInfo );
+ }
+
+ /**
+ * Stores information about the filters.
+ *
+ * @since 2.6.1
+ */
+ private static class PageFilterInfo extends WikiModuleInfo
+ {
+ private PageFilterInfo( String name )
+ {
+ super(name);
+ }
+
+ protected static PageFilterInfo newInstance(String className, Element pluginEl)
+ {
+ if( className == null || className.length() == 0 ) return null;
+ PageFilterInfo info = new PageFilterInfo( className );
+
+ info.initializeFromXML( pluginEl );
+ return info;
+ }
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PageFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PageFilter.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PageFilter.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PageFilter.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,100 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+
+/**
+ * Provides a definition for a page filter. A page filter is a class
+ * that can be used to transform the WikiPage content being saved or
+ * being loaded at any given time.
+ * <p>
+ * Note that the WikiContext.getPage() method always returns the context
+ * in which text is rendered, i.e. the original request. Thus the content
+ * may actually be different content than what what the wikiContext.getPage()
+ * implies! This happens often if you are for example including multiple
+ * pages on the same page.
+ * <p>
+ * PageFilters must be thread-safe! There is only one instance of each PageFilter
+ * per each WikiEngine invocation. If you need to store data persistently, use
+ * VariableManager, or WikiContext.
+ * <p>
+ * As of 2.5.30, initialize() gains accesso to the WikiEngine.
+ *
+ * @author Janne Jalkanen
+ */
+public interface PageFilter
+{
+ /**
+ * Is called whenever the a new PageFilter is instantiated and
+ * reset.
+ */
+ public void initialize( WikiEngine engine, Properties properties )
+ throws FilterException;
+
+ /**
+ * This method is called whenever a page has been loaded from the provider,
+ * but not yet been sent through the TranslatorReader. Note that you cannot
+ * do HTML translation here, because TranslatorReader is likely to escape it.
+ *
+ * @param wikiContext The current wikicontext.
+ * @param content WikiMarkup.
+ */
+ public String preTranslate( WikiContext wikiContext, String content )
+ throws FilterException;
+
+ /**
+ * This method is called after a page has been fed through the TranslatorReader,
+ * so anything you are seeing here is translated content. If you want to
+ * do any of your own WikiMarkup2HTML translation, do it here.
+ */
+ public String postTranslate( WikiContext wikiContext, String htmlContent )
+ throws FilterException;
+
+ /**
+ * This method is called before the page has been saved to the PageProvider.
+ */
+ public String preSave( WikiContext wikiContext, String content )
+ throws FilterException;
+
+ /**
+ * This method is called after the page has been successfully saved.
+ * If the saving fails for any reason, then this method will not
+ * be called.
+ * <p>
+ * Since the result is discarded from this method, this is only useful
+ * for things like counters, etc.
+ */
+ public void postSave( WikiContext wikiContext, String content )
+ throws FilterException;
+
+ /**
+ * Called for every filter, e.g. on wiki eingine shutdown. Use this if you have to
+ * clean up or close global resources you allocated in the initialize() method.
+ *
+ * @since 2.5.36
+ */
+ public void destroy( WikiEngine engine );
+
+
+}
\ No newline at end of file
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PingWeblogsComFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PingWeblogsComFilter.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PingWeblogsComFilter.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/PingWeblogsComFilter.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,116 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.action.ViewActionBean;
+
+import org.apache.xmlrpc.*;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.*;
+import org.apache.log4j.Logger;
+
+/**
+ * A very dumb class that pings weblogs.com on each save. INTERNAL USE ONLY SO FAR!
+ * Look, but don't use as-is.
+ */
+// FIXME: Needs to figure out when only weblogs have been saved.
+// FIXME: rpc endpoint must be configurable
+// FIXME: Should really be settable per-page.
+// FIXME: Weblog name has been set to stone
+public class PingWeblogsComFilter
+ extends BasicPageFilter
+{
+ static Logger log = Logger.getLogger( PingWeblogsComFilter.class );
+
+ public String m_pingURL;
+
+ public static final String PROP_PINGURL = "pingurl";
+
+ public void initialize( WikiEngine engine, Properties props )
+ {
+ m_pingURL = props.getProperty( PROP_PINGURL, "http://rpc.weblogs.com/RPC2" );
+ }
+
+ public void postSave( WikiContext context, String pagecontent )
+ {
+ String blogName = context.getPage().getName();
+ WikiEngine engine = context.getEngine();
+
+ int blogentryTxt = blogName.indexOf("_blogentry_");
+ if( blogentryTxt == -1 )
+ {
+ return; // This is not a weblog entry.
+ }
+
+ 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>();
+ params.addElement( "The Butt Ugly Weblog" ); // FIXME: Must be settable
+ params.addElement( context.getContext().getURL( ViewActionBean.class, blogName, null, true ) );
+
+ if( log.isDebugEnabled() )
+ log.debug("Pinging weblogs.com with URL: "+context.getContext().getURL( ViewActionBean.class, 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);
+ }
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ProfanityFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ProfanityFilter.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ProfanityFilter.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ProfanityFilter.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,44 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.TextUtil;
+
+public class ProfanityFilter
+ extends BasicPageFilter
+{
+ private static final String[] c_profanities = {
+ "fuck",
+ "shit" };
+
+ public String preTranslate( WikiContext context, String content )
+ {
+ for( int i = 0; i < c_profanities.length; i++ )
+ {
+ String word = c_profanities[i];
+ String replacement = word.charAt(0)+"*"+word.charAt(word.length()-1);
+
+ content = TextUtil.replaceString( content, word, replacement );
+ }
+
+ return content;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/RedirectException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/RedirectException.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/RedirectException.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/RedirectException.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,50 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2003 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+/**
+ * This exception may be thrown if a filter wants to reject something and
+ * redirect the user elsewhere.
+ *
+ * @since 2.1.112
+ * @deprecated use {@link ResolutionException instead}
+ */
+public class RedirectException
+ extends FilterException
+{
+ private static final long serialVersionUID = 0L;
+
+ private final String m_where;
+
+ public RedirectException( String msg, String redirect )
+ {
+ super( msg );
+
+ m_where = redirect;
+ }
+
+ /**
+ * Get the URI for redirection.
+ */
+ public String getRedirect()
+ {
+ return m_where;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ResolutionException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ResolutionException.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ResolutionException.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/filters/ResolutionException.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,73 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2003 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.filters;
+
+import net.sourceforge.stripes.action.Resolution;
+
+/**
+ * Subclass of exception may be thrown if a filter wants to reject something and
+ * redirect the user elsewhere. Unlike {@link RedirectResolution}, this class
+ * requires the caller to supply an i18n message key and Stripes
+ * {@link net.sourceforge.stripes.action.Resolution} instead of a
+ * full-text message and URI.
+ *
+ * @since 3.0
+ */
+public class ResolutionException
+ extends FilterException
+{
+ private static final long serialVersionUID = 0L;
+
+ private final Resolution m_resolution;
+
+ /**
+ * Constructs a new exception with a supplied string message and
+ * Stripes {@link net.sourceforge.stripes.action.Resolution}.
+ * A typical Resolution is the {@link net.sourceforge.stripes.action.ForwardResolution},
+ * which forwards the user to an ActionBean or application path. Another is
+ * the {@link net.sourceforge.stripes.action.RedirectResolution}, which issues
+ * a client-side redirect, and will send the user to an ActionBean or to any
+ * arbitrary URI. The Resolution can be retrieved easily by
+ * @param messageKey the i18n message key, representing the error
+ * to send back to the caller
+ * @param resolution the resolution
+ */
+ public ResolutionException( String messageKey, Resolution resolution )
+ {
+ super( messageKey );
+
+ if ( resolution == null )
+ {
+ throw new IllegalArgumentException("Resolution cannot be null.");
+ }
+
+ m_resolution = resolution;
+ }
+
+ /**
+ * Get the Resolution for redirection. If the constructor {@link #RedirectException(String, String)}
+ * was used, this method may return <code>null</code>.
+ * @return the Resolution for redirection
+ */
+ public Resolution getResolution()
+ {
+ return m_resolution;
+ }
+}