Author: metskem
Date: Sat Jan 3 11:57:21 2009
New Revision: 731075
URL: http://svn.apache.org/viewvc?rev=731075&view=rev
Log:
3.0.0-svn-44 JSPWIKI-458 - IndexPlugin now has a new showAttachments parameter
Added:
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/IndexPluginTest.java
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/ReleaseNotes
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IndexPlugin.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=731075&r1=731074&r2=731075&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sat Jan 3 11:57:21 2009
@@ -1,5 +1,11 @@
2009-01-03 Harry Metske <[email protected]>
+ * 3.0.0-svn-44
+
+ * JSPWIKI-458 - IndexPlugin now has a new showAttachments parameter
+
+2009-01-03 Harry Metske <[email protected]>
+
* 3.0.0-svn-43
* JSPWIKI-452 - The LoggerFactory is now also multi-wiki-per-JVM
capable
Modified: incubator/jspwiki/trunk/ReleaseNotes
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ReleaseNotes?rev=731075&r1=731074&r2=731075&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ReleaseNotes (original)
+++ incubator/jspwiki/trunk/ReleaseNotes Sat Jan 3 11:57:21 2009
@@ -23,7 +23,12 @@
The log4j configuration statements have been moved to a separate file
log4j.properties,
this file should be on your CLASSPATH, by default it is placed in
WEB-INF/classes
-* A new plugin was added that shows you all plugins that are available:
PluginIndexPlugin
+* Plugins
+
+ A new plugin was added that shows you all plugins that are available:
PluginIndexPlugin
+
+ The IndexPlugin has a new parameter (showAttachments=true/false), use
false if you don't
+ want attachments to show up on the PageIndex page.
The full log of any issues fixed can be found at:
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=731075&r1=731074&r2=731075&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sat Jan 3
11:57:21 2009
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "43";
+ public static final String BUILD = "44";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IndexPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IndexPlugin.java?rev=731075&r1=731074&r2=731075&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IndexPlugin.java
(original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IndexPlugin.java Sat
Jan 3 11:57:21 2009
@@ -42,12 +42,16 @@
* <ul>
* <li><b>include</b> - A regexp pattern for marking which pages should be
included.</li>
* <li><b>exclude</b> - A regexp pattern for marking which pages should be
excluded.</li>
+ * <li><b>showAttachments</b> - Indicates if attachments should also be
shown, the default is true.</li>
* </ul>
*/
public class IndexPlugin extends AbstractReferralPlugin implements WikiPlugin
{
private static Logger log = LoggerFactory.getLogger( IndexPlugin.class );
+ /** The parameter name for setting the showAttachment. Value is
<tt>{...@value}</tt>. */
+ public static final String PARAM_SHOW_ATTACHMENTS = "showAttachments";
+
/**
* {...@inheritdoc}
*/
@@ -55,6 +59,12 @@
{
String include = (String)params.get( PARAM_INCLUDE );
String exclude = (String)params.get( PARAM_EXCLUDE );
+ String showAttachmentsString = (String) params.get(
PARAM_SHOW_ATTACHMENTS );
+ boolean showAttachments = true;
+ if( "false".equals( showAttachmentsString ) )
+ {
+ showAttachments = false;
+ }
List<String> pages;
div masterDiv = new div();
@@ -66,7 +76,7 @@
indexDiv.setClass( "header" );
try
{
- pages = listPages( context, include, exclude );
+ pages = listPages( context, include, exclude, showAttachments );
Collections.sort( pages );
char initialChar = ' ';
@@ -132,7 +142,7 @@
* @return A list containing page names which matched the filters.
* @throws ProviderException
*/
- private List<String> listPages( WikiContext context, String include,
String exclude )
+ private List<String> listPages( WikiContext context, String include,
String exclude, boolean showAttachments )
throws ProviderException
{
Pattern includePtrn = include != null ? Pattern.compile( include ) :
Pattern.compile(".*");
@@ -149,7 +159,17 @@
if( excludePtrn.matcher( pageName ).matches() ) continue;
if( includePtrn.matcher( pageName ).matches() )
{
- result.add( pageName );
+ if( showAttachments )
+ {
+ result.add( pageName );
+ }
+ else
+ {
+ if( !pageName.contains( "/" ) )
+ {
+ result.add( pageName );
+ }
+ }
}
}
Added:
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/IndexPluginTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/IndexPluginTest.java?rev=731075&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/IndexPluginTest.java
(added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/IndexPluginTest.java
Sat Jan 3 11:57:21 2009
@@ -0,0 +1,136 @@
+/*
+JSPWiki - a JSP-based WikiWiki clone.
+
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+ */
+package com.ecyrd.jspwiki.plugin;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.StringReader;
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.attachment.Attachment;
+import com.ecyrd.jspwiki.attachment.AttachmentManager;
+import com.ecyrd.jspwiki.util.FileUtil;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class IndexPluginTest extends TestCase
+{
+ Properties m_props = new Properties();
+
+ TestEngine m_engine;
+
+ AttachmentManager m_attManager;
+
+ WikiContext m_context;
+
+ PluginManager m_manager;
+
+ public void setUp() throws Exception
+ {
+ m_props.load( TestEngine.findTestProperties() );
+ m_engine = new TestEngine( m_props );
+ m_attManager = m_engine.getAttachmentManager();
+ m_context = m_engine.getWikiContextFactory().newViewContext( null,
null, m_engine.createPage( "WhatEver" ) );
+ m_manager = new PluginManager( m_engine, m_props );
+ }
+
+ public void tearDown()
+ {
+ TestEngine.deleteTestPage( "TestPage" );
+ TestEngine.emptyWorkDir();
+ m_engine.shutdown();
+ }
+
+ /**
+ * Plain test without parameters
+ *
+ * @throws Exception
+ */
+ public void testSimple() throws Exception
+ {
+ m_engine.saveText( "TestPage", "Content of TestPage" );
+
+ String res = m_manager.execute( m_context, "{INSERT
com.ecyrd.jspwiki.plugin.IndexPlugin}" );
+
+ assertTrue( "TestPage not found in Index", res.contains( "<a
href='/Wiki.jsp?page=TestPage'>TestPage</a>" ) );
+ }
+
+ /**
+ * Plain test without parameters, but with an attachment
+ *
+ * @throws Exception
+ */
+ public void testAttachment() throws Exception
+ {
+ m_engine.saveText( "TestPage", "Content of TestPage" );
+
+ Attachment att = new Attachment( m_engine, "TestPage", "test1.txt" );
+ att.setAuthor( "OmeJoop" );
+ m_attManager.storeAttachment( att, makeAttachmentFile() );
+
+ String res = m_manager.execute( m_context, "{INSERT
com.ecyrd.jspwiki.plugin.IndexPlugin}" );
+
+ assertTrue( "TestPage not found in Index", res.contains( "<a
href='/Wiki.jsp?page=TestPage'>TestPage</a>" ) );
+
+ assertTrue( "attachment not found in Index", res
+ .contains( "<a
href='/Wiki.jsp?page=TestPage/test1.txt'>TestPage/test1.txt</a>" ) );
+ }
+
+ /**
+ * Test with showAttachment=false parameter
+ *
+ * @throws Exception
+ */
+ public void testAttachmentDoNotShow() throws Exception
+ {
+ m_engine.saveText( "TestPage", "Content of TestPage" );
+
+ Attachment att = new Attachment( m_engine, "TestPage", "test1.txt" );
+ att.setAuthor( "OmeJoop" );
+ m_attManager.storeAttachment( att, makeAttachmentFile() );
+
+ String res = m_manager.execute( m_context, "{INSERT
com.ecyrd.jspwiki.plugin.IndexPlugin showAttachments=false}" );
+
+ assertTrue( "TestPage not found in Index", res.contains( "<a
href='/Wiki.jsp?page=TestPage'>TestPage</a>" ) );
+
+ assertFalse( "attachment should not be in Index", res
+ .contains( "<a
href='/Wiki.jsp?page=TestPage/test1.txt'>TestPage/test1.txt</a>" ) );
+ }
+
+ private File makeAttachmentFile() throws Exception
+ {
+ File tmpFile = File.createTempFile( "test", "txt" );
+ tmpFile.deleteOnExit();
+ FileWriter out = new FileWriter( tmpFile );
+ FileUtil.copyContents( new StringReader( "contents of attachment file"
), out );
+ out.close();
+ return tmpFile;
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( IndexPluginTest.class );
+ }
+}