Search in sources :

Example 6 with Syntax

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));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 7 with Syntax

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));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 8 with Syntax

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();
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) PrintRenderer(org.xwiki.rendering.renderer.PrintRenderer) StringReader(java.io.StringReader) TransformationManager(org.xwiki.rendering.transformation.TransformationManager) Syntax(org.xwiki.rendering.syntax.Syntax) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) Parser(org.xwiki.rendering.parser.Parser)

Example 9 with Syntax

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;
}
Also used : Skin(org.xwiki.skin.Skin) Syntax(org.xwiki.rendering.syntax.Syntax)

Example 10 with Syntax

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);
    }
}
Also used : Skin(org.xwiki.skin.Skin) WikiSkin(com.xpn.xwiki.internal.skin.WikiSkin) Syntax(org.xwiki.rendering.syntax.Syntax) MutableRenderingContext(org.xwiki.rendering.internal.transformation.MutableRenderingContext) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Aggregations

Syntax (org.xwiki.rendering.syntax.Syntax)35 Test (org.junit.Test)16 DocumentReference (org.xwiki.model.reference.DocumentReference)15 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)11 Expectations (org.jmock.Expectations)10 SyntaxType (org.xwiki.rendering.syntax.SyntaxType)7 ParseException (org.xwiki.rendering.parser.ParseException)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 IOException (java.io.IOException)4 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)4 Parser (org.xwiki.rendering.parser.Parser)4 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 HashMap (java.util.HashMap)3 ConfigurationSource (org.xwiki.configuration.ConfigurationSource)3 XDOM (org.xwiki.rendering.block.XDOM)3 CoreConfiguration (com.xpn.xwiki.CoreConfiguration)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AbstractInstanceFilterStreamTest (com.xpn.xwiki.internal.filter.AbstractInstanceFilterStreamTest)2 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2