Available Transformations
Here's the list of available Transformations you can use:
Macro Transformation
See Architecture.
Icon Transformation
Transforms some special characters representing icons into images. For example transforms the
characters into a smiley (:)).
| Characters | Result |
|---|---|
| :) | |
| :( | |
| :P | |
| :D | |
| ;) | |
| (y) | |
| (n) | |
| (i) | |
| (/) | |
| (x) | |
| (!) | |
| (+) | |
| (-) | |
| (?) | |
| (on) | |
| (off) | |
| (*) |
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 getting the IconTransformationConfiguration component as shown below (works on XWiki Rendering 3.3M1+):
// 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(':')))));
// Test adding a new Icon Mapping.
cm.lookup(IconTransformationConfiguration.class).addMapping("::", "something");
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:box";
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());LinkChecker Transformation
Checks validity of external links (URLs) and store the result in memory which can then be accessed through a Component or through a Script Service.
Here's how it works:
- When the LinkChecker Transformation Component is first looked up, it spawns a LinkChecker Thread
- All external links (URLs) found are put on a Queue in order to not impact the rendering process
- The LinkChecker Thread is a low priority Thread that checks if there are links to verify on the Queue, take them one by one and verify the links by calling them and storing the response code of the HTTP request in memory
- The LinkChecker Thread only rechecks a given link after a certain amount of time has elapsed (5 minutes by default)
Accessing Link states from a Component
Example:
...
<dependency>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-transformation-linkchecker</artifactId>
<version>3.3-milestone-1</version>
</dependency>
......
@Inject
private LinkStateManager linkStateManager;
...
public void someMethod()
{
Map<String, Map<String, LinkState>> linkStates = this.linkStateManager.getLinkStates();
}