Available Transformations

Version 4.1 by Vincent Massol on 2011/10/14 00:30

Here's the list of available Transformations you can use:

Icon Transformation

Transforms some special characters representing icons into images. For example transforms the emoticon_smile characters into a smiley (:)).

CharactersResult
:)emoticon_smile
:(emoticon_unhappy
:Pemoticon_tongue
:Demoticon_grin
;)emoticon_wink
(y)thumb_up
(n)thumb_down
(i)information
(/)accept
(x)cancel
(!)error
(+)add
(-)delete
(?)help
(on)lightbulb
(off)lightbulb_off
(*)star

Example of using it:

// Initialize Rendering components and allow getting instances
final EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(this.getClass().getClassLoader());

XDOM xdom = new XDOM(Arrays.<Block>asList(new ParagraphBlock(Arrays.asList((Block) new SpecialSymbolBlock(':'),
    new SpecialSymbolBlock(')')))));

Transformation transformation = cm.lookup(Transformation.class, "icon");
TransformationContext txContext = new TransformationContext();
transformation.transform(xdom, txContext);

WikiPrinter printer = new DefaultWikiPrinter();
BlockRenderer renderer = cm.lookup(BlockRenderer.class, Syntax.XWIKI_2_0.toIdString());
renderer.render(xdom, printer);

String expected = "image:emoticon_smile";

Assert.assertEquals(expected, printer.toString());

It's also possible to configure new emoticons or override existing ones by implementing a ConfigurationSource component. Here's an example of registering such an implementation programatically at runtime (you can do the same statically by using Annotations and by writing the implementation in a proper class):

// Initialize Rendering components and allow getting instances
final EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(this.getClass().getClassLoader());

XDOM xdom = new XDOM(Arrays.<Block>asList(new ParagraphBlock(Arrays.asList((Block) new SpecialSymbolBlock(':'),
    new SpecialSymbolBlock(')')))));

ConfigurationSource customConfigurationSource = new ConfigurationSource() {
    @Override public boolean containsKey(String key)
    {
        return key.equals("rendering.transformation.icon.mappings");
    }

    @Override public List<String> getKeys()
    {
        return Arrays.asList("rendering.transformation.icon.mappings");
    }

    @Override public <T> T getProperty(String key)
    {
        return (T) getProperty(key, Properties.class);
    }

    @Override public <T> T getProperty(String key, T defaultValue)
    {
        return (T) getProperty(key, Properties.class);
    }

    @Override public <T> T getProperty(String key, Class<T> valueClass)
    {
        Properties props = new Properties();
        props.setProperty("::", "something");
        return (T) props;
    }

    @Override public boolean isEmpty()
    {
        return false;
    }
};
DefaultComponentDescriptor<ConfigurationSource> cd = new DefaultComponentDescriptor<ConfigurationSource>();
cd.setRole(ConfigurationSource.class);
cm.registerComponent(cd, customConfigurationSource);

Transformation transformation = cm.lookup(Transformation.class, "icon");
TransformationContext txContext = new TransformationContext();
transformation.transform(xdom, txContext);

WikiPrinter printer = new DefaultWikiPrinter();
BlockRenderer renderer = cm.lookup(BlockRenderer.class, Syntax.XWIKI_2_0.toIdString());
renderer.render(xdom, printer);

String expected = "image:emoticon_smile";

Assert.assertEquals(expected, printer.toString());

WikiWord Transformation

Automatically replace words representing Wiki Words with a link. For example This is a WikiWord gets transformation into This is a [[WikiWord]] (when rendered in XWiki Syntax 2.0).

Example of using it:

// Initialize Rendering components and allow getting instances
final EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(this.getClass().getClassLoader());

 XDOM xdom = new XDOM(
    Arrays.<Block>asList(new ParagraphBlock(Arrays.asList((Block) new WordBlock("WikiWord")))));

 Transformation transformation = cm.lookup(Transformation.class, "wikiword");
 TransformationContext txContext = new TransformationContext();
 transformation.transform(xdom, txContext);

 WikiPrinter printer = new DefaultWikiPrinter();
 BlockRenderer renderer = cm.lookup(BlockRenderer.class, Syntax.XWIKI_2_0.toIdString());
 renderer.render(xdom, printer);

 String expected = "[[WikiWord]]";

 Assert.assertEquals(expected, printer.toString());
  • Powered by XWiki 18.4.6 - node1. Hosted and managed by XWiki SAS

Get Connected