use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultIOTargetServiceTest method testGetterWhenTargetIsNonTypedObjectProperty.
@Test
public void testGetterWhenTargetIsNonTypedObjectProperty() throws Exception {
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
getMockery().checking(new Expectations() {
{
// target will be parsed as document, because document is the default
allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space.Page^XWiki.Class", "property"));
will(returnValue(dmb));
oneOf(dmb).getContent();
will(returnValue("defcontent"));
oneOf(dmb).getSyntax();
will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
}
});
String reference = "wiki:Space\\.Page^XWiki\\.Class.property";
assertEquals("defcontent", ioTargetService.getSource(reference));
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultIOTargetServiceTest method testGettersWhenTargetIsNonTypedRelativeDocument.
@Test
public void testGettersWhenTargetIsNonTypedRelativeDocument() throws Exception {
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
getMockery().checking(new Expectations() {
{
// default resolver should be used
allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Space", "Page"));
will(returnValue(dmb));
oneOf(dmb).getContent();
will(returnValue("defcontent"));
oneOf(dmb).getSyntax();
will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
}
});
String reference = "Space.Page";
assertEquals("defcontent", ioTargetService.getSource(reference));
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class AbstractAnnotationMaintainer method renderPlainText.
/**
* Helper method to render the plain text version of the passed content.
*
* @param content the content to render in plain text
* @param syntaxId the source syntax of the content to render
* @throws Exception if anything goes wrong while rendering the content
* @return the normalized plain text rendered content
*/
private String renderPlainText(String content, String syntaxId) throws Exception {
PrintRenderer renderer = componentManager.getInstance(PrintRenderer.class, "normalizer-plain/1.0");
// parse
Parser parser = componentManager.getInstance(Parser.class, syntaxId);
XDOM xdom = parser.parse(new StringReader(content));
// run transformations -> although it's going to be at least strange to handle rendered content since there
// is no context
Syntax sourceSyntax = Syntax.valueOf(syntaxId);
TransformationManager transformationManager = componentManager.getInstance(TransformationManager.class);
transformationManager.performTransformations(xdom, sourceSyntax);
// render
WikiPrinter printer = new DefaultWikiPrinter();
renderer.setPrinter(printer);
xdom.traverse(renderer);
return printer.toString();
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class AbstractSkin method getOutputSyntax.
@Override
public Syntax getOutputSyntax() {
Syntax targetSyntax = null;
String targetSyntaxString = getOutputSyntaxString();
if (StringUtils.isNotEmpty(targetSyntaxString)) {
targetSyntax = parseSyntax(this, targetSyntaxString);
if (targetSyntax != null) {
return targetSyntax;
}
}
Skin parent = getParent();
if (parent != null) {
targetSyntax = parent.getOutputSyntax();
}
// Fallback to the XHTML 1.0 syntax for backward compatibility
return targetSyntax != null ? targetSyntax : Syntax.XHTML_1_0;
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class XWiki method parseTemplate.
/**
* @param template the name of the template
* @param skinId the id of the skin from which to load the template
* @param context see {@link XWikiContext}
* @deprecated since 7.0M1, use {@link TemplateManager#renderFromSkin(String, Skin)} instead
*/
@Deprecated
public String parseTemplate(String template, String skinId, XWikiContext context) {
MutableRenderingContext mutableRenderingContext = getMutableRenderingContext();
Syntax currentTargetSyntax = mutableRenderingContext.getTargetSyntax();
try {
// Force rendering with XHTML 1.0 syntax for retro-compatibility
mutableRenderingContext.setTargetSyntax(Syntax.XHTML_1_0);
Skin skin = getInternalSkinManager().getSkin(skinId);
return getTemplateManager().renderFromSkin(template, skin);
} catch (Exception e) {
LOGGER.error("Error while evaluating velocity template [{}] skin [{}]", template, skinId, e);
Object[] args = { template, skinId };
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_RENDERING_VELOCITY_EXCEPTION, "Error while evaluating velocity template [{0}] from skin [{1}]", e, args);
return Util.getHTMLExceptionMessage(xe, context);
} finally {
mutableRenderingContext.setTargetSyntax(currentTargetSyntax);
}
}
Aggregations