1   /*
2    * Confluence BibSonomy plugin
3    * Copyright (C) 2007 Christian Schenk
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
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   * This macro displays your tags as a cloud or list.
33   * 
34   * @author Christian Schenk
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  		// parse the parameters
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  }