Index: src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- src/main/java/com/xpn/xwiki/XWiki.java (revision 23262)
+++ src/main/java/com/xpn/xwiki/XWiki.java Thu Sep 03 20:13:56 CEST 2009
@@ -92,6 +92,7 @@
import org.xwiki.observation.event.DocumentUpdateEvent;
import org.xwiki.query.QueryException;
import org.xwiki.rendering.macro.wikibridge.WikiMacroInitializer;
+import org.xwiki.rendering.syntax.Syntax;
import com.xpn.xwiki.api.Api;
import com.xpn.xwiki.api.Document;
@@ -3897,7 +3898,8 @@
} else {
// Note: the Script macro in the new rendering checks for programming rights for the document in
// the xwiki context.
- result = contentdoc.getRenderedContent(context);
+ result = contentdoc.getRenderedContent(contentdoc.getTranslatedContent(context), contentdoc.getSyntaxId(),
+ Syntax.XHTML_1_0.toIdString(), false, context);
}
} else {
// We stay in the included document context
@@ -3912,7 +3914,8 @@
try {
originalDoc = context.getDoc();
context.put("doc", doc);
- result = contentdoc.getRenderedContent(context);
+ result = contentdoc.getRenderedContent(contentdoc.getTranslatedContent(context), contentdoc.getSyntaxId(),
+ Syntax.XHTML_1_0.toIdString(), false, context);
} finally {
context.put("doc", originalDoc);
}
Index: src/test/java/com/xpn/xwiki/doc/XWikiDocumentTest.java
===================================================================
--- src/test/java/com/xpn/xwiki/doc/XWikiDocumentTest.java (revision 21967)
+++ src/test/java/com/xpn/xwiki/doc/XWikiDocumentTest.java Thu Sep 03 21:45:50 CEST 2009
@@ -688,7 +688,7 @@
this.document.setContent("*bold*");
this.document.setSyntaxId("xwiki/1.0");
- this.mockXWikiRenderingEngine.expects(once()).method("renderDocument").will(returnValue("bold"));
+ this.mockXWikiRenderingEngine.expects(once()).method("renderText").will(returnValue("bold"));
assertEquals("bold", this.document.getRenderedContent(getContext()));
@@ -699,7 +699,7 @@
this.mockXWiki.stubs().method("getLanguagePreference").will(returnValue("fr"));
this.mockXWikiStoreInterface.stubs().method("loadXWikiDoc").will(returnValue(this.translatedDocument));
- this.mockXWikiRenderingEngine.expects(once()).method("renderDocument").will(returnValue("italic"));
+ this.mockXWikiRenderingEngine.expects(once()).method("renderText").will(returnValue("italic"));
assertEquals("italic", this.document.getRenderedContent(getContext()));
}
Index: src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (revision 23266)
+++ src/main/java/com/xpn/xwiki/doc/XWikiDocument.java Fri Sep 04 09:29:51 CEST 2009
@@ -519,42 +519,14 @@
setContent(renderXDOM(content, getSyntax()));
}
- public String getRenderedContent(Syntax targetSyntax, XWikiContext context) throws XWikiException
+ public String getRenderedContent(XWikiContext context) throws XWikiException
{
- // Note: We are currently duplicating code from the other getRendered signature since there are
- // some unresolved issues with saving/restoring the context in some cases (need to be investigated),
- // for example in the Admin Import page.
-
- String renderedContent;
- Object isInRenderingEngine = context.get("isInRenderingEngine");
-
- try {
- // This tells display() methods that we are inside the rendering engine and thus
- // that they can return wiki syntax and not HTML syntax (which is needed when
- // outside the rendering engine, i.e. when we're inside templates using only
- // Velocity for example).
- context.put("isInRenderingEngine", true);
-
- // If the Syntax id is "xwiki/1.0" then use the old rendering subsystem. Otherwise use the new one.
- if (is10Syntax()) {
- renderedContent = context.getWiki().getRenderingEngine().renderDocument(this, context);
- } else {
- renderedContent =
- performSyntaxConversion(getTranslatedContent(context), getSyntaxId(), targetSyntax, true);
+ return getRenderedContent(Syntax.XHTML_1_0, context);
- }
+ }
- } finally {
- if (isInRenderingEngine != null) {
- context.put("isInRenderingEngine", isInRenderingEngine);
- } else {
- context.remove("isInRenderingEngine");
- }
- }
- return renderedContent;
- }
- public String getRenderedContent(XWikiContext context) throws XWikiException
+ public String getRenderedContent(Syntax targetSyntax, XWikiContext context) throws XWikiException
{
- return getRenderedContent(Syntax.XHTML_1_0, context);
+ return getRenderedContent(getTranslatedContent(context), getSyntaxId(), targetSyntax.toIdString(), context);
}
/**
@@ -578,13 +550,30 @@
*/
public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId, XWikiContext context)
{
+ return getRenderedContent(text, sourceSyntaxId, targetSyntaxId, true, context);
+ }
+
+ /**
+ * @param text the text to render
+ * @param sourceSyntaxId the id of the Syntax used by the passed text (for example: "xwiki/1.0")
+ * @param targetSyntaxId the id of the syntax in which to render the document content
+ * @param isolateContext if true then this document's instance is put in the xwiki context as the current doc and
+ * thus the rendering is done in the context of this document
+ * @return the given text rendered in the context of this document using the passed Syntax
+ * @since 2.0M3
+ */
+ public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId, boolean isolateContext,
+ XWikiContext context)
+ {
String result;
HashMap backup = new HashMap();
Object isInRenderingEngine = context.get("isInRenderingEngine");
try {
+ if (isolateContext) {
- backupContext(backup, context);
- setAsContextDoc(context);
+ backupContext(backup, context);
+ setAsContextDoc(context);
+ }
-
+
// This tells display() methods that we are inside the rendering engine and thus
// that they can return wiki syntax and not HTML syntax (which is needed when
// outside the rendering engine, i.e. when we're inside templates using only
@@ -606,7 +595,9 @@
LOG.warn(e);
result = "";
} finally {
+ if (isolateContext) {
- restoreContext(backup, context);
+ restoreContext(backup, context);
+ }
if (isInRenderingEngine != null) {
context.put("isInRenderingEngine", isInRenderingEngine);
} else {
@@ -5142,7 +5133,7 @@
public static void backupContext(Map backup, XWikiContext context)
{
backup.put("doc", context.getDoc());
- VelocityManager velocityManager = (VelocityManager) Utils.getComponent(VelocityManager.class);
+ VelocityManager velocityManager = Utils.getComponent(VelocityManager.class);
VelocityContext vcontext = velocityManager.getVelocityContext();
if (vcontext != null) {
backup.put("vdoc", vcontext.get("doc"));
@@ -5166,7 +5157,6 @@
VelocityManager velocityManager = Utils.getComponent(VelocityManager.class);
VelocityContext vcontext = velocityManager.getVelocityContext();
- Map gcontext = (Map) context.get("gcontext");
if (vcontext != null) {
if (backup.get("vdoc") != null) {
vcontext.put("doc", backup.get("vdoc"));
@@ -5181,6 +5171,7 @@
}
}
+ Map gcontext = (Map) context.get("gcontext");
if (gcontext != null) {
if (backup.get("gdoc") != null) {
gcontext.put("doc", backup.get("gdoc"));