Hi Arun,
On Aug 8, 2009, at 10:29 PM, arun (SVN) wrote:
Author: arun
Date: 2009-08-08 22:29:54 +0200 (Sat, 08 Aug 2009)
New Revision: 22431
Modified:
sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/WikiImporter.java
sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/internal/ConfluenceWikiImporter.java
sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/internal/MediaWikiImporter.java
sandbox/gsoc/importexport/xwiki-core-importer/src/test/java/org/
xwiki/platform/mediawiki/MediaWikiTest.java
Log:
[Changes]
New Rendering Module Syntax Converter component is used to conver
Wiki Syntax.
Modified: sandbox/gsoc/importexport/xwiki-core-importer/src/main/
java/org/xwiki/platform/WikiImporter.java
===================================================================
--- sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/WikiImporter.java 2009-08-08 19:44:33 UTC (rev 22430)
+++ sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/WikiImporter.java 2009-08-08 20:29:54 UTC (rev 22431)
@@ -44,9 +44,9 @@
T parse(byte[] bytes) throws Exception;
/**
- * Creates XWiki Pages based on the given Wiki Instance and
Wiki Type
+ * Import Wiki content based on the given Wiki Instance and
Wiki Type
*
- * @param wiki Wiki object returned by {@link
#processInputDump(byte[], String)}
+ * @param wiki Wiki object returned after parsing the input.
* @return Summary of import process as a list.
* @throws Exception
*/
Modified: sandbox/gsoc/importexport/xwiki-core-importer/src/main/
java/org/xwiki/platform/internal/ConfluenceWikiImporter.java
===================================================================
--- sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/internal/ConfluenceWikiImporter.java 2009-08-08
19:44:33 UTC (rev 22430)
+++ sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/internal/ConfluenceWikiImporter.java 2009-08-08
20:29:54 UTC (rev 22431)
@@ -20,6 +20,7 @@
package org.xwiki.platform.internal;
import java.io.ByteArrayInputStream;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -38,11 +39,11 @@
import org.xwiki.platform.internal.confluence.ConfluenceSpace;
import org.xwiki.platform.internal.confluence.ConfluenceWiki;
import org.xwiki.platform.internal.confluence.ProcessConfluenceXml;
-import org.xwiki.platform.parser.ImportWikiParser;
-import org.xwiki.platform.renderer.ImportWikiRenderer;
import org.xwiki.platform.wiki.Summary;
+import org.xwiki.rendering.converter.Converter;
import org.xwiki.rendering.parser.Syntax;
-import org.xwiki.rendering.parser.SyntaxType;
+import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
+import org.xwiki.rendering.renderer.printer.WikiPrinter;
/**
* Confluence Wiki Importer processes the Input data and creates
wiki pages.
@@ -66,11 +67,8 @@
private DocumentAccessBridge docAccessBridge;
@Requirement
- private ImportWikiParser parser;
+ private Converter converter;
- @Requirement
- private ImportWikiRenderer renderer;
-
/**
* Process Input data and returns Wiki object of Confluence Wiki
Type.
* <p>
@@ -153,7 +151,6 @@
{
Map<String, ConfluenceRevision> revisions =
page.getConfluenceRevisions();
Iterator<String> iterator = revisions.keySet().iterator();
- Syntax syntax = new Syntax(SyntaxType.CONFLUENCE, "1.0");
String title = "";
// Title
@@ -169,7 +166,9 @@
// Revisions.
while (iterator.hasNext()) {
ConfluenceRevision rev = revisions.get(iterator.next());
- String text =
this
.renderer.renderFromWikiXdom(this.parser.getWikiXdom(rev.getText(),
syntax));
+ WikiPrinter printer = new DefaultWikiPrinter();
+ converter.convert(new StringReader(rev.getText()),
Syntax.CONFLUENCE_1_0, Syntax.XWIKI_2_0, printer);
+ String text = printer.toString();
this.docAccessBridge.setDocumentContent(title, text,
rev.getComment(), rev.getMinorEdit());
}
Modified: sandbox/gsoc/importexport/xwiki-core-importer/src/main/
java/org/xwiki/platform/internal/MediaWikiImporter.java
===================================================================
--- sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/internal/MediaWikiImporter.java 2009-08-08 19:44:33
UTC (rev 22430)
+++ sandbox/gsoc/importexport/xwiki-core-importer/src/main/java/org/
xwiki/platform/internal/MediaWikiImporter.java 2009-08-08 20:29:54
UTC (rev 22431)
@@ -20,6 +20,7 @@
package org.xwiki.platform.internal;
import java.io.ByteArrayInputStream;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
@@ -34,11 +35,11 @@
import org.xwiki.platform.internal.mediawiki.MediaWikiPage;
import org.xwiki.platform.internal.mediawiki.MediaWikiRevision;
import org.xwiki.platform.internal.mediawiki.ProcessMediaWikiXml;
-import org.xwiki.platform.parser.ImportWikiParser;
-import org.xwiki.platform.renderer.ImportWikiRenderer;
import org.xwiki.platform.wiki.Summary;
+import org.xwiki.rendering.converter.Converter;
import org.xwiki.rendering.parser.Syntax;
-import org.xwiki.rendering.parser.SyntaxType;
+import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
+import org.xwiki.rendering.renderer.printer.WikiPrinter;
/**
* Default Wiki Importer - Imports other Wiki types into XWiki.
@@ -62,11 +63,8 @@
private DocumentAccessBridge docAccessBridge;
@Requirement
- private ImportWikiParser parser;
+ private Converter converter;
- @Requirement
- private ImportWikiRenderer renderer;
-
public void initialize() throws InitializationException
{
getLogger().debug("MediaWiki Importer Intialized");
@@ -113,16 +111,18 @@
private List<Summary> importMediaWiki(MediaWiki mediawiki)
throws Exception
{
List<Summary> wikiSummary = new ArrayList<Summary>();
- Syntax syntax = new Syntax(SyntaxType.MEDIAWIKI, "1.0");
// For every mediawiki page
for (MediaWikiPage mediaWikiPage : mediawiki.getWikiPages()) {
// Fore every mediawiki revision of a page
for (MediaWikiRevision mediaWikiRevision :
mediaWikiPage.getRevisions()) {
- // Read the body content parse it to xdom and
render it into XWiki Syntax.
- String text =
-
this
.renderer
.renderFromWikiXdom
(this.parser.getWikiXdom(mediaWikiRevision.getText(), syntax));
+ // Read the body content convert it into XWiki
Syntax.
+ WikiPrinter printer = new DefaultWikiPrinter();
+ converter.convert(new
StringReader(mediaWikiRevision.getText()), Syntax.MEDIAWIKI_1_0,
+ Syntax.XWIKI_2_0, printer);
+ String text = printer.toString();
+
// Create the page using document access bridge
this.docAccessBridge.setDocumentContent(mediaWikiPage.getPageName(),
text, mediaWikiRevision
.getComment(), mediaWikiRevision.getMinorEdit());
Modified: sandbox/gsoc/importexport/xwiki-core-importer/src/test/
java/org/xwiki/platform/mediawiki/MediaWikiTest.java
===================================================================
--- sandbox/gsoc/importexport/xwiki-core-importer/src/test/java/org/
xwiki/platform/mediawiki/MediaWikiTest.java 2009-08-08 19:44:33 UTC
(rev 22430)
+++ sandbox/gsoc/importexport/xwiki-core-importer/src/test/java/org/
xwiki/platform/mediawiki/MediaWikiTest.java 2009-08-08 20:29:54 UTC
(rev 22431)
@@ -19,15 +19,21 @@
*/
package org.xwiki.platform.mediawiki;
+import java.io.StringReader;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import junit.framework.TestCase;
+import org.xwiki.component.embed.EmbeddableComponentManager;
import org.xwiki.platform.internal.mediawiki.MediaWiki;
import org.xwiki.platform.internal.mediawiki.MediaWikiPage;
import org.xwiki.platform.internal.mediawiki.ProcessMediaWikiXml;
+import org.xwiki.rendering.converter.Converter;
+import org.xwiki.rendering.parser.Syntax;
+import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
+import org.xwiki.rendering.renderer.printer.WikiPrinter;
/**
* @version $Id$
@@ -66,5 +72,21 @@
}
+ public void renderXWiki20SyntaxAsXHTML() throws Exception
+ {
+ // Initialize Rendering components and allow getting
instances
+ EmbeddableComponentManager ecm = new
EmbeddableComponentManager();
+ ecm.initialize(this.getClass().getClassLoader());
This should be getComponentManager() instead from
AbstractComponentTestCase
Thanks
-Vincent
+
+ // Use a the Converter component to convert between one
syntax to another.
+ Converter converter = ecm.lookup(Converter.class);
+ // Convert input in XWiki Syntax 2.0 into XHTML. The result
is stored in the printer.
+ WikiPrinter printer = new DefaultWikiPrinter();
+ converter.convert(new StringReader("This is **bold**"),
Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
+
+ assertEquals("<p>This is
<strong>bold</strong></p>",
printer.toString());
+ }
+