1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wiki.rendering.render.confluence;
18
19 import java.util.Map;
20
21 import org.xwiki.rendering.internal.renderer.ParametersPrinter;
22
23
24
25
26 public class ConfluenceSyntaxMacroRenderer {
27
28 private ParametersPrinter parametersPrinter = new ParametersPrinter();
29
30 public String renderMacro(String id, Map<String, String> parameters, String content, boolean isInline) {
31 StringBuffer buffer = new StringBuffer();
32
33
34 buffer.append("{");
35 buffer.append(id);
36
37
38 if (!parameters.isEmpty()) {
39 buffer.append(':');
40 buffer.append(renderMacroParameters(parameters));
41 }
42
43 buffer.append("}");
44
45 if (content != null && content.length() > 0) {
46 if (!isInline && !content.startsWith("\n")) {
47 buffer.append("\n");
48 }
49 buffer.append(content);
50 if (!isInline && !content.endsWith("\n")) {
51 buffer.append("\n");
52 }
53
54
55
56
57 if (!content.endsWith("{" + id + "}")) {
58 buffer.append("{").append(id).append("}");
59 }
60 }
61
62 return buffer.toString();
63 }
64
65 public String renderMacroParameters(Map<String, String> parameters) {
66 return this.parametersPrinter.print(parameters, '~').replace("}", "~}");
67 }
68 }