jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r772041 - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/content/ tests/java/org/apache/wiki/content/
Date Wed, 06 May 2009 03:13:48 GMT
Author: ajaquith
Date: Wed May  6 03:13:47 2009
New Revision: 772041

URL: http://svn.apache.org/viewvc?rev=772041&view=rev
Log:
Minor refactoring of pageExists() in WikiEngine, PageManager (legacy) and ContentManager to
clarify that a page "exists" if it is present in the JCR and it has also been previously saved.
Previously, we did not consider persistence, only if the page existed in memory in the JCR.
Page-renaming code in ContentManager is now JCR-optimized (even though the renaming tests
still all fail).

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.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/content/ContentManager.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=772041&r1=772040&r2=772041&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Wed May  6 03:13:47 2009
@@ -1,3 +1,37 @@
+2009-05-05  Andrew Jaquith <ajaquith AT apache DOT org>
+
+        * 3.0.0-svn-112
+        
+        * Minor refactoring of pageExists() in WikiEngine, PageManager (legacy)
+        and ContentManager to clarify that a page "exists" if it is present
+        in the JCR and it has also been previously saved. Previously, we did not
+        consider persistence, only if the page existed in memory in the JCR.
+        Page-renaming code in ContentManager is now JCR-optimized (even
+        though the renaming tests still all fail).
+        
+        * Fixed NPE in JCRWikiPage.getLastModified().
+        
+        * Fixed bug in AuthenticationManager that was causing cookie authentication
+        to fail.
+        
+        * Fixed bug in RPCHandler and test code that was causing a test to fail.
+        
+2009-05-05  Andrew Jaquith <ajaquith AT apache DOT org>
+
+        * 3.0.0-svn-111
+
+        * Fixed AuthenticationManager bug that prevented cookie authentication from
+        working.
+        
+        * Fixed bug in WikiEngine.pageExists that caused pages to be reported as
+        "existing" when they had been added to the JCR repository but not yet saved.
+        WikiEngine.pageExists now checks to see if has actually been saved,
+        whereas ContentManager does not.
+        
+        * Re-wrrote ContentManager.renamePage to use JCR. Sadly, Priha does
+        not support Workspace.move(). If it did, maybe the renaming tests would
+        all work?
+        
 2009-05-04  Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-110

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java?rev=772041&r1=772040&r2=772041&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java Wed May  6 03:13:47
2009
@@ -320,7 +320,7 @@
     public boolean pageExists( String pageName )
         throws ProviderException
     {
-        return m_engine.getContentManager().pageExists( WikiPath.valueOf( pageName ) );
+        return m_engine.pageExists( pageName );
     }
 
     /**
@@ -335,7 +335,7 @@
     public boolean pageExists( String pageName, int version )
         throws ProviderException
     {
-        return m_engine.getContentManager().pageExists( WikiPath.valueOf( pageName ), version
);
+        return m_engine.pageExists( pageName, version );
     }
 
     /**

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=772041&r1=772040&r2=772041&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Wed May  6 03:13:47 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "110";
+    public static final String     BUILD         = "111";
     
     /**
      *  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=772041&r1=772040&r2=772041&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java Wed May  6 03:13:47 2009
@@ -1211,24 +1211,19 @@
      *  any version as existing.  Will also consider attachments.
      *
      *  @param page WikiName of the page.
-     *  @return true, if page (or attachment) exists.
+     *  @return true, if page (or attachment) exists
+     *  @see #pageExists(String, int)
      */
     public boolean pageExists( String page )
     {
-        WikiPath name = WikiPath.valueOf(page);
         try
         {
-            if( getFinalPageName( name ) != null )
-            {
-                return true;
-            }
+            return pageExists( page, WikiProvider.LATEST_VERSION ); 
         }
-        catch( Exception e )
+        catch ( ProviderException e )
         {
-            log.debug("pageExists() failed to find attachments",e);
+            return false;
         }
-
-        return false;
     }
 
     /**
@@ -1237,27 +1232,19 @@
      *
      *  @param page Page name
      *  @param version Page version
-     *  @return True, if page (or alias, or attachment) exists
-     *  @throws ProviderException If the provider fails.
+     *  @return True, if page (or alias, or attachment) exists.
+     *  @throws ProviderException If the provider fails
      */
     public boolean pageExists( String page, int version )
         throws ProviderException
     {
-        boolean isThere = false;
-        WikiPath finalName = WikiPath.valueOf( page );
-        try
-        {
-            //  Go and check if this particular version of this page exists
-            finalName = getFinalPageName( finalName );
-            isThere = m_contentManager.pageExists( finalName, version );
-        }
-        catch( Exception e )
-        {
-            // FIXME: probably not a good idea to catch everything.
-            // It's not there!
-        }
+        // Resolve the page path
+        WikiPath path = WikiPath.valueOf( page );
+        WikiPath finalPath = getFinalPageName( path );
+        finalPath = finalPath == null ? path : finalPath;
 
-        return isThere;
+        // Delegate to ContentManager
+        return m_contentManager.pageExists( finalPath, version );
     }
 
     /**
@@ -1268,15 +1255,12 @@
      *  @return true, if the page (or alias, or attachment) exists.
      *  @throws ProviderException If something goes badly wrong.
      *  @since 2.0
+     *  @see #pageExists(String, int)
      */
     public boolean pageExists( WikiPage page )
         throws ProviderException
     {
-        if( page != null )
-        {
-            return pageExists( page.getName(), page.getVersion() );
-        }
-        return false;
+        return pageExists( page.getPath().toString(), WikiProvider.LATEST_VERSION );
     }
 
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=772041&r1=772040&r2=772041&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Wed May 
6 03:13:47 2009
@@ -760,7 +760,14 @@
     }
     
     /**
-     *  Returns true, if the page exists (any version).
+     *  Returns <code>true</code> if a given page exists (any version). 
+     *  In order for
+     *  this method to return <code>true</code>, the JCR node
+     *  representing the page must exist, and it must also have been
+     *  previously saved (that is, not "new").
+     *  
+     *  Unlike {@link WikiEngine#pageExists(String}, this method does not
+     *  resolve the supplied path by calling {@link WikiEngine#getFinalPageName(WikiPath)}.

      *  
      *  @param wikiPath  the {@link WikiPath} to check for
      *  @return A boolean value describing the existence of a page
@@ -773,25 +780,36 @@
         {
             throw new ProviderException("Illegal page name");
         }
-
+        
+        // Find the JCR node
+        String jcrPath = getJCRPath( wikiPath ); 
+        Node node = null;
         try
         {
-            Session session = m_sessionManager.getSession();
-            
-            String jcrPath = getJCRPath( wikiPath ); 
-            
-            return session.getRootNode().hasNode( jcrPath );
+            node = getJCRNode( jcrPath );
+        }
+        catch ( PathNotFoundException e )
+        {
+            // Node wasn't in JCR; thus, page doesn't exist.
+            return false;
         }
         catch( RepositoryException e )
         {
             throw new ProviderException( "Unable to check for page existence", e );
         }
+        
+        // Node "exists" only if it's been saved already.
+        return  !node.isNew();
     }
     
     /**
-     *  Checks for existence of a specific page and version.
+     *  Returns <code>true</code> if a given page exists for a specific version.
+     *  For the page to "exist" the page must have been previously added
+     *  (for example, by {@link #addPage(WikiPath, String)}), although it need not
+     *  have been saved. This is unlike the {@link WikiEngine} version of
+     *  <code>pageExists</code>, which requires the page to be saved before it
+     *  is considered to exist.
      *  
-     *  @since 2.3.29
      *  @param wikiPath  the {@link WikiPath} to check for
      *  @param version The version to check
      *  @return <code>true</code> if the page exists, <code>false</code>
otherwise
@@ -805,16 +823,25 @@
             throw new ProviderException("Illegal page name");
         }
 
+        // Find the JCR node
+        String jcrPath = getJCRPath( wikiPath ); 
+        Node node = null;
         try
         {
-            Session session = m_sessionManager.getSession();
-            
-            return session.itemExists( getJCRPath( wikiPath ) );
+            node = getJCRNode( jcrPath );
+        }
+        catch ( PathNotFoundException e )
+        {
+            // Node wasn't in JCR; thus, page doesn't exist.
+            return false;
         }
         catch( RepositoryException e )
         {
-            throw new ProviderException("Unable to check for page existence",e);
+            throw new ProviderException( "Unable to check for page existence", e );
         }
+        
+        // Node "exists" only if it's been saved already.
+        return  !node.isNew();
     }
 
     /**
@@ -1148,81 +1175,59 @@
         //
         //  Clean up the "to" -name so that it does not contain anything illegal
         //
-        
         renameTo = MarkupParser.cleanLink( renameTo.trim() );
-        
         if( renameTo.equals(renameFrom) )
         {
             throw new WikiException( "You cannot rename the page to itself" );
         }
         
         //
-        //  Preconditions: "from" page must exist, and "to" page must not yet exist.
+        //  Preconditions: "from" page must exist, and "to" page must NOT exist.
         //
         WikiEngine engine = context.getEngine();
-        WikiPage fromPage;
-        try
-        {
-            fromPage = engine.getPage( renameFrom );
-        }
-        catch( PageNotFoundException e )
+        WikiPath fromPage = WikiPath.valueOf( renameFrom );
+        WikiPath toPage = WikiPath.valueOf( renameTo );
+        if ( !engine.pageExists( fromPage.toString() ) )
         {
-            throw new WikiException("No such page "+renameFrom, e );
+            // TODO: Should localize this
+            throw new WikiException("Cannot rename: source page '"+fromPage.toString() +
"' does not exist." );
         }
-        
-        WikiPage toPage;
-        try
-        {
-            toPage = engine.getPage( renameTo );
-            if( toPage != null )
-            {
-                throw new WikiException("Page already exists "+renameTo);
-            }
-        }
-        catch( PageNotFoundException e )
+        if ( engine.pageExists( toPage.toString() ) )
         {
-            // Good. The page should NOT exist already.
+            // TODO: Should localize this
+            throw new WikiException("Cannot rename: destination page '"+toPage.toString()
+ "' already exists." );
         }
         
         //
         //  Do the actual rename by changing from the frompage to the topage, including
         //  all of the attachments
         //
-        
-        engine.getPageManager().getProvider().movePage( renameFrom, renameTo );
-        /*
-        if( engine.getAttachmentManager().attachmentsEnabled() )
+        Workspace w;
+        try
         {
-            engine.getAttachmentManager().getCurrentProvider().moveAttachmentsForPage( renameFrom,
renameTo );
+            w = getCurrentSession().getWorkspace();
+            w.move( getJCRPath( fromPage ), getJCRPath( toPage ) );
         }
-*/
-        //
-        //  Add a comment to the page notifying what changed.  This adds a new revision
-        //  to the repo with no actual change.
-        //
-        
+        catch( RepositoryException e )
+        {
+            throw new WikiException( "Could not rename page. Reason: " + e.getMessage(),
e );
+        }
+
+        // Make sure the move succeeded...
+        WikiPage page;
         try
         {
-            toPage = engine.getPage( renameTo );
+            page = engine.getPage( toPage );
         }
-        catch( PageNotFoundException e )
+        catch ( PageNotFoundException e )
         {
             throw new InternalWikiException( "Rename seems to have failed for some strange
reason - please check logs!" );
         }
-
-        toPage.setAttribute( WikiPage.CHANGENOTE, fromPage.getName() + " ==> " + toPage.getName()
);
-        toPage.setAuthor( context.getCurrentUser().getName() );
-        
-        engine.getPageManager().putPageText( toPage, engine.getPureText( toPage ) );
+        page.setAttribute( WikiPage.CHANGENOTE, fromPage.toString() + " ==> " + toPage.toString()
);
+        page.setAuthor( context.getCurrentUser().getName() );
 
         // Tell everyone we moved the page
-        fireEvent( ContentEvent.NODE_RENAMED, toPage.getName(), fromPage.getName(), Boolean.valueOf(
changeReferrers ) );
-        
-        //
-        //  re-index the page 
-        //
-        engine.getSearchManager().reindexPage(toPage);
-
+        fireEvent( ContentEvent.NODE_RENAMED, toPage.toString(), fromPage.toString(), Boolean.valueOf(
changeReferrers ) );
         
         //
         //  Done, return the new name.

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java?rev=772041&r1=772040&r2=772041&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java Wed
May  6 03:13:47 2009
@@ -1,5 +1,6 @@
 package org.apache.wiki.content;
 
+import java.util.Collection;
 import java.util.Properties;
 
 import junit.framework.Test;
@@ -9,8 +10,6 @@
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
-import org.apache.wiki.content.ContentManager;
-import org.apache.wiki.content.WikiPath;
 
 
 public class ContentManagerTest extends TestCase
@@ -62,7 +61,7 @@
         
         page.setContent( content );
         
-        page.save();
+        m_mgr.save( page );
         
         WikiPage page2 = m_mgr.getPage( WikiPath.valueOf("Main:TestPage") );
         
@@ -81,7 +80,7 @@
         
         page.setContent( content );
         
-        page.save();
+        m_mgr.save( page );
         
         WikiPage page2 = m_mgr.getPage( WikiPath.valueOf("TestPage") );
         
@@ -98,6 +97,20 @@
         assertEquals( "Back", WikiPath.valueOf("Main:MainPage"), ContentManager.getWikiPath(
"/pages/Main/MainPage" ) );
     }
     
+    public void getAllPages() throws Exception
+    {
+        m_engine.emptyRepository();
+        Collection<WikiPage> allPages = m_mgr.getAllPages( ContentManager.DEFAULT_SPACE
);
+        assertEquals( 0, allPages.size() );
+
+        // Add 2 pages to space Main
+        m_engine.saveText( "Test1", "This is a test." );
+        m_engine.saveText( "Test2", "This is a test." );
+
+        allPages = m_mgr.getAllPages( null );
+        assertEquals( 2, allPages.size() );
+    }
+
     public static Test suite()
     {
         return new TestSuite( ContentManagerTest.class );



Mime
View raw message