Author: ajaquith
Date: Sun Oct 18 05:30:01 2009
New Revision: 826355

URL: http://svn.apache.org/viewvc?rev=826355&view=rev
Log:
Reverted previous fix to lone failing JSPWikiMarkupParserTest and added checks 
into ContentManager.addPage() that recycles Nodes that haven't been saved yet. 
This fixes the edge-case bug that the failing test uncovered: a caller that 
created a particular WikiPage twice via addPage() -- without calling 
WikiPage.save() in between invocations -- created a same-named-sibling (SNS) in 
JCR. Instead of doing this, we simply re-use this Node in the returned WikiPage.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=826355&r1=826354&r2=826355&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Oct 18 05:30:01 2009
@@ -1,5 +1,18 @@
 2009-10-17 Andrew Jaquith <ajaquith AT apache DOT org>
 
+        * 3.0.0-svn-169
+
+        * Reverted previous fix to lone failing JSPWikiMarkupParserTest
+        and added checks into ContentManager.addPage() that recycles
+        Nodes that haven't been saved yet. This fixes the edge-case
+        bug that the failing test uncovered: a caller that created
+        a particular WikiPage twice via addPage() -- without calling
+        WikiPage.save() in between invocations -- created a
+        same-named-sibling (SNS) in JCR. Instead of doing this, we
+        simply re-use this Node in the returned WikiPage. 
+
+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.

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

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=826355&r1=826354&r2=826355&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 
Sun Oct 18 05:30:01 2009
@@ -1455,10 +1455,13 @@
     }
     
     /**
-     *  Adds new content to the repository without saving it. To update, get a 
page, modify
-     *  it, then store it back using save().
+     *  Adds new content to the repository without saving it. To update,
+     *  get a page, modify it, then store it back using save(). If a JCR
+     *  Node with the same path already exists but has not previously been
+     *  saved, it is retained inside the WikiPage that is returned,
+     *  instead of creating a new one.
      *  
-     *  @param path the WikiName
+     *  @param path the WikiPath for the page
      *  @param contentType the type of content
      *  @return the {...@link JCRWikiPage} 
      *  @throws PageAlreadyExistsException if the page already exists in the 
repository
@@ -1470,13 +1473,16 @@
     }
 
     /**
-     *  Add new content to the repository to a particular JCR path, without 
saving it.
+     *  Add new content to the repository to a particular JCR path,
+     *  without saving it. If a JCR Node with the same path already exists
+     *  but has not previously been saved, it is retained inside the WikiPage
+     *  that is returned, instead of creating a new one.
      *  
-     *  @param path
-     *  @param jcrPath
-     *  @param contentType
-     *  @return
-     *  @throws ProviderException
+     *  @param path the WikiPath for the page
+     *  @param jcrPath the JCR path for the page
+     *  @param contentType the type of content
+     *  @return the {...@link JCRWikiPage} 
+     *  @throws ProviderException if the backend fails
      */
     private JCRWikiPage addPage( WikiPath path, String jcrPath, String 
contentType ) 
         throws ProviderException
@@ -1485,15 +1491,32 @@
         
         try
         {
+            // Is there an unsaved node already?
             Session session = m_sessionManager.getSession();
-        
-            Node nd = session.getRootNode().addNode( jcrPath );
+            Node nd = null;
+            try
+            {
+                nd = session.getRootNode().getNode( jcrPath );
+                if ( !isNew( nd ) )
+                {
+                    nd = null;
+                }
+            }
+            catch ( PathNotFoundException e )
+            {
+                // No worries
+            }
             
-            nd.addMixin( "mix:referenceable" );
-            nd.setProperty( JCRWikiPage.CONTENT_TYPE, contentType );
+            // Create a new node from scratch
+            if ( nd == null )
+            {
+                nd = session.getRootNode().addNode( jcrPath );
+                nd.addMixin( "mix:referenceable" );
+                nd.setProperty( JCRWikiPage.CONTENT_TYPE, contentType );
+            }
             
+            // Return the new WikiPage containing the new/re-used Node
             JCRWikiPage page = new JCRWikiPage(m_engine, path, nd);
-            
             return page;
         }
         catch( RepositoryException e )


Reply via email to