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"));
}
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;
}
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;
}
Aggregations