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 2014/01/07 20:20:45 UTC

svn commit: r1556327 - in /jspwiki/trunk: ./ jspwiki-war/src/main/java/org/apache/wiki/ jspwiki-war/src/main/java/org/apache/wiki/plugin/ jspwiki-war/src/main/resources/plugin/ jspwiki-war/src/test/java/org/apache/wiki/plugin/

Author: metskem
Date: Tue Jan  7 19:20:45 2014
New Revision: 1556327

URL: http://svn.apache.org/r1556327
Log:
2014-01-07  Harry Metske (metskem@apache.org)

       * 2.10.0-svn-66

       * JSPWIKI-810 - included the ReferringUndefinedPagesPlugin

Added:
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/ReferringUndefinedPagesPluginTest.java
Modified:
    jspwiki/trunk/ChangeLog
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_de.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_es.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fi.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fr.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_it.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_nl.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_pt_BR.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_ru.properties
    jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_zh_CN.properties

Modified: jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/jspwiki/trunk/ChangeLog?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/ChangeLog (original)
+++ jspwiki/trunk/ChangeLog Tue Jan  7 19:20:45 2014
@@ -1,3 +1,9 @@
+2014-01-07  Harry Metske (metskem@apache.org)
+
+       * 2.10.0-svn-66
+
+       * JSPWIKI-810 - included the ReferringUndefinedPagesPlugin
+
 2014-01-02  Juan Pablo Santos (juanpablo AT apache DOT org)
 
        * 2.10.0-svn-65

Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java Tue Jan  7 19:20:45 2014
@@ -72,7 +72,7 @@ public final class Release {
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "65";
+    public static final String     BUILD         = "66";
     
     /**
      *  This is the generic version string you should use when printing out the version.  It is of 

Added: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java?rev=1556327&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java (added)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java Tue Jan  7 19:20:45 2014
@@ -0,0 +1,106 @@
+/*
+    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 org.apache.log4j.Logger;
+import org.apache.wiki.ReferenceManager;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.api.exceptions.PluginException;
+import org.apache.wiki.api.plugin.WikiPlugin;
+import org.apache.wiki.preferences.Preferences;
+import org.apache.wiki.util.TextUtil;
+
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.TreeMap;
+/**
+ *  <p>Lists all pages containing links to Undefined Pages (pages containing dead links).</p>
+ *
+ *  An original idea from Gregor Hagedorn.
+ *
+ *  @since 2.10.0
+ */
+public class ReferringUndefinedPagesPlugin extends AbstractReferralPlugin {
+    private static Logger log = Logger.getLogger(ReferringUndefinedPagesPlugin.class);
+
+    /**
+     * Parameter name for setting the maximum items to show.  Value is <tt>{@value}</tt>.
+     */
+    public static final String PARAM_MAX = "max";
+
+    /**
+     * Parameter name for setting the text to show when the maximum items is overruled.
+     * Value is <tt>{@value}</tt>.
+     */
+    public static final String PARAM_EXTRAS = "extras";
+
+    public String execute(WikiContext context, Map<String, String> params) throws PluginException {
+        ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
+
+        ReferenceManager referenceManager = context.getEngine().getReferenceManager();
+
+        int items = TextUtil.parseIntParameter(params.get(PARAM_MAX), ALL_ITEMS);
+        String extras = params.get(PARAM_EXTRAS);
+        if (extras == null) {
+            extras = rb.getString("referringundefinedpagesplugin.more");
+        }
+
+        StringBuilder resultHTML = new StringBuilder();
+
+        Collection<String> uncreatedPages = referenceManager.findUncreated();
+
+        super.initialize(context, params);
+
+        Collection<String> result = null;
+
+        TreeMap sortedMap = new TreeMap();
+        if (uncreatedPages != null) {
+            for (String uncreatedPageName : uncreatedPages) {
+                Collection<String> referrers = referenceManager.findReferrers(uncreatedPageName);
+                if (referrers != null) {
+                    for (String referringPage : referrers) {
+                        sortedMap.put(referringPage, "");
+                    }
+                }
+            }
+            result = sortedMap.keySet();
+        }
+
+        result = super.filterAndSortCollection(result);
+
+        String wikitext = wikitizeCollection(result, m_separator, items);
+
+        resultHTML.append(makeHTML(context, wikitext));
+
+        // add the more.... text
+        if (items < result.size() && items > 0) {
+            Object[] args = {"" + (result.size() - items)};
+            extras = MessageFormat.format(extras, args);
+
+            resultHTML.append("<br/>" + extras + "<br/>");
+        }
+        return resultHTML.toString();
+    }
+
+}
+
+
+

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources.properties Tue Jan  7 19:20:45 2014
@@ -70,4 +70,7 @@ plugin.listlocks.page=Page
 plugin.listlocks.locked.by=Locked by
 plugin.listlocks.acquired=Acquired
 plugin.listlocks.expires=Expires
-plugin.listlocks.no.locks.exist=No locks exist currently.
\ No newline at end of file
+plugin.listlocks.no.locks.exist=No locks exist currently.
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ...and {0} more

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_de.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_de.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_de.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_de.properties Tue Jan  7 19:20:45 2014
@@ -89,3 +89,5 @@ plugin.listlocks.acquired=gesperrt ab
 plugin.listlocks.expires=gesperrt bis
 plugin.listlocks.no.locks.exist=Momentan existieren keine Sperren.
 
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ... und {0} weitere

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_es.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_es.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_es.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_es.properties Tue Jan  7 19:20:45 2014
@@ -71,4 +71,7 @@ plugin.listlocks.page=Página
 plugin.listlocks.locked.by=Bloqueada por
 plugin.listlocks.acquired=Adquirida
 plugin.listlocks.expires=Expira
-plugin.listlocks.no.locks.exist=No existen bloqueos actualmente.
\ No newline at end of file
+plugin.listlocks.no.locks.exist=No existen bloqueos actualmente.
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ... y {0} más

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fi.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fi.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fi.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fi.properties Tue Jan  7 19:20:45 2014
@@ -72,3 +72,6 @@ plugin.listlocks.expires = Lukko umpeutu
 plugin.listlocks.locked.by = Lukitsija
 plugin.listlocks.no.locks.exist = Ei lukkoja tällä hetkellä.
 plugin.listlocks.page = Sivu
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ...ja {0} lisää

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fr.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fr.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fr.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_fr.properties Tue Jan  7 19:20:45 2014
@@ -84,3 +84,6 @@ plugin.listlocks.no.locks.exist=Aucun ve
 
 #Plugin Denounce
 #denounce.denouncetext = &lt;Le lien vers les moteurs de recherche d\u00E9sapprouv\u00E9s a \u00E9t\u00E9 supprim\u00E9&gt;
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ...et [{0} plus |{1}]\\\\

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_it.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_it.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_it.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_it.properties Tue Jan  7 19:20:45 2014
@@ -72,4 +72,5 @@ plugin.listlocks.acquired=Aquisiti
 plugin.listlocks.expires=Scade il
 plugin.listlocks.no.locks.exist=In questo momento non esitono blocchi.
 
-
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ... e {0} altri

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_nl.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_nl.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_nl.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_nl.properties Tue Jan  7 19:20:45 2014
@@ -78,4 +78,7 @@ plugin.listlocks.page=Pagina
 plugin.listlocks.locked.by=In gebruik door
 plugin.listlocks.acquired=Sinds
 plugin.listlocks.expires=Loopt af
-plugin.listlocks.no.locks.exist=Er zijn momenteel geen locks.
\ No newline at end of file
+plugin.listlocks.no.locks.exist=Er zijn momenteel geen locks.
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ... en {0} meer

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_pt_BR.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_pt_BR.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_pt_BR.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_pt_BR.properties Tue Jan  7 19:20:45 2014
@@ -70,4 +70,7 @@ plugin.listlocks.page=Página
 plugin.listlocks.locked.by=Bloquada por
 plugin.listlocks.acquired=Adquirida
 plugin.listlocks.expires=Expira
-plugin.listlocks.no.locks.exist=Não existe bloqueio atualmente.
\ No newline at end of file
+plugin.listlocks.no.locks.exist=Não existe bloqueio atualmente.
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ...e {0} mais

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_ru.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_ru.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_ru.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_ru.properties Tue Jan  7 19:20:45 2014
@@ -71,3 +71,6 @@ plugin.listlocks.locked.by=\u0417\u0430\
 plugin.listlocks.acquired=\u041f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u043e
 plugin.listlocks.expires=\u0418\u0441\u0442\u0435\u043a\u0430\u0435\u0442
 plugin.listlocks.no.locks.exist=\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435\u0442.
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ...\u0438 {0} \u0431\u043e\u043b\u044c\u0448\u0435

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_zh_CN.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_zh_CN.properties?rev=1556327&r1=1556326&r2=1556327&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_zh_CN.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/plugin/PluginResources_zh_CN.properties Tue Jan  7 19:20:45 2014
@@ -71,4 +71,7 @@ plugin.listlocks.page=\u9875\u9762
 plugin.listlocks.locked.by=\u9501\u5b9a\u8005\u4e3a
 plugin.listlocks.acquired=\u5df2\u83b7\u5f97
 plugin.listlocks.expires=\u5df2\u8fc7\u671f
-plugin.listlocks.no.locks.exist=\u76ee\u524d\u4e0d\u5b58\u5728\u9501\u3002
\ No newline at end of file
+plugin.listlocks.no.locks.exist=\u76ee\u524d\u4e0d\u5b58\u5728\u9501\u3002
+
+# ReferringUndefinedPagesPlugin
+referringundefinedpagesplugin.more = ...\u8fd8\u6709 {0} \u4e2a\u5f15\u7528\u9875\u9762

Added: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/ReferringUndefinedPagesPluginTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/ReferringUndefinedPagesPluginTest.java?rev=1556327&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/ReferringUndefinedPagesPluginTest.java (added)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/ReferringUndefinedPagesPluginTest.java Tue Jan  7 19:20:45 2014
@@ -0,0 +1,113 @@
+/*
+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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.engine.PluginManager;
+
+import java.util.Properties;
+
+public class ReferringUndefinedPagesPluginTest extends TestCase {
+    Properties props = TestEngine.getTestProperties();
+
+	TestEngine testEngine;
+
+	WikiContext context;
+
+	PluginManager manager;
+
+	public void setUp() throws Exception {
+        CacheManager.getInstance().clearAll();
+		testEngine = new TestEngine(props);
+
+        testEngine.saveText("TestPage01", "Some Text for testing 01 which refers [NonExistingPageA] ");
+        testEngine.saveText("TestPage02", "Some Text for testing 02 which refers [NonExistingPageB] ");
+		testEngine.saveText("TestPage03", "Some Text for testing 03 which refers [NonExistingPageC] ");
+
+        context = new WikiContext( testEngine, testEngine.newHttpRequest(), new WikiPage(testEngine,"TestPage") );
+        manager = new DefaultPluginManager( testEngine, props );	}
+
+	public void tearDown() {
+		testEngine.deleteTestPage("TestPage01");
+		testEngine.deleteTestPage("TestPage02");
+		testEngine.deleteTestPage("TestPage03");
+
+		TestEngine.emptyWorkDir();
+	}
+
+	/**
+	 * Plain test without parameters
+	 * 
+	 * @throws Exception
+	 */
+	public void testSimple() throws Exception {
+		String res = manager.execute(context, "{INSERT ReferringUndefinedPagesPlugin}");
+		assertTrue(res.contains("href=\"/Wiki.jsp?page=TestPage01\""));
+	}
+
+	/**
+	 * Test with the include parameter
+	 * 
+	 * @throws Exception
+	 */
+	public void testParmInClude() throws Exception {
+		String res = manager.execute(context, "{INSERT ReferringUndefinedPagesPlugin} include='TestPage02*'}"); 
+		assertFalse(res.contains("href=\"/Wiki.jsp?page=TestPage01\""));
+		assertTrue(res.contains("href=\"/Wiki.jsp?page=TestPage02\""));
+        assertFalse(res.contains("href=\"/Wiki.jsp?page=TestPage03\""));
+	}
+
+    /**
+     * Test with the exclude parameter
+     *
+     * @throws Exception
+     */
+    public void testParmExClude() throws Exception {
+        String res = manager.execute(context,"{INSERT ReferringUndefinedPagesPlugin} exclude='TestPage02*'}");
+
+        assertTrue(res.contains("href=\"/Wiki.jsp?page=TestPage01\""));
+        assertFalse(res.contains("href=\"/Wiki.jsp?page=TestPage02\""));
+        assertTrue(res.contains("href=\"/Wiki.jsp?page=TestPage03\""));
+    }
+
+    /**
+     * Test with the max parameter
+     *
+     * @throws Exception
+     */
+    public void testParmMax() throws Exception {
+        String res = manager.execute(context,"{INSERT ReferringUndefinedPagesPlugin} max='2'}");
+
+        assertTrue(res.contains("href=\"/Wiki.jsp?page=TestPage01\""));
+        assertTrue(res.contains("href=\"/Wiki.jsp?page=TestPage02\""));
+        assertFalse(res.contains("href=\"/Wiki.jsp?page=TestPage03\""));
+        assertTrue(res.contains("...and 1 more"));
+    }
+
+	public static Test suite() {
+		return new TestSuite(ReferringUndefinedPagesPluginTest.class);
+	}
+}