| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.icon.internal; |
| 21 |
|
|
| 22 |
|
import java.io.StringWriter; |
| 23 |
|
|
| 24 |
|
import javax.inject.Inject; |
| 25 |
|
import javax.inject.Singleton; |
| 26 |
|
|
| 27 |
|
import org.apache.velocity.VelocityContext; |
| 28 |
|
import org.xwiki.component.annotation.Component; |
| 29 |
|
import org.xwiki.icon.IconException; |
| 30 |
|
import org.xwiki.velocity.VelocityEngine; |
| 31 |
|
import org.xwiki.velocity.VelocityManager; |
| 32 |
|
import org.xwiki.velocity.XWikiVelocityException; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@version |
| 38 |
|
@since |
| 39 |
|
|
| 40 |
|
@Component(roles = VelocityRenderer.class) |
| 41 |
|
@Singleton |
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.31 |
|
| 42 |
|
public class VelocityRenderer |
| 43 |
|
{ |
| 44 |
|
@Inject |
| 45 |
|
private VelocityManager velocityManager; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@param |
| 50 |
|
@return |
| 51 |
|
@throws |
| 52 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
| 53 |
2675 |
public String render(String code) throws IconException... |
| 54 |
|
{ |
| 55 |
|
|
| 56 |
2675 |
String namespace = "IconVelocityRenderer_" + Thread.currentThread().getId(); |
| 57 |
|
|
| 58 |
|
|
| 59 |
2675 |
StringWriter output = new StringWriter(); |
| 60 |
|
|
| 61 |
2674 |
VelocityEngine engine = null; |
| 62 |
2675 |
try { |
| 63 |
|
|
| 64 |
2674 |
engine = velocityManager.getVelocityEngine(); |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
2674 |
engine.startedUsingMacroNamespace(namespace); |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
2674 |
VelocityContext context = new VelocityContext(velocityManager.getVelocityContext()); |
| 75 |
|
|
| 76 |
|
|
| 77 |
2674 |
if (engine.evaluate(context, output, "DefaultIconRenderer", code)) { |
| 78 |
2673 |
return output.toString(); |
| 79 |
|
} else { |
| 80 |
|
|
| 81 |
1 |
throw new IconException("Failed to render the icon. See the Velocity runtime log.", null); |
| 82 |
|
} |
| 83 |
|
} catch (XWikiVelocityException e) { |
| 84 |
1 |
throw new IconException("Failed to render the icon.", e); |
| 85 |
|
} finally { |
| 86 |
|
|
| 87 |
2675 |
if (engine != null) { |
| 88 |
2674 |
engine.stoppedUsingMacroNamespace(namespace); |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
} |
| 92 |
|
} |