Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java (revision 25230) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java (working copy) @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Vector; +import java.io.StringReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,6 +46,15 @@ import org.xwiki.xmlrpc.model.XWikiPage; import org.xwiki.xmlrpc.model.XWikiPageHistorySummary; import org.xwiki.xmlrpc.model.XWikiPageSummary; +import org.xwiki.rendering.renderer.PrintRendererFactory; +import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; +import org.xwiki.rendering.renderer.printer.WikiPrinter; +import org.xwiki.rendering.parser.Parser; +import org.xwiki.rendering.syntax.SyntaxFactory; +import org.xwiki.rendering.syntax.Syntax; +import org.xwiki.rendering.converter.Converter; +import org.xwiki.component.manager.ComponentLookupException; +import org.xwiki.component.manager.ComponentManager; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; @@ -812,7 +822,7 @@ * * @param token The authentication token. * @param contentId Ignored - * @param attachment The Attachment object used to identify the page id, and attachment metadata. + * @param attachmentMap The Attachment object used to identify the page id, and attachment metadata. * @param attachmentData The actual attachment data. * @return An Attachment object describing the newly added attachment. * @throws Exception An invalid token is provided or if the page does not exist or the user has not the right to @@ -1346,4 +1356,81 @@ return DomainObjectFactory.createXWikiObject(this.xwiki, this.xwikiContext, doc, object).toRawMap(); } + + /** + * Converts a wiki source from a syntax to another syntax. + * + * @param token The authentication token. + * @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 Exception An invalid token is provided, the syntaxId is not supported, the source is invalid or the + * conversion fails. + */ + public String convert(String token, String source, String initialSyntaxId, String targetSyntaxId) throws Exception + { + XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext); + try { + SyntaxFactory syntaxFactory = (SyntaxFactory) Utils.getComponent(SyntaxFactory.class); + Syntax initialSyntax = syntaxFactory.createSyntaxFromIdString(initialSyntaxId); + Syntax targetSyntax = syntaxFactory.createSyntaxFromIdString(targetSyntaxId); + WikiPrinter printer = new DefaultWikiPrinter(); + Converter converter = (Converter) Utils.getComponent(Converter.class); + converter.convert(new StringReader(source), initialSyntax, targetSyntax, printer); + + return printer.toString(); + } catch (Throwable t) { + throw new RuntimeException("Exception while performing syntax conversion.", t); + } + } + + /** + * Gets all syntaxes supported by the rendering parsers as an input for a syntax conversion. + * + * @param token The authentication token. + * @return A list containing all syntaxes supported by rendering parsers. + * @throws Exception An invalid token is provided or the syntax lookup fails. + */ + public List getInputSyntaxes(String token) throws Exception + { + XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext); + List syntaxes = new ArrayList(); + List parsers; + ComponentManager componentManager = Utils.getComponentManager(); + try { + parsers = componentManager.lookupList(Parser.class); + for (Parser parser : parsers) { + syntaxes.add(parser.getSyntax().toIdString()); + } + } catch (ComponentLookupException e) { + throw new RuntimeException("Failed to lookup the list of available parser syntaxes", e); + } + return syntaxes; + } + + /** + * Gets all syntaxes supported by the rendering as an output for a syntax conversion. + * + * @param token The authentication token. + * @return A list containing all syntaxes supported by renderers. + * @throws Exception An invalid token is provided or the syntax lookup fails. + */ + public List getOutputSyntaxes(String token) throws Exception + { + XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext); + List syntaxes = new ArrayList(); + List renderers; + ComponentManager componentManager = Utils.getComponentManager(); + try { + //TODO: use BlockRenderer + renderers = componentManager.lookupList(PrintRendererFactory.class); + for (PrintRendererFactory renderer : renderers) { + syntaxes.add(renderer.getSyntax().toIdString()); + } + } catch (ComponentLookupException e) { + throw new RuntimeException("Failed to lookup the list of available renderer syntaxes", e); + } + return syntaxes; + } } Index: xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java =================================================================== --- xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java (revision 25230) +++ xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java (working copy) @@ -63,6 +63,12 @@ public String renderContent(String token, String space, String pageId, String content) throws Exception; + public String convert(String token, String source, String initialSyntaxId, String targetSyntaxId) throws Exception; + + public List getInputSyntaxes(String token) throws Exception; + + public List getOutputSyntaxes(String token) throws Exception; + /* Comments */ public List/* List */getComments(String token, String pageId) throws Exception; @@ -106,5 +112,4 @@ public List/* List */getModifiedPagesHistory(String token, Date date, int numberOfResults, int start, boolean fromLatest) throws Exception; - }