Search in sources :

Example 16 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class MessageToolTranslationMessageParserTest method messageSimple.

@Test
public void messageSimple() throws ComponentLookupException {
    TranslationMessage translationMessage = getMockedComponent().parse("word");
    Assert.assertEquals("word", translationMessage.getRawSource());
    Assert.assertEquals(new WordBlock("word"), translationMessage.render(null, null));
}
Also used : WordBlock(org.xwiki.rendering.block.WordBlock) TranslationMessage(org.xwiki.localization.message.TranslationMessage) Test(org.junit.Test)

Example 17 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class MessageToolTranslationMessageParserTest method messageWithExpectedParameter.

@Test
public void messageWithExpectedParameter() throws ComponentLookupException {
    TranslationMessage translationMessage = getMockedComponent().parse("{0}");
    Assert.assertEquals("{0}", translationMessage.getRawSource());
    Assert.assertEquals(new CompositeBlock(Arrays.<Block>asList(new SpecialSymbolBlock('{'), new WordBlock("0"), new SpecialSymbolBlock('}'))), translationMessage.render(null, null));
}
Also used : SpecialSymbolBlock(org.xwiki.rendering.block.SpecialSymbolBlock) WordBlock(org.xwiki.rendering.block.WordBlock) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) WordBlock(org.xwiki.rendering.block.WordBlock) Block(org.xwiki.rendering.block.Block) SpecialSymbolBlock(org.xwiki.rendering.block.SpecialSymbolBlock) TranslationMessage(org.xwiki.localization.message.TranslationMessage) Test(org.junit.Test)

Example 18 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class FormulaMacro method execute.

@Override
public List<Block> execute(FormulaMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    if (StringUtils.isEmpty(content)) {
        throw new MacroExecutionException(CONTENT_MISSING_ERROR);
    }
    String rendererHint = this.configuration.getRenderer();
    FontSize size = parameters.getFontSize();
    Type type = parameters.getImageType();
    Block result;
    try {
        result = render(content, context.isInline(), size, type, rendererHint);
    } catch (MacroExecutionException ex) {
        this.logger.debug("Failed to render content with the [{}] renderer. Falling back to the safe renderer.", rendererHint, ex);
        try {
            result = render(content, context.isInline(), size, type, this.configuration.getSafeRenderer());
        } catch (IllegalArgumentException ex2) {
            throw new MacroExecutionException(WRONG_CONTENT_ERROR);
        }
    } catch (IllegalArgumentException ex) {
        throw new MacroExecutionException(WRONG_CONTENT_ERROR);
    }
    // If no image was generated, just return the original text
    if (result == null) {
        result = new WordBlock(content);
    }
    // Block level formulae should be wrapped in a paragraph element
    if (!context.isInline()) {
        result = new ParagraphBlock(Collections.<Block>singletonList(result));
    }
    return Collections.singletonList(result);
}
Also used : Type(org.xwiki.formula.FormulaRenderer.Type) ResourceType(org.xwiki.rendering.listener.reference.ResourceType) FontSize(org.xwiki.formula.FormulaRenderer.FontSize) WordBlock(org.xwiki.rendering.block.WordBlock) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) Block(org.xwiki.rendering.block.Block) ImageBlock(org.xwiki.rendering.block.ImageBlock) WordBlock(org.xwiki.rendering.block.WordBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock)

Example 19 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class DefaultWikiMacroManagerTest method generateWikiMacro.

private DefaultWikiMacro generateWikiMacro(WikiMacroVisibility visibility) throws Exception {
    DocumentReference wikiMacroDocReference = new DocumentReference("wiki", Arrays.asList("space"), "space");
    WikiMacroDescriptor descriptor = new WikiMacroDescriptor(new MacroId("testwikimacro"), "Test Wiki Macro", "Description", "Test", visibility, new DefaultContentDescriptor(), Collections.<WikiMacroParameterDescriptor>emptyList());
    XDOM xdom = new XDOM(Arrays.asList(new ParagraphBlock(Arrays.<Block>asList(new WordBlock("test")))));
    DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocReference, authorReference, true, descriptor, xdom, Syntax.XWIKI_2_0, this.mocker);
    return wikiMacro;
}
Also used : DefaultContentDescriptor(org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor) XDOM(org.xwiki.rendering.block.XDOM) WordBlock(org.xwiki.rendering.block.WordBlock) MacroId(org.xwiki.rendering.macro.MacroId) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) WikiMacroDescriptor(org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 20 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class DefaultDocumentSplitterTest method updateAnchors.

@Test
public void updateAnchors() throws Exception {
    SplittingCriterion splittingCriterion = mock(SplittingCriterion.class);
    when(splittingCriterion.shouldSplit(any(Block.class), anyInt())).thenReturn(false, true, true);
    when(splittingCriterion.shouldIterate(any(SectionBlock.class), anyInt())).thenReturn(false, false, false);
    NamingCriterion namingCriterion = mock(NamingCriterion.class);
    when(namingCriterion.getDocumentName(any(XDOM.class))).thenReturn("Child1", "Child2");
    // [[link>>||anchor="chapter1"]]
    // = {{id name="chapter1"}}Chapter 1 =
    // = Chapter 2 ==
    // [[link>>path:#chapter1]]
    ResourceReference reference = new ResourceReference("", ResourceType.DOCUMENT);
    reference.setParameter("anchor", "chapter1");
    LinkBlock link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false);
    ParagraphBlock paragraph = new ParagraphBlock(Arrays.<Block>asList(link));
    HeaderBlock header = new HeaderBlock(Arrays.<Block>asList(new IdBlock("chapter1"), new WordBlock("Chapter 1")), HeaderLevel.LEVEL1);
    SectionBlock section1 = new SectionBlock(Arrays.<Block>asList(header));
    header = new HeaderBlock(Arrays.<Block>asList(new WordBlock("Chapter 2")), HeaderLevel.LEVEL1);
    reference = new ResourceReference("#chapter1", ResourceType.PATH);
    link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false);
    SectionBlock section2 = new SectionBlock(Arrays.<Block>asList(header, new ParagraphBlock(Arrays.<Block>asList(link))));
    XDOM xdom = new XDOM(Arrays.<Block>asList(paragraph, section1, section2));
    WikiDocument document = new WikiDocument("Space.Page", xdom, null);
    List<WikiDocument> result = mocker.getComponentUnderTest().split(document, splittingCriterion, namingCriterion);
    ClassBlockMatcher linkMatcher = new ClassBlockMatcher(LinkBlock.class);
    ResourceReference updatedReference = document.getXdom().<LinkBlock>getFirstBlock(linkMatcher, Axes.DESCENDANT).getReference();
    assertEquals("chapter1", updatedReference.getParameter("anchor"));
    assertEquals(result.get(1).getFullName(), updatedReference.getReference());
    updatedReference = result.get(2).getXdom().<LinkBlock>getFirstBlock(linkMatcher, Axes.DESCENDANT).getReference();
    assertEquals(ResourceType.DOCUMENT, updatedReference.getType());
    assertEquals("chapter1", updatedReference.getParameter("anchor"));
    assertEquals(result.get(1).getFullName(), updatedReference.getReference());
}
Also used : HeaderBlock(org.xwiki.rendering.block.HeaderBlock) XDOM(org.xwiki.rendering.block.XDOM) WordBlock(org.xwiki.rendering.block.WordBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) WikiDocument(org.xwiki.refactoring.WikiDocument) IdBlock(org.xwiki.rendering.block.IdBlock) NamingCriterion(org.xwiki.refactoring.splitter.criterion.naming.NamingCriterion) LinkBlock(org.xwiki.rendering.block.LinkBlock) ClassBlockMatcher(org.xwiki.rendering.block.match.ClassBlockMatcher) LinkBlock(org.xwiki.rendering.block.LinkBlock) HeaderBlock(org.xwiki.rendering.block.HeaderBlock) Block(org.xwiki.rendering.block.Block) IdBlock(org.xwiki.rendering.block.IdBlock) WordBlock(org.xwiki.rendering.block.WordBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) SectionBlock(org.xwiki.rendering.block.SectionBlock) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) SectionBlock(org.xwiki.rendering.block.SectionBlock) SplittingCriterion(org.xwiki.refactoring.splitter.criterion.SplittingCriterion) Test(org.junit.Test)

Aggregations

WordBlock (org.xwiki.rendering.block.WordBlock)24 Test (org.junit.Test)13 Block (org.xwiki.rendering.block.Block)13 XDOM (org.xwiki.rendering.block.XDOM)8 DocumentReference (org.xwiki.model.reference.DocumentReference)6 TranslationMessage (org.xwiki.localization.message.TranslationMessage)5 ArrayList (java.util.ArrayList)4 HeaderBlock (org.xwiki.rendering.block.HeaderBlock)4 LinkBlock (org.xwiki.rendering.block.LinkBlock)4 ParagraphBlock (org.xwiki.rendering.block.ParagraphBlock)4 SpecialSymbolBlock (org.xwiki.rendering.block.SpecialSymbolBlock)4 EntityReference (org.xwiki.model.reference.EntityReference)3 IdBlock (org.xwiki.rendering.block.IdBlock)3 SectionBlock (org.xwiki.rendering.block.SectionBlock)3 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 List (java.util.List)2 Expectations (org.jmock.Expectations)2 Mockery (org.jmock.Mockery)2