1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.christianschenk.confluence.plugin.bibsonomy;
20
21 import java.util.Map;
22
23 import org.christianschenk.confluence.plugin.bibsonomy.helper.ConfluenceHelper;
24 import org.christianschenk.confluence.plugin.bibsonomy.helper.HttpClientHelper;
25
26 import com.atlassian.renderer.RenderContext;
27 import com.atlassian.renderer.v2.RenderMode;
28 import com.atlassian.renderer.v2.macro.BaseMacro;
29 import com.atlassian.renderer.v2.macro.MacroException;
30
31
32
33
34
35
36 public class BibSonomyTagCloudMacro extends BaseMacro {
37
38 private String username;
39 private int minFreq;
40
41 public String execute(@SuppressWarnings("unchecked") final Map params, final String body, final RenderContext renderContext) throws MacroException {
42
43 this.username = ConfluenceHelper.getParam(params, new String[] { "0", "username", "userName" }, true);
44 this.minFreq = Integer.parseInt(ConfluenceHelper.getParam(params, new String[] { "1", "minfreq", "minFreq" }, "5"));
45
46 String tags = new HttpClientHelper().getString("http://www.bibsonomy.org/ajax/subTagList.jsp?requUser=" + this.username + "&minfreq=" + this.minFreq);
47 tags = tags.replace("<taglist>", "<ul class=\"tagcloud\">");
48 tags = tags.replace("</taglist>", "</ul>");
49 tags = tags.replaceAll("href=\"/", "href=\"http://www.bibsonomy.org/");
50
51 final StringBuffer buf = new StringBuffer();
52 buf.append(this.getCSS());
53 buf.append(tags);
54 return buf.toString();
55 }
56
57 private String getCSS() {
58 final StringBuffer buf = new StringBuffer();
59 buf.append("\n<style type=\"text/css\">\n");
60 buf.append(".tagcloud { text-align: justify; font-size: 70%; }\n");
61 buf.append(".tagcloud li { display: inline; padding: 0em .1em 0em .1em; }\n");
62 buf.append(".tagcloud a,.taglist a { color: #069; }\n");
63 buf.append(".tagcloud a:hover, .taglist a:hover { color: #f00; text-decoration: none; }\n");
64 buf.append(".tagone a { color: #3399cc; }\n");
65 buf.append(".tagten a { font-size: 140%; }\n");
66 buf.append("</style>\n");
67 return buf.toString();
68 }
69
70 public boolean isInline() {
71 return false;
72 }
73
74 public boolean hasBody() {
75 return false;
76 }
77
78 public RenderMode getBodyRenderMode() {
79 return RenderMode.NO_RENDER;
80 }
81 }