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 2009/10/17 18:18:56 UTC

svn commit: r826276 - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/content/ tests/java/org/apache/wiki/ tests/java/org/apache/wiki/content/

Author: ajaquith
Date: Sat Oct 17 16:18:56 2009
New Revision: 826276

URL: http://svn.apache.org/viewvc?rev=826276&view=rev
Log:
All but three tests running, 99.71%. The last three seem to be Priha-related.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ReferenceManager.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/PageRenamerTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ReferenceManagerTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sat Oct 17 16:18:56 2009
@@ -1,3 +1,9 @@
+2009-10-17 Andrew Jaquith <ajaquith AT apache DOT org>
+
+        * 3.0.0-svn-168
+        
+        * All but three tests running, 99.71%. The last three seem to be Priha-related.
+        
 2009-10-14 Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-167

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=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Sat Oct 17 16:18:56 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "167";
+    public static final String     BUILD         = "168";
 
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ReferenceManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ReferenceManager.java?rev=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ReferenceManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ReferenceManager.java Sat Oct 17 16:18:56 2009
@@ -98,7 +98,7 @@
 
     private static final String[] NO_VALUES = new String[0];
 
-    private static final Pattern LINK_PATTERN = Pattern
+    protected static final Pattern LINK_PATTERN = Pattern
         .compile( "([\\[\\~]?)\\[([^\\|\\]]*)(\\|)?([^\\|\\]]*)(\\|)?([^\\|\\]]*)\\]" );
 
     protected static final String REFERENCES_ROOT = "/wiki:references";
@@ -370,8 +370,18 @@
                     Boolean changeReferrers = (Boolean) ((WikiPageEvent) event).getArgs()[1];
                     List<WikiPath> referrers = getReferredBy( fromPage );
                     
+                    // Find all pages the old page referred to,
+                    // and remove the inbound links to those pages by the old page
+                    for ( WikiPath ref : getRefersTo( toPage ) )
+                    {
+                        ref = resolvePage( ref );
+                        String jcrPath = getReferredByJCRNode( ref );
+                        removeFromProperty( jcrPath, PROPERTY_REFERRED_BY, fromPage.toString() );
+                    }
+
                     // Delete all references to the old page name
                     removeLinks( fromPage );
+                    removeLinks( toPage );
                     setLinks( toPage, extractLinks( toPage ) );
 
                     // In every referrer, replace all references to the old page with the new one
@@ -555,13 +565,34 @@
         
         try
         {
-            String jcrPath = getReferencedByJCRNode( destination );
+            String jcrPath = getReferredByJCRNode( destination );
+
+            // Get 'referred-by' links for this Node
             String[] links = getFromProperty( jcrPath, PROPERTY_REFERRED_BY );
             List<WikiPath> referrers = new ArrayList<WikiPath>();
             for( String link : links )
             {
                 referrers.add( WikiPath.valueOf( link ) );
             }
+
+            // Get 'referred-by' links for any child Nodes
+            try
+            {
+                NodeIterator children = m_cm.getJCRNode( jcrPath ).getNodes();
+                int childPathOffset = (REFERRED_BY + "/" + destination.getSpace() + "/").length();
+                while( children.hasNext() )
+                {
+                    Node child = children.nextNode();
+                    String childPathString = destination.getSpace() + ":" + child.getPath().substring( childPathOffset );
+                    WikiPath childPath = WikiPath.valueOf( childPathString );
+                    referrers.addAll( getReferredBy( childPath ) );
+                }
+            }
+            catch ( PathNotFoundException e )
+            {
+                // No worries
+            }
+            
             return referrers;
         }
         catch( RepositoryException e )
@@ -678,7 +709,7 @@
     /**
      * Builds and returns the path used to store the ReferredBy data
      */
-    private String getReferencedByJCRNode( WikiPath path )
+    private String getReferredByJCRNode( WikiPath path )
     {
         if ( path == null )
         {
@@ -761,7 +792,7 @@
 
         // Set the inverse 'referredBy' link for the destination (referred by
         // the source)
-        String jcrPath = getReferencedByJCRNode( page );
+        String jcrPath = getReferredByJCRNode( page );
         addToProperty( jcrPath, PROPERTY_REFERRED_BY, from.toString(), true );
     }
 
@@ -862,11 +893,13 @@
         
         // Set up a streamlined parser to collect links
         WikiPage page = m_engine.getPage( path );
-        LinkCollector localCollector = new LinkCollector();
+        LinkCollector pageLinks = new LinkCollector();
+        LinkCollector attachmentLinks = new LinkCollector();
         String pagedata = page.getContentAsString();
         WikiContext context = m_engine.getWikiContextFactory().newViewContext( page );
         MarkupParser mp = m_engine.getRenderingManager().getParser( context, pagedata );
-        mp.addLocalLinkHook( localCollector );
+        mp.addLocalLinkHook( pageLinks );
+        mp.addAttachmentLinkHook( attachmentLinks );
         mp.disableAccessRules();
 
         // Parse the page, and collect the links
@@ -882,7 +915,15 @@
 
         // Return a WikiPath for each link
         ArrayList<WikiPath> links = new ArrayList<WikiPath>();
-        for( String s : localCollector.getLinks() )
+        for( String s : pageLinks.getLinks() )
+        {
+            WikiPath finalPath = resolvePage( WikiPath.valueOf( s ) );
+            if( !links.contains( finalPath ) )
+            {
+                links.add( finalPath );
+            }
+        }
+        for( String s : attachmentLinks.getLinks() )
         {
             WikiPath finalPath = resolvePage( WikiPath.valueOf( s ) );
             if( !links.contains( finalPath ) )
@@ -1106,7 +1147,7 @@
         // Let's pretend B and C ---> A
 
         // First, remove all inbound links from B & C to A
-        String jcrPath = getReferencedByJCRNode( page );
+        String jcrPath = getReferredByJCRNode( page );
         List<WikiPath> inboundLinks = getReferredBy( page );
         for( WikiPath source : inboundLinks )
         {
@@ -1126,7 +1167,7 @@
             jcrPath = ContentManager.getJCRPath( destination );
             removeFromProperty( jcrPath, PROPERTY_REFERS_TO, page.toString() );
 
-            jcrPath = getReferencedByJCRNode( destination );
+            jcrPath = getReferredByJCRNode( destination );
             removeFromProperty( jcrPath, PROPERTY_REFERRED_BY, page.toString() );
         }
 
@@ -1188,7 +1229,7 @@
         List<WikiPath> oldDestinations = getRefersTo( source );
         for( WikiPath oldDestination : oldDestinations )
         {
-            String jcrPath = getReferencedByJCRNode( oldDestination );
+            String jcrPath = getReferredByJCRNode( oldDestination );
             removeFromProperty( jcrPath, PROPERTY_REFERRED_BY, source.toString() );
         }
 

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java?rev=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java Sat Oct 17 16:18:56 2009
@@ -324,7 +324,7 @@
     public void addAttachment( String pageName, String attachmentName, byte[] data )
         throws PageAlreadyExistsException, ProviderException, IOException
     {
-        Attachment att = getContentManager().addPage( WikiPath.valueOf( pageName ).resolve( attachmentName ), "application/octet-stream" );
+        Attachment att = getContentManager().addPage( WikiPath.valueOf( pageName + "/" + attachmentName ), "application/octet-stream" );
 
         att.setContent( new ByteArrayInputStream(data) );
 

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java?rev=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Sat Oct 17 16:18:56 2009
@@ -756,6 +756,7 @@
         m_engine.saveText( "OldNameTestPage", "Linked to RenameBugTestPage" );
        
         Collection<WikiPath> pages = m_engine.getReferenceManager().getReferredBy( WikiPath.valueOf("RenameBugTestPage") );
+        assertEquals( "wrong # of referrers", 1, pages.size() );
         assertEquals( "has one", "Main:OldNameTestPage", pages.iterator().next().toString() );
         
         WikiContext ctx = m_engine.getWikiContextFactory().newViewContext( m_engine.getPage("OldNameTestPage") );
@@ -768,8 +769,7 @@
         pages = m_engine.getReferenceManager().getReferredBy( WikiPath.valueOf("RenameBugTestPage") );
         
         assertEquals( "wrong # of referrers", 1, pages.size() );
-        
-        assertEquals( "has wrong referrer", "NewNameTestPage", pages.iterator().next() );        
+        assertEquals( "has wrong referrer", "Main:NewNameTestPage", pages.iterator().next().toString() );        
     }
     
     public void testChangeNoteOldVersion2() throws Exception

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/PageRenamerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/PageRenamerTest.java?rev=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/PageRenamerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/PageRenamerTest.java Sat Oct 17 16:18:56 2009
@@ -234,18 +234,18 @@
  
         WikiContext context = m_engine.getWikiContextFactory().newViewContext( p );
  
-        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        m_engine.renamePage(context, "TestPage", "RenamedTest", true);
  
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
  
         assertEquals( "no rename", 
-                      "[FooTest/foo.txt] [linktext|FooTest/bar.jpg]", 
+                      "[RenamedTest/foo.txt] [linktext|RenamedTest/bar.jpg]", 
                       data.trim() );
 
-        WikiPage att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/foo.txt");
+        WikiPage att = m_engine.getAttachmentManager().getAttachmentInfo("RenamedTest/foo.txt");
         assertNotNull("footext",att);
         
-        att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/bar.jpg");
+        att = m_engine.getAttachmentManager().getAttachmentInfo("RenamedTest/bar.jpg");
         assertNotNull("barjpg",att);
         
         att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/bar.jpg");
@@ -258,7 +258,7 @@
     
         assertNull( "oldpage", refs );
     
-        refs = findReferrers( "FooTest/bar.jpg" );
+        refs = findReferrers( "RenamedTest/bar.jpg" );
         assertEquals( "new size", 1, refs.size() );
         assertEquals( "wrong ref", "TestPage2", refs.iterator().next() );
     }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ReferenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ReferenceManagerTest.java?rev=826276&r1=826275&r2=826276&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ReferenceManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ReferenceManagerTest.java Sat Oct 17 16:18:56 2009
@@ -21,7 +21,10 @@
 
 package org.apache.wiki.content;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
 
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
@@ -34,9 +37,6 @@
 
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.api.WikiException;
-import org.apache.wiki.content.ContentManager;
-import org.apache.wiki.content.ReferenceManager;
-import org.apache.wiki.content.WikiPath;
 import org.apache.wiki.providers.ProviderException;
 
 /**
@@ -291,6 +291,25 @@
         assertEquals( 0, links.size() );
     }
 
+    /**
+     * Tests the link-pattern matcher in ReferenceManager, used for changing references.
+     * We test combinations of attachments, anchors and sub-pages.
+     */
+    public void testLinkPatternPage()
+    {
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [FooBar] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [Foo/Bar] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [Foo Bar] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [FooBar#anchor] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [linktext|FooBar] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [linktext|FooBar#anchor] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [FooBar/foo.txt] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [linktext|FooBar/bar.jpg] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [linktext|FooBar#anchor/bar.jpg] text" ).find() );
+        assertTrue( ReferenceManager.LINK_PATTERN.matcher( "Some [linktext|Foo/Bar#anchor/bar.jpg] text" ).find() );
+        assertFalse( ReferenceManager.LINK_PATTERN.matcher( "Some linktext|FooBar#anchor/bar.jpg] text" ).find() );
+    }
+
     public void testNonExistant1() throws Exception
     {
         Collection<WikiPath> c = mgr.getReferredBy( WikiPath.valueOf( "Foobar2" ) );