Author: vmassol
Date: 2007-11-23 17:28:09 +0100 (Fri, 23 Nov 2007)
New Revision: 6052

Modified:
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/ConfluenceRpcHandler.java
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/client/XWikiClient.java
   
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java
Log:
XWIKI-1884: Verify that the pageId passed to the XWiki implementation of the 
Confluence XMLRPC API are of the form Space.Page and throw an exception 
otherwise

+ improved some javadoc


Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/ConfluenceRpcHandler.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/ConfluenceRpcHandler.java
   2007-11-23 14:03:08 UTC (rev 6051)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/ConfluenceRpcHandler.java
   2007-11-23 16:28:09 UTC (rev 6052)
@@ -665,10 +665,11 @@
      * is used instead (ie useful for 'view page' function).
      * 
      * @param token the authentication token retrieved when calling the login 
method
-     * @param spaceKey in which space is our page
-     * @param pageId id of page to get rendered HTML
+     * @param spaceKey unused. We have to have since it's in the Confluence 
XMLRPC API but it doesn't seem to be used.
+     * @param pageId the id of page to get rendered HTML. A getPage() call 
should be done to get the pageId. The
+     *        pageId can be in any format since this API will support any 
server side system implementing it.
      * @param content if this is set, it will replace the original content for 
rendering
-     * @return string representing rendered content of page as HTML
+     * @return the string representing the rendered content of the page as HTML
      * @throws XWikiException in case of error
      */
     public String renderContent(String token, String spaceKey, String pageId, 
String content)

Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java
    2007-11-23 14:03:08 UTC (rev 6051)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java
    2007-11-23 16:28:09 UTC (rev 6052)
@@ -80,6 +80,13 @@
         throws XWikiException
     {
         XWiki xwiki = context.getWiki();
+
+        // First verify that the pageId is valid. It must be of the form 
Space.Page.
+        if (pageId.indexOf('.') == -1) {
+            throw exception("The page format for [" + pageId
+                + "] is invalid. A page id must be of the form Space.Page");
+        }
+
         if (!pageId.contains(PAGE_VERSION_SEPARATOR)) {
             // Current version of document
             if (xwiki.exists(pageId, context)) {
@@ -90,7 +97,7 @@
 
                 return xwiki.getDocument(pageId, context);
             } else {
-                throw exception("The page '" + pageId + "' does not exist.");
+                throw exception("The page [" + pageId + "] does not exist.");
             }
         } else {
             int i = pageId.indexOf(PAGE_VERSION_SEPARATOR);
@@ -105,7 +112,7 @@
                 XWikiDocument currentDoc = xwiki.getDocument(fullName, 
context);
                 return xwiki.getDocument(currentDoc, version, context);
             } else {
-                throw exception("The page '" + fullName + "' does not exist.");
+                throw exception("The page [" + fullName + "] does not exist.");
             }
         }
     }

Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/client/XWikiClient.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/client/XWikiClient.java
     2007-11-23 14:03:08 UTC (rev 6051)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/client/XWikiClient.java
     2007-11-23 16:28:09 UTC (rev 6052)
@@ -148,6 +148,14 @@
      * rendered as if it were the body of the page (useful for a 'preview 
page' function). If it's
      * not provided, then the existing content of the page is used instead (ie 
useful for 'view
      * page' function).
+     *
+     * @param spaceKey unused. We have to have since it's in the Confluence 
XMLRPC API but it doesn't seem to be used.
+     * @param pageId the id of page to get rendered HTML. A getPage() call 
should be done to get the pageId. The
+     *        pageId can be in any format since this API will support any 
server side system implementing it.
+     * @param content if this is set, it will replace the original content for 
rendering
+     * @return the string representing the rendered content of the page as HTML
+     * @throws XWikiClientException in case of error
+     * @throws XWikiClientRemoteException in case of error
      */
     String renderContent(String spaceKey, String pageId, String content)
         throws XWikiClientException, XWikiClientRemoteException;

Modified: 
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java
===================================================================
--- 
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java
     2007-11-23 14:03:08 UTC (rev 6051)
+++ 
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java
     2007-11-23 16:28:09 UTC (rev 6052)
@@ -1,9 +1,8 @@
 package com.xpn.xwiki.it.xmlrpc;
 
-import java.util.List;
-
 import com.xpn.xwiki.it.xmlrpc.framework.AbstractXmlRpcTestCase;
 import com.xpn.xwiki.xmlrpc.client.XWikiClientException;
+import com.xpn.xwiki.xmlrpc.client.XWikiClientRemoteException;
 import com.xpn.xwiki.xmlrpc.model.Page;
 import com.xpn.xwiki.xmlrpc.model.PageHistorySummary;
 import com.xpn.xwiki.xmlrpc.model.PageSummary;
@@ -11,7 +10,9 @@
 import com.xpn.xwiki.xmlrpc.model.swizzle.PageImpl;
 import com.xpn.xwiki.xmlrpc.model.swizzle.SpaceImpl;
 
+import java.util.List;
 
+
 public class PagesTest extends AbstractXmlRpcTestCase
 {
        private String spaceKey;
@@ -215,9 +216,18 @@
             // ok, continue
         }
     }
-    
-//    public void testExceptions() throws Exception
-//    {
-//        rpc.getPage("NotExistingId");
-//    }
+
+    /**
+     * Verify that pageId must be of the form Space.Page when the xmlrpc 
server is XWiki.
+     */
+    public void testRenderContentWithInvalidPageId()
+    {
+        try {
+            rpc.renderContent("unused", "InvalidPageId", "Dummy content");
+            fail("Should have received an exception here since the page id 
format is invalid");
+        } catch (Exception expected) {
+            assertTrue(expected.getMessage().contains("The page format for 
[InvalidPageId] is invalid. A page id "
+                + "must be of the form Space.Page"));
+        }
+    }
 }

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to