Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java (revision 25230) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/DomainObjectFactory.java (working copy) @@ -197,7 +197,8 @@ result.setModifier(document.getContentAuthor()); result.setHomePage(document.getName().equals("WebHome")); result.setLanguage(document.getLanguage()); - + result.setSyntaxId(document.getSyntaxId()); + return result; } @@ -221,6 +222,7 @@ result.setModifier(""); result.setHomePage(false); result.setLanguage(""); + result.setSyntaxId(""); return result; } 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,8 @@ import java.util.List; import java.util.Map; import java.util.Vector; +import java.util.HashMap; +import java.io.StringReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,6 +47,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; @@ -130,8 +141,11 @@ String version = this.xwikiApi.getVersion(); Integer majorVersion = null; Integer minorVersion = null; - ServerInfo serverInfo = new ServerInfo(); + Map serverInfoMap = new HashMap(); + serverInfoMap.put("DefaultSyntax", xwikiApi.getDefaultDocumentSyntax()); + serverInfoMap.put("ConfiguredSyntaxes", xwikiApi.getConfiguredSyntaxes()); + ServerInfo serverInfo = new ServerInfo(serverInfoMap); if (version != null) { serverInfo.setBuildId(version); if (version.indexOf('.') != -1) { @@ -435,6 +449,11 @@ page.setLanguage(""); } + /* If the syntax field is null then set it to the default wiki syntax */ + if (page.getSyntaxId() == null) { + page.setSyntaxId(xwikiApi.getDefaultDocumentSyntax()); + } + /* Build the extended id from the page id */ XWikiExtendedId extendedId = new XWikiExtendedId(page.getId()); @@ -556,6 +575,11 @@ } } + if(page.getSyntaxId() != null && !(page.getSyntaxId().equals(""))) + { + doc.setSyntaxId(page.getSyntaxId()); + } + doc.setContent(page.getContent()); doc.setTitle(page.getTitle()); doc.setParent(page.getParentId()); /* Allow reparenting */ @@ -812,7 +836,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 +1370,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/model/XWikiPage.java =================================================================== --- xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/model/XWikiPage.java (revision 25230) +++ xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/model/XWikiPage.java (working copy) @@ -72,4 +72,14 @@ { return getList("translations"); } + + public String getSyntaxId() + { + return super.getString("syntaxId"); + } + + public void setSyntaxId(String syntaxId) + { + super.setString("syntaxId", syntaxId); + } } 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; - }