You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by me...@apache.org on 2009/02/25 21:49:53 UTC

svn commit: r747916 - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/parser/ src/java/org/apache/wiki/plugin/ tests/java/org/apache/wiki/plugin/

Author: metskem
Date: Wed Feb 25 20:49:52 2009
New Revision: 747916

URL: http://svn.apache.org/viewvc?rev=747916&view=rev
Log:
* 3.0.0-svn-73 JSPWIKI-505 - New Plugin: InterWikiLinksPlugin, thanks to Wouter Van daele
added strong typing for some Collections returned by WikiEngine and a few others

Added:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InterWikiLinksPlugin.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/InterWikiLinksPluginTest.java
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/ReleaseNotes
    incubator/jspwiki/trunk/src/java/org/apache/wiki/LinkCollector.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WikiPlugin.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/AllTests.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Wed Feb 25 20:49:52 2009
@@ -1,3 +1,11 @@
+2009-02-25  Harry Metske <me...@apache.org>
+
+        * 3.0.0-svn-73
+        
+        * JSPWIKI-505 - New Plugin: InterWikiLinksPlugin, thanks to Wouter Van daele
+        
+        * strong typing for some Collections returned by WikiEngine and a few others
+
 2009-02-22  Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-72

Modified: incubator/jspwiki/trunk/ReleaseNotes
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ReleaseNotes?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ReleaseNotes (original)
+++ incubator/jspwiki/trunk/ReleaseNotes Wed Feb 25 20:49:52 2009
@@ -11,7 +11,7 @@
 NEW FEATURES
 ============
 
-* JSPWiki now requires JDK 1.5 to run.
+* JSPWiki now requires at least JDK 1.5 to run.
 
 * Simplified Chinese, Dutch, Russian and Italian localizations added!
 
@@ -25,7 +25,9 @@
   
 * Plugins
 	
-	A new plugin was added that shows you all plugins that are available: PluginIndexPlugin
+	New plugins were added:
+	- The PluginIndexPlugin shows you all plugins that are available.
+	- The InterWikiLinksPlugin shows you all defined InterWikiLinks in a customizable manner.
 	
 	The IndexPlugin has a new parameter (showAttachments=true/false), use false if you don't
 	want attachments to show up on the PageIndex page.

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/LinkCollector.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/LinkCollector.java?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/LinkCollector.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/LinkCollector.java Wed Feb 25 20:49:52 2009
@@ -36,7 +36,7 @@
      * Returns a List of Strings representing links.
      * @return the link collection
      */
-    public Collection getLinks()
+    public Collection<String> getLinks()
     {
         return m_items;
     }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Wed Feb 25 20:49:52 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "72";
+    public static final String     BUILD         = "73";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java Wed Feb 25 20:49:52 2009
@@ -1039,7 +1039,7 @@
      *
      *  @return A Collection of Strings.
      */
-    public Collection getAllInterWikiLinks()
+    public Collection<String> getAllInterWikiLinks()
     {
         Vector<String> v = new Vector<String>();
 
@@ -1062,7 +1062,7 @@
      *  @return A Collection of Strings with a regexp pattern.
      */
 
-    public Collection getAllInlinedImagePatterns()
+    public Collection<String> getAllInlinedImagePatterns()
     {
         return JSPWikiMarkupParser.getImagePatterns( this );
     }
@@ -1554,14 +1554,14 @@
     }
 
     /**
-     *  Reads a WikiPageful of data from a String and returns all links
+     *  Reads a WikiPage full of data from a String and returns all links
      *  internal to this Wiki in a Collection.
      *
      *  @param page The WikiPage to scan
      *  @param pagedata The page contents
      *  @return a Collection of Strings
      */
-    public Collection scanWikiLinks( WikiPage page, String pagedata )
+    public Collection<String> scanWikiLinks( WikiPage page, String pagedata )
     {
         LinkCollector localCollector = new LinkCollector();
 
@@ -1823,7 +1823,7 @@
     // FIXME: Should really get a Date object and do proper comparisons.
     //        This is terribly wasteful.
     @SuppressWarnings("unchecked")
-    public Collection getRecentChanges()
+    public Collection<WikiPage> getRecentChanges()
     {
         try
         {

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java Wed Feb 25 20:49:52 2009
@@ -405,7 +405,7 @@
      */
 
     // FIXME: Does not belong here; should be elsewhere
-    public static Collection getImagePatterns( WikiEngine engine )
+    public static Collection<String> getImagePatterns( WikiEngine engine )
     {
         Properties props    = engine.getWikiProperties();
         ArrayList<String>  ptrnlist = new ArrayList<String>();

Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InterWikiLinksPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InterWikiLinksPlugin.java?rev=747916&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InterWikiLinksPlugin.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InterWikiLinksPlugin.java Wed Feb 25 20:49:52 2009
@@ -0,0 +1,202 @@
+/*
+    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 org.apache.wiki.plugin;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.api.PluginException;
+
+/**
+ * Provides a list or table of InterWiki links.
+ * <p>
+ * Parameters:
+ * </p>
+ * <ul>
+ * <li><b>type</b> - The type of output: acceptable values are 'text', 'ulist'
+ * (unordered list), 'olist' or 'table'. Default = 'text'.</li>
+ * <li><b>tabletitle</b> - The title of the table, when specified.</li>
+ * <li><b>separator</b> - The separator string to be used between two entries in
+ * the output of type 'text'. Default = ", ".</li>
+ * </ul>
+ * <p>
+ * Note that the output of this plugin is placed in an HTML DIV with a class
+ * 'interwikilinks'; you can use that in your CSS to give the output a distinct
+ * look.
+ * </p>
+ * 
+ * @author Wouter van daele (devjunkie at nukleos dot com)
+ */
+public class InterWikiLinksPlugin implements WikiPlugin
+{
+    private static enum OutputTypes
+    {
+        TEXT_OUTPUT, U_LIST_OUTPUT, O_LIST_OUTPUT, TABLE_OUTPUT
+    };
+
+    private static Logger log = Logger.getLogger( InterWikiLinksPlugin.class );
+
+    /** Parameter name for setting the type. */
+    public static final String PARAM_TYPE = "type";
+
+    /** Parameter name for setting the title. */
+    public static final String PARAM_TABLE_TITLE = "tabletitle";
+
+    /** Parameter name for setting the separator. */
+    public static final String PARAM_SEPARATOR = "separator";
+
+    private OutputTypes m_defaultOutputType = OutputTypes.TEXT_OUTPUT;
+
+    private String m_defaultTableTitle = "Interwiki Links Table";
+
+    private String m_defaultSeparator = ", ";
+
+    private String m_crlf = System.getProperty( "line.separator" );
+
+    private Collection<String> m_links = null;
+
+    /**
+     * {@inheritDoc}
+     */
+    public String execute( WikiContext context, Map<String, String> params ) throws PluginException
+    {
+        try
+        {
+            StringBuffer sb = new StringBuffer();
+            OutputTypes outputType = m_defaultOutputType;
+
+            m_links = context.getEngine().getAllInterWikiLinks();
+            
+            // Get parameters, if any
+            String typeParam = (String) params.get( PARAM_TYPE );
+            String tableTitleParam = (String) params.get( PARAM_TABLE_TITLE );
+            String separatorParam = (String) params.get( PARAM_SEPARATOR );
+
+            // Handle default cases
+            if( typeParam == null )
+            {
+                outputType = OutputTypes.TEXT_OUTPUT;
+            }
+            else if( "TEXT".equals( typeParam.toUpperCase() ) )
+            {
+                outputType = OutputTypes.TEXT_OUTPUT;
+            }
+            else if( "ULIST".equals( typeParam.toUpperCase() ) )
+            {
+                outputType = OutputTypes.U_LIST_OUTPUT;
+            }
+            else if( "OLIST".equals( typeParam.toUpperCase() ) )
+            {
+                outputType = OutputTypes.O_LIST_OUTPUT;
+            }
+            else if( "TABLE".equals( typeParam.toUpperCase() ) )
+            {
+                outputType = OutputTypes.TABLE_OUTPUT;
+            }
+
+            if( (tableTitleParam == null) || "".equals( tableTitleParam ) )
+            {
+                tableTitleParam = m_defaultTableTitle;
+            }
+
+            if( (separatorParam == null) || "".equals( separatorParam ) )
+            {
+                separatorParam = m_defaultSeparator;
+            }
+
+            // Create output buffer
+            log.debug( "TITLE: " + tableTitleParam + ", SEPARATOR: " + separatorParam + ", TYPE: " + outputType.name() );
+
+            sb.append( "<div class=\"interwikilinks\">" + m_crlf );
+
+            if( outputType.equals( OutputTypes.TEXT_OUTPUT ) )
+            {
+                sb.append( m_crlf + "<span id=\"interwikilisttext\">" );
+
+                int linkCount = 0;
+                for( String link : m_links )
+                {
+                    sb.append( link );
+                    sb.append( " == " );
+                    sb.append( context.getEngine().getInterWikiURL( link ) );
+
+                    // we don't want a separator after the last link :
+                    if( linkCount++ != m_links.size() )
+                    {
+                        sb.append( separatorParam );
+                    }
+                }
+                sb.append( "</span>" + m_crlf );
+            }
+            else if( outputType.equals( OutputTypes.U_LIST_OUTPUT ) )
+            {
+                sb.append( generateListOutput( context, "<ul>", "</ul>" ) );
+            }
+            else if( outputType.equals( OutputTypes.O_LIST_OUTPUT ) )
+            {
+                sb.append( generateListOutput( context, "<ol>", "</ol>" ) );
+            }
+            else if( outputType.equals( OutputTypes.TABLE_OUTPUT ) )
+            {
+                sb.append( "<table><caption>" + tableTitleParam + "</caption>" + m_crlf );
+                sb.append( "<tbody>" + m_crlf );
+
+                for( String link : m_links )
+                {
+                    sb.append( "<tr><td>" );
+                    sb.append( link );
+                    sb.append( "</td><td>" );
+                    sb.append( context.getEngine().getInterWikiURL( link ) );
+                    sb.append( "</td></tr>" + m_crlf );
+                }
+                sb.append( "</tbody>" + m_crlf );
+                sb.append( "</table>" + m_crlf );
+            }
+
+            sb.append( m_crlf + "</div>" + m_crlf );
+
+            return sb.toString();
+        }
+        catch( Exception e )
+        {
+            log.error( "Could not construct InterwikiLinks plugin output, reason: ", e );
+            throw new PluginException( "Unable to construct InterwikiLinks plugin output (see logs)" );
+        }
+    }
+
+    private StringBuffer generateListOutput( WikiContext context, String startTag, String endTag )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( startTag + m_crlf );
+        for( String link : m_links )
+        {
+            sb.append( "    <li>" );
+            sb.append( link );
+            sb.append( " == " );
+            sb.append( context.getEngine().getInterWikiURL( link ) );
+            sb.append( "    </li>" + m_crlf );
+        }
+        return sb.append( endTag + m_crlf );
+    }
+}

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WikiPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WikiPlugin.java?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WikiPlugin.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WikiPlugin.java Wed Feb 25 20:49:52 2009
@@ -61,6 +61,6 @@
      *  @throws PluginException In case anything goes wrong.
      */
 
-    public String execute( WikiContext context, Map params )
+    public String execute( WikiContext context, Map<String,String> params )
         throws PluginException;
 }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/AllTests.java?rev=747916&r1=747915&r2=747916&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/AllTests.java Wed Feb 25 20:49:52 2009
@@ -49,6 +49,8 @@
         suite.addTest( DenouncePluginTest.suite() );
         suite.addTest( ReferredPagesPluginTest.suite() );
         suite.addTest( RecentChangesPluginTest.suite() );
+        suite.addTest( IndexPluginTest.suite() );
+        suite.addTest( InterWikiLinksPluginTest.suite() );
 
         return suite;
     }

Added: incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/InterWikiLinksPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/InterWikiLinksPluginTest.java?rev=747916&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/InterWikiLinksPluginTest.java (added)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/InterWikiLinksPluginTest.java Wed Feb 25 20:49:52 2009
@@ -0,0 +1,108 @@
+/* 
+    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 org.apache.wiki.plugin;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.api.PluginException;
+
+public class InterWikiLinksPluginTest extends TestCase
+{
+    private Properties props = new Properties();
+
+    private TestEngine engine;
+
+    private WikiContext context;
+
+    private PluginManager manager;
+
+    private Collection<String> m_links = null;
+
+    public void setUp() throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        engine = new TestEngine( props );
+
+        manager = new PluginManager( engine, props );
+
+        context = engine.getWikiContextFactory().newViewContext( engine.createPage( "TestPage" ) );
+
+        m_links = engine.getAllInterWikiLinks();
+
+    }
+
+    public void tearDown()
+    {
+        TestEngine.emptyWorkDir();
+
+        engine.shutdown();
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( InterWikiLinksPluginTest.class );
+    }
+
+    /**
+     * Test if all interwikilinks are shown
+     * 
+     * @throws PluginException
+     */
+    public void testLinkCollection() throws PluginException
+    {
+        String result = manager.execute( context, "{InterWikiLinksPlugin}" );
+
+        boolean allLinksFound = true;
+        for( String link : m_links )
+        {
+            if( !result.contains( link ) )
+            {
+                allLinksFound = false;
+            }
+        }
+
+        assertTrue( "none, or not all wikiLinks found", allLinksFound );
+    }
+
+    /**
+     * Test if a table format is presented
+     * 
+     * @throws PluginException
+     */
+    public void testTableFormat() throws PluginException
+    {
+        String title = "DirtyHarryWikiLinks";
+        String result = manager.execute( context, "{InterWikiLinksPlugin type=TABLE,tabletitle=" + title + "}" );
+
+        assertTrue( "no table found", result.contains( "<table>" ) );
+
+        assertTrue( "no (correct) table title found", result.contains( title ) );
+    }
+}