is needed at all after the refactoring Florin did.
The rationale for this interface was that before we were creating a Java proxy object in
order to wrap each invocation inside a context initialization-cleanup. And since proxies
could be created only by using interfaces we needed the API to be expressed as an
interface.
Now that the context initialization/cleanup is handled through filters there is no more
need for the proxy and hence for that interface.
Moreover this interface exposes method signature using XMLRPC types (so Maps instead of
model objects). So it might also be confusing.
I am +1 for removing it so that the code is even more clean.
-Fabio
On Nov 26, 2009, at 5:17 PM, tmortagne (SVN) wrote:
Author: tmortagne
Date: 2009-11-26 17:17:04 +0100 (Thu, 26 Nov 2009)
New Revision: 25290
Added:
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/RenderingTest.java
Modified:
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java
platform/core/branches/xwiki-core-2.0/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-client/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcClient.java
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java
Log:
XWIKI-4464: Extend the XmlRpc API with new rendering features
* Apply patch from Florin Ciubotaru:
** New getRenderedContendMethods added to the api(We still need a few votes on devs for
these to get commited). Completed the client with the new additions.
** Added integration tests.
Modified:
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java
===================================================================
---
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java 2009-11-26
15:38:04 UTC (rev 25289)
+++
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java 2009-11-26
16:17:04 UTC (rev 25290)
@@ -62,6 +62,7 @@
addTestCase(suite, org.xwiki.xmlrpc.XWikiClassesTest.class);
addTestCase(suite, org.xwiki.xmlrpc.XWikiObjectsTest.class);
addTestCase(suite, org.xwiki.xmlrpc.SearchTest.class);
+ addTestCase(suite, org.xwiki.xmlrpc.RenderingTest.class);
return new XWikiTestSetup(suite);
}
Copied:
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/RenderingTest.java
(from rev 25288,
enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/RenderingTest.java)
===================================================================
---
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/RenderingTest.java
(rev 0)
+++
enterprise/branches/xwiki-enterprise-2.0/distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/RenderingTest.java 2009-11-26
16:17:04 UTC (rev 25290)
@@ -0,0 +1,145 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *
+ */
+package org.xwiki.xmlrpc;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.xwiki.xmlrpc.model.XWikiPage;
+
+public class RenderingTest extends AbstractXWikiXmlRpcTest
+{
+ public void testGetInputSyntaxes() throws XmlRpcException
+ {
+ List<String> syntaxes = rpc.getInputSyntaxes();
+
+ TestUtils.banner("TEST: getInputSyntaxes()");
+ System.out.format("%d conversion input syntaxes found:\n",
syntaxes.size());
+ for (String syntaxId : syntaxes) {
+ System.out.format("%s\n", syntaxId);
+ }
+ Assert.assertTrue(syntaxes.size() != 0);
+ }
+
+ public void testGetOutputSyntaxes() throws XmlRpcException
+ {
+ List<String> syntaxes = rpc.getOutputSyntaxes();
+
+ TestUtils.banner("TEST: getOutputSyntaxes()");
+ System.out.format("%d conversion output syntaxes found:\n",
syntaxes.size());
+ for (String syntaxId : syntaxes) {
+ System.out.format("%s\n", syntaxId);
+ }
+ Assert.assertTrue(syntaxes.size() != 0);
+ }
+
+ public void testConvert() throws XmlRpcException
+ {
+ String inputXWiki =
+ "**BoldText**//ItalicText//" + String.format("%n") +
"==h2Text==" + String.format("%n") + "normalText";
+ String inputXhtml =
+
"<div><p><strong>boldText</strong><br/><em>ItalicText</em></p>"
+ String.format("%n")
+ + "<h2
id=\"h2Text\"><span>h2Text</span></h2><p>normalText</p></div>";
+
+ TestUtils.banner("TEST: convert()");
+ System.out.format("\nTesting xwiki/2.0 -> xhtml/1.0
conversion\n");
+ System.out.format("Input text:\n%s", inputXWiki);
+
+ String outputXhtml = rpc.convert(inputXhtml, "xwiki/2.0",
"xhtml/1.0");
+
+ System.out.format("\nOutput text:\n%s", outputXhtml);
+
+ Assert.assertNotNull(outputXhtml);
+ Assert.assertFalse(outputXhtml.equals(""));
+ Assert.assertTrue(outputXhtml.contains("strong"));
+ Assert.assertTrue(outputXhtml.contains("normalText"));
+ Assert.assertTrue(outputXhtml.contains("ItalicText"));
+
+ System.out.format("\nTesting xhtml/1.0 -> xwiki/2.0
conversion\n");
+ System.out.format("Input text:\n%s", inputXhtml);
+
+ String outputXWiki = rpc.convert(inputXhtml, "xhtml/1.0",
"xwiki/2.0");
+
+ System.out.format("\nOutput text:\n%s\n", outputXWiki);
+
+ Assert.assertNotNull(outputXWiki);
+ Assert.assertFalse(outputXhtml.equals(""));
+ Assert.assertTrue(outputXhtml.contains("normalText"));
+ Assert.assertTrue(outputXhtml.contains("ItalicText"));
+ }
+
+ public void testGetRenderedContent() throws XmlRpcException
+ {
+ String pageContent = "**Text in
Bold**{{velocity}}VelocityCode{{/velocity}}";
+
+ XWikiPage page = new XWikiPage();
+ page.setId(TestConstants.TEST_PAGE);
+ page.setContent(pageContent);
+ page.setSyntaxId("xwiki/2.0");
+
+ TestUtils.banner("TEST: getRenderedContent()");
+ System.out.format("\nCalling getRenderedContent for page %s\n",
page.getId());
+ System.out.format("\nWiki content is:\n%s\n", pageContent);
+
+ rpc.storePage(page);
+
+ try {
+ String renderedContent = rpc.getRenderedContent(page.getId(),
"annotatedxhtml/1.0");
+
+ System.out.format("\nObtained rendered content:\n%s\n\n",
renderedContent);
+
+ Assert.assertTrue(renderedContent.contains("Text in Bold"));
+ Assert.assertTrue(renderedContent.contains("startmacro"));
+ } finally {
+ rpc.removePage(page.getId());
+ }
+ }
+
+ public void testRenderPageContent() throws XmlRpcException
+ {
+ String pageContent = "**Text in
Bold**{{velocity}}VelocityCode{{/velocity}}";
+
+ XWikiPage page = new XWikiPage();
+ page.setId(TestConstants.TEST_PAGE);
+ page.setContent(pageContent);
+ page.setSyntaxId("xwiki/2.0");
+
+ TestUtils.banner("TEST: renderPageContent");
+ System.out.format("\nCalling renderPageContent with context as page
%s\n", TestConstants.TEST_PAGE);
+ System.out.format("\nWiki content is:\n%s\n", pageContent);
+
+ rpc.storePage(page);
+
+ try {
+ String renderedContent =
+ rpc.renderPageContent(page.getId(), page.getContent(),
page.getSyntaxId(), "annotatedxhtml/1.0");
+
+ System.out.format("\nObtained rendered content:\n%s\n\n",
renderedContent);
+
+ Assert.assertTrue(renderedContent.contains("Text in Bold"));
+ Assert.assertTrue(renderedContent.contains("startmacro"));
+ } finally {
+ rpc.removePage(page.getId());
+ }
+ }
+}
Modified:
platform/core/branches/xwiki-core-2.0/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java
===================================================================
---
platform/core/branches/xwiki-core-2.0/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java 2009-11-26
15:38:04 UTC (rev 25289)
+++
platform/core/branches/xwiki-core-2.0/xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java 2009-11-26
16:17:04 UTC (rev 25290)
@@ -1446,4 +1446,47 @@
}
return syntaxes;
}
+
+ /**
+ * Renders a text in the context of a wiki page.
+ *
+ * @param token The authentication token.
+ * @param pageId The id of the page.
+ * @param content The context to be rendered.
+ * @param sourceSyntaxId The syntax of the content.
+ * @param targetSyntaxId The target syntax of the rendered content
+ * @return The rendered content.
+ * @throws Exception If a invalid token is provided, an unsupported syntax id is
given or the rendering fails.
+ */
+ public String renderPageContent(String token, String pageId, String content, String
sourceSyntaxId,
+ String targetSyntaxId) throws Exception
+ {
+ XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext);
+ LOG.debug(String.format("User %s has called renderPageContent()",
user.getName()));
+
+ Document doc = XWikiUtils.getDocument(this.xwikiApi, pageId, true);
+
+ return doc.getRenderedContent(content, sourceSyntaxId, targetSyntaxId);
+ }
+
+ /**
+ * Gets the rendered content of an existing document.
+ *
+ * @param token The authentication token.
+ * @param pageId The id of the page.
+ * @param syntaxId The target syntax of the rendered content
+ * @return The rendered content
+ * @throws Exception If a invalid token is provided, an unsupported syntax id is
given or the rendering fails.
+ */
+ public String getRenderedContent(String token, String pageId, String syntaxId)
throws Exception
+ {
+ XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext);
+ LOG.debug(String.format("User %s has called getRenderedContent()",
user.getName()));
+
+ Document doc = XWikiUtils.getDocument(this.xwikiApi, pageId, true);
+ SyntaxFactory syntaxFactory = Utils.getComponent(SyntaxFactory.class);
+ Syntax syntax = syntaxFactory.createSyntaxFromIdString(syntaxId);
+
+ return doc.getRenderedContent(syntax);
+ }
}
Modified:
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-client/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcClient.java
===================================================================
---
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-client/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcClient.java 2009-11-26
15:38:04 UTC (rev 25289)
+++
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-client/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcClient.java 2009-11-26
16:17:04 UTC (rev 25290)
@@ -932,6 +932,85 @@
}
/**
+ * Converts a wiki source from a syntax to another syntax.
+ *
+ * @param source The content to be converted.
+ * @param initialSyntaxId The initial syntax of the source.
+ * @param targetSyntaxId The final syntax of the returned content.
+ * @return The converted source.
+ * @throws XmlRpcException An invalid token is provided, the syntaxId is not
supported, the source is invalid or the
+ * conversion fails.
+ */
+ public String convert( String source, String initialSyntaxId, String
targetSyntaxId)
+ throws XmlRpcException
+ {
+ return (String) invokeRpc("convert", this.token, source,
initialSyntaxId, targetSyntaxId);
+ }
+
+ /**
+ * Gets all syntaxes supported by the rendering parsers as an input for a syntax
conversion.
+ *
+ * @return A list containing all syntaxes supported by rendering parsers.
+ * @throws Exception An invalid token is provided or the syntax lookup fails.
+ */
+ public List<String> getInputSyntaxes() throws XmlRpcException
+ {
+ List<String> result = new ArrayList<String>();
+ Object[] objects = (Object[]) invokeRpc("getInputSyntaxes",
this.token);
+ for(Object object:objects)
+ {
+ result.add((String)object);
+ }
+ return result;
+ }
+
+ /**
+ * Gets all syntaxes supported by the rendering as an output for a syntax
conversion.
+ *
+ * @return A list containing all syntaxes supported by renderers.
+ * @throws XmlRpcException An invalid token is provided or the syntax lookup fails.
+ */
+ public List<String> getOutputSyntaxes() throws XmlRpcException
+ {
+ List<String> result = new ArrayList<String>();
+ Object[] objects = (Object[]) invokeRpc("getOutputSyntaxes",
this.token);
+ for(Object object:objects)
+ {
+ result.add((String)object);
+ }
+ return result;
+ }
+
+ /**
+ * Renders a text in the context of a wiki page.
+ *
+ * @param pageId The id of the page.
+ * @param content The contenxt to be rendered.
+ * @param sourceSyntaxId The syntax of the content.
+ * @param targetSyntaxId The target syntax of the rendered content
+ * @return The rendered content.
+ * @throws XmlRpcException If a invalid token is provided, an unsuported syntax id
is given or the rendering fails.
+ */
+ public String renderPageContent(String pageId, String content, String
sourceSyntaxId,
+ String targetSyntaxId) throws XmlRpcException
+ {
+ return (String) invokeRpc("renderPageContent", this.token, pageId,
content, sourceSyntaxId, targetSyntaxId);
+ }
+
+ /**
+ * Gets the rendered content of an existing document.
+ *
+ * @param pageId The id of the page.
+ * @param syntaxId The target syntax of the rendered content
+ * @return The renderded content
+ * @throws Exception If a invalid token is provided, an unsuported syntax id is
given or the rendering fails.
+ */
+ public String getRenderedContent(String pageId, String syntaxId) throws
XmlRpcException
+ {
+ return (String) invokeRpc("getRenderedContent", this.token, pageId,
syntaxId);
+ }
+
+ /**
* Utility method for invoking remote RPC methods.
*
* @param methodName
Modified:
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java
===================================================================
---
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java 2009-11-26
15:38:04 UTC (rev 25289)
+++
platform/core/branches/xwiki-core-2.0/xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java 2009-11-26
16:17:04 UTC (rev 25290)
@@ -63,6 +63,11 @@
public String renderContent(String token, String space, String pageId, String
content) throws Exception;
+ public String renderPageContent(String token, String pageId, String content, String
sourceSyntaxId,
+ String targetSyntaxId) throws Exception;
+
+ public String getRenderedContent(String token, String pageId, String syntaxId)
throws Exception;
+
public String convert(String token, String source, String initialSyntaxId, String
targetSyntaxId) throws Exception;
public List<String> getInputSyntaxes(String token) throws Exception;
_______________________________________________
notifications mailing list
notifications(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications