Author: jalkanen
Date: Sun Apr 20 08:50:29 2008
New Revision: 649941
URL: http://svn.apache.org/viewvc?rev=649941&view=rev
Log:
JSPWIKI-100: Added two new parameters to referral plugins; show and
showLastModified. Thanks to Harry Metske.
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferringPagesPlugin.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UndefinedPagesPlugin.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UnusedPagesPlugin.java
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Apr 20 08:50:29 2008
@@ -1,4 +1,14 @@
-2008-04-13 Janne Jalkanen <[EMAIL PROTECTED]>
+2008-04-20 Janne Jalkanen <[EMAIL PROTECTED]>
+
+ * 2.7.0-svn-15
+
+ * [JSPWIKI-5] FileSystemProvider now properly mangles names of pages
which
+ start with a dot. This is done in a fully backwards compatible manner,
+ so no changes to the repo is needed.
+
+ * [JSPWIKI-100] Added two new parameters to ReferringPagesPlugin,
+ UnusedPagesPlugin, ReferredPagesPlugin, and UndefinedPagesPlugin:
+ show and showLastModified. Thanks to Harry Metske for the patch!
* 2.7.0-svn-14
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sun Apr 20
08:50:29 2008
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "14";
+ public static final String BUILD = "15";
/**
* This is the generic version string you should use
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java
(original)
+++
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java
Sun Apr 20 08:50:29 2008
@@ -21,10 +21,8 @@
package com.ecyrd.jspwiki.plugin;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -39,25 +37,35 @@
/**
* This is a base class for all plugins using referral things.
*
- * <p>Parameters:<br>
- * maxwidth: maximum width of generated links<br>
- * separator: separator between generated links (wikitext)<br>
- * after: output after the link
- * before: output before the link
+ * <p>Parameters also valid for all subclasses.</p>
+ * <ul>
+ * <li><b>maxwidth</b>: maximum width of generated links</li>
+ * <li><b>separator</b>: separator between generated links (wikitext)</li>
+ * <li><b>after</b>: output after the link</li>
+ * <li><b>before</b>: output before the link</li>
+ * <li><b>show</b>: Either "pages" (default) or "count". When "count", shows
only the count
+ * of pages which match. (Since 2.8)</li>
+ * <li><b>showLastModified</b>: When show=count, shows also the last modified
date. (Since 2.8)</li>
+ * </ul>
+ *
*/
public abstract class AbstractReferralPlugin
implements WikiPlugin
{
private static Logger log = Logger.getLogger( AbstractReferralPlugin.class
);
- public static final int ALL_ITEMS = -1;
- public static final String PARAM_MAXWIDTH = "maxwidth";
- public static final String PARAM_SEPARATOR = "separator";
- public static final String PARAM_AFTER = "after";
- public static final String PARAM_BEFORE = "before";
-
- public static final String PARAM_EXCLUDE = "exclude";
- public static final String PARAM_INCLUDE = "include";
+ public static final int ALL_ITEMS = -1;
+ public static final String PARAM_MAXWIDTH = "maxwidth";
+ public static final String PARAM_SEPARATOR = "separator";
+ public static final String PARAM_AFTER = "after";
+ public static final String PARAM_BEFORE = "before";
+
+ public static final String PARAM_EXCLUDE = "exclude";
+ public static final String PARAM_INCLUDE = "include";
+ public static final String PARAM_SHOW = "show";
+ public static final String PARAM_SHOW_VALUE_PAGES = "pages";
+ public static final String PARAM_SHOW_VALUE_COUNT = "count";
+ public static final String PARAM_LASTMODIFIED = "showLastModified";
protected int m_maxwidth = Integer.MAX_VALUE;
protected String m_before = ""; // null not blank
@@ -66,6 +74,12 @@
protected Pattern[] m_exclude;
protected Pattern[] m_include;
+
+ protected String m_show = "pages";
+ protected boolean m_lastModified=false;
+ // the last modified date of the page that has been last modified:
+ protected Date m_dateLastModified = new Date(0);
+ protected SimpleDateFormat m_dateFormat = new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
protected WikiEngine m_engine;
@@ -157,7 +171,34 @@
}
// log.debug( "Requested maximum width is "+m_maxwidth );
+ s = (String) params.get(PARAM_SHOW);
+
+ if( s != null )
+ {
+ if( s.equalsIgnoreCase( "count" ) )
+ {
+ m_show = "count";
+ }
+ }
+
+ s = (String) params.get( PARAM_LASTMODIFIED );
+
+ if( s != null )
+ {
+ if( s.equalsIgnoreCase( "true" ) )
+ {
+ if( m_show.equals( "count" ) )
+ {
+ m_lastModified = true;
+ }
+ else
+ {
+ throw new PluginException( "showLastModified=true is only
valid if show=count is also specified" );
+ }
+ }
+ }
}
+
protected Collection filterCollection( Collection c )
{
@@ -204,6 +245,23 @@
if( includeThis )
{
result.add( pageName );
+ //
+ // if we want to show the last modified date of the most
recently change page, we keep a "high watermark" here:
+ WikiPage page = null;
+ if (m_lastModified) {
+ page = m_engine.getPage(pageName);
+ if (page!= null)
+ {
+ Date lastModPage = page.getLastModified();
+ if (log.isDebugEnabled()) {
+ log.debug("lastModified Date of page " + pageName
+ " : " + m_dateLastModified);
+ }
+ if (lastModPage.after(m_dateLastModified)){
+ m_dateLastModified=lastModPage;
+ }
+ }
+
+ }
}
}
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferringPagesPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferringPagesPlugin.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferringPagesPlugin.java
(original)
+++
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferringPagesPlugin.java
Sun Apr 20 08:50:29 2008
@@ -93,13 +93,25 @@
}
//
- // If nothing was left after filtering or during search
+ // If nothing was left after filtering or during search
//
- if( links == null || links.size() == 0 )
+ if (links == null || links.size() == 0)
{
wikitext = rb.getString("referringpagesplugin.nobody");
}
+ else
+ {
+ if (m_show.equals(PARAM_SHOW_VALUE_COUNT))
+ {
+ wikitext = "" + links.size();
+ if (m_lastModified)
+ {
+ wikitext = links.size() + " (" +
m_dateFormat.format(m_dateLastModified) + ")";
+ }
+ }
+ }
+
return makeHTML( context, wikitext );
}
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UndefinedPagesPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UndefinedPagesPlugin.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UndefinedPagesPlugin.java
(original)
+++
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UndefinedPagesPlugin.java
Sun Apr 20 08:50:29 2008
@@ -21,6 +21,7 @@
package com.ecyrd.jspwiki.plugin;
import com.ecyrd.jspwiki.*;
+
import java.util.*;
/**
@@ -44,11 +45,26 @@
super.initialize( context, params );
TreeSet sortedSet = new TreeSet();
+
+ links = filterCollection( links );
+
sortedSet.addAll( links );
- filterCollection( links );
+ String wikitext = null;
+
+ if (m_lastModified)
+ {
+ throw new PluginException("parameter " + PARAM_LASTMODIFIED + " is
not valid for the UndefinedPagesPlugin");
+ }
- String wikitext = wikitizeCollection( sortedSet, m_separator,
ALL_ITEMS );
+ if (m_show.equals(PARAM_SHOW_VALUE_COUNT))
+ {
+ wikitext = "" + links.size();
+ }
+ else
+ {
+ wikitext = wikitizeCollection(sortedSet, m_separator, ALL_ITEMS);
+ }
return makeHTML( context, wikitext );
}
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UnusedPagesPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UnusedPagesPlugin.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UnusedPagesPlugin.java
(original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/UnusedPagesPlugin.java
Sun Apr 20 08:50:29 2008
@@ -72,12 +72,25 @@
super.initialize( context, params );
TreeSet sortedSet = new TreeSet();
-
+
+ links = filterCollection( links );
+
sortedSet.addAll( links );
- filterCollection( links );
- String wikitext = wikitizeCollection( sortedSet, m_separator,
ALL_ITEMS );
+ String wikitext = null;
+ if (m_show.equals(PARAM_SHOW_VALUE_COUNT))
+ {
+ wikitext = "" + links.size();
+ if (m_lastModified & links.size()!=0)
+ {
+ wikitext = links.size() + " (" +
m_dateFormat.format(m_dateLastModified) + ")";
+ }
+ }
+ else
+ {
+ wikitext = wikitizeCollection(sortedSet, m_separator, ALL_ITEMS);
+ }
return makeHTML( context, wikitext );
}
Modified:
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
---
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
(original)
+++
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
Sun Apr 20 08:50:29 2008
@@ -1,6 +1,7 @@
package com.ecyrd.jspwiki.plugin;
+import java.text.SimpleDateFormat;
import java.util.Properties;
import junit.framework.Test;
@@ -83,24 +84,28 @@
{
String res = manager.execute( context,
"{INSERT
com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=5}");
-
+
int count = 0;
int index = -1;
-
+
// Count the number of hyperlinks. We could check their
// correctness as well, though.
-
+
while( (index = res.indexOf("<a",index+1)) != -1 )
{
count++;
}
-
- assertEquals( 5, count );
-
- String expected = "...and 2 more<br />";
-
- assertEquals( "End", expected,
- res.substring( res.length()-expected.length() ) );
+
+ // there are always 2 more "<a" 's in the result
+ assertEquals( 5+2, count );
+
+ String expected = ">2 more</a>";
+ count =0;
+ while( (index = res.indexOf(expected,index+1)) != -1 )
+ {
+ count++;
+ }
+ assertEquals("End", 1, count );
}
public void testReferenceWidth()
@@ -162,6 +167,38 @@
assertTrue( "2", res.indexOf("Foobar2") != -1 );
}
+ public void testCount() throws Exception
+ {
+ String result = null;
+ result = manager.execute(context, "{ReferringPagesPlugin show=count}");
+ assertEquals("7",result);
+
+ result = manager.execute(context,
"{ReferringPagesPlugin,exclude='*7',show=count}");
+ assertEquals("6",result);
+
+ result = manager.execute(context,
"{ReferringPagesPlugin,exclude='*7',show=count,showLastModified=true}");
+ String numberResult=result.substring(0,result.indexOf(" "));
+ assertEquals("6",numberResult);
+
+ String dateString =
result.substring(result.indexOf("(")+1,result.indexOf(")"));
+ // the date should be parseable:
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ df.parse(dateString);
+
+ // test if the proper exception is thrown:
+ String expectedExceptionString = "showLastModified=true is only valid
if show=count is also specified";
+ String exceptionString = null;
+ try
+ {
+ result = manager.execute(context,
"{ReferringPagesPlugin,showLastModified=true}");
+ }
+ catch (PluginException pe)
+ {
+ exceptionString = pe.getMessage();
+ }
+
+ assertEquals(expectedExceptionString, exceptionString);
+ }
public static Test suite()
{
Modified:
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java?rev=649941&r1=649940&r2=649941&view=diff
==============================================================================
---
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java
(original)
+++
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java
Sun Apr 20 08:50:29 2008
@@ -67,6 +67,27 @@
assertEquals( wikitize(exp), res );
}
+ public void testCount() throws Exception
+ {
+ String result = null;
+ result = manager.execute(context, "{UndefinedPagesPlugin show=count}");
+ assertEquals("1", result);
+
+ // test if the proper exception is thrown:
+ String expectedExceptionString = "parameter showLastModified is not
valid for the UndefinedPagesPlugin";
+ String exceptionString = null;
+ try
+ {
+ result = manager.execute(context,
"{UndefinedPagesPlugin,show=count,showLastModified=true}");
+ }
+ catch (PluginException pe)
+ {
+ exceptionString = pe.getMessage();
+ }
+
+ assertEquals(expectedExceptionString, exceptionString);
+ }
+
public static Test suite()
{
return new TestSuite( UndefinedPagesPluginTest.class );