Search in sources :

Example 11 with ParseException

use of org.xwiki.rendering.parser.ParseException in project xwiki-platform by xwiki.

the class RenderingScriptServiceTest method parseAndRenderWhenErrorInParse.

@Test
public void parseAndRenderWhenErrorInParse() throws Exception {
    Parser parser = this.mocker.registerMockComponent(Parser.class, "plain/1.0");
    when(parser.parse(new StringReader("some [[TODO]] stuff"))).thenThrow(new ParseException(("error")));
    Assert.assertNull(this.mocker.getComponentUnderTest().parse("some [[TODO]] stuff", "plain/1.0"));
}
Also used : StringReader(java.io.StringReader) ParseException(org.xwiki.rendering.parser.ParseException) Parser(org.xwiki.rendering.parser.Parser) Test(org.junit.Test)

Example 12 with ParseException

use of org.xwiki.rendering.parser.ParseException in project xwiki-platform by xwiki.

the class DefaultCoreConfiguration method getDefaultDocumentSyntax.

/**
 * @see CoreConfiguration#getDefaultDocumentSyntax()
 * @since 2.3M1
 */
@Override
public Syntax getDefaultDocumentSyntax() {
    // If the found value is an empty string then default to the configuration value in the main configuration
    // source.
    // TODO: In the future we would need the notion of initialized/not-initialized property values in the wiki.
    // When this is implemented modify the code below.
    String key = PREFIX + "defaultDocumentSyntax";
    String syntaxId = this.configuration.getProperty(key, String.class);
    if (StringUtils.isEmpty(syntaxId)) {
        syntaxId = this.xwikiPropertiesConfiguration.getProperty(key, Syntax.XWIKI_2_1.toIdString());
    }
    // Try to parse the syntax and if it fails defaults to the XWiki Syntax 2.1
    Syntax syntax;
    try {
        syntax = Syntax.valueOf(syntaxId);
    } catch (ParseException e) {
        this.logger.warn("Invalid default document Syntax [" + syntaxId + "], defaulting to [" + Syntax.XWIKI_2_1.toIdString() + "] instead", e);
        syntax = Syntax.XWIKI_2_1;
    }
    return syntax;
}
Also used : ParseException(org.xwiki.rendering.parser.ParseException) Syntax(org.xwiki.rendering.syntax.Syntax)

Example 13 with ParseException

use of org.xwiki.rendering.parser.ParseException in project xwiki-platform by xwiki.

the class TranslationMacro method execute.

@Override
public List<Block> execute(TranslationMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    Locale locale = parameters.getLocale() != null ? parameters.getLocale() : this.localizationContext.getCurrentLocale();
    Translation translation = this.localization.getTranslation(parameters.getKey(), locale);
    List<Block> blocks;
    if (translation != null) {
        Block block = parameters.getParameters() != null ? translation.render(locale, (Object[]) parameters.getParameters()) : translation.render(locale);
        if (block instanceof CompositeBlock) {
            blocks = block.getChildren();
        } else {
            blocks = Arrays.asList(block);
        }
        if (!context.getCurrentMacroBlock().isInline()) {
            // Make the content standalone
            blocks = Arrays.<Block>asList(new GroupBlock(blocks));
        }
    } else if (content != null) {
        blocks = this.macroContentParser.parse(content, context, false, context.getCurrentMacroBlock().isInline()).getChildren();
    } else {
        try {
            blocks = this.plainParser.parse(new StringReader(parameters.getKey())).getChildren();
            if (context.getCurrentMacroBlock().isInline()) {
                PARSERUTILS.removeTopLevelParagraph(blocks);
            }
        } catch (ParseException e) {
            throw new MacroExecutionException("Failed to parse key [" + parameters.getKey() + "]", e);
        }
    }
    return blocks;
}
Also used : Locale(java.util.Locale) Translation(org.xwiki.localization.Translation) GroupBlock(org.xwiki.rendering.block.GroupBlock) StringReader(java.io.StringReader) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) Block(org.xwiki.rendering.block.Block) GroupBlock(org.xwiki.rendering.block.GroupBlock) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) ParseException(org.xwiki.rendering.parser.ParseException)

Aggregations

ParseException (org.xwiki.rendering.parser.ParseException)13 StringReader (java.io.StringReader)9 Block (org.xwiki.rendering.block.Block)6 XDOM (org.xwiki.rendering.block.XDOM)4 CompositeBlock (org.xwiki.rendering.block.CompositeBlock)3 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)2 Syntax (org.xwiki.rendering.syntax.Syntax)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 ScriptException (javax.script.ScriptException)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Translation (org.xwiki.localization.Translation)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 OfficeImporterException (org.xwiki.officeimporter.OfficeImporterException)1 XDOMOfficeDocument (org.xwiki.officeimporter.document.XDOMOfficeDocument)1