001
014
015 package com.liferay.portlet.wiki.engines.jspwiki.plugin;
016
017 import com.ecyrd.jspwiki.WikiContext;
018 import com.ecyrd.jspwiki.parser.Heading;
019 import com.ecyrd.jspwiki.plugin.PluginException;
020
021 import com.liferay.portal.kernel.util.StringBundler;
022 import com.liferay.portal.kernel.util.StringPool;
023
024 import java.util.Map;
025
026
036 public class TableOfContents extends com.ecyrd.jspwiki.plugin.TableOfContents {
037
038 public String execute(WikiContext context, Map params)
039 throws PluginException {
040
041 if (!params.containsKey(PARAM_NUMBERED)) {
042 params.put(PARAM_NUMBERED, Boolean.TRUE.toString());
043 }
044
045 String result = super.execute(context, params);
046
047 if (_count < 2) {
048 return StringPool.BLANK;
049 }
050
051 int x = result.indexOf("<div class=\"collapsebox\">\n");
052
053 x = result.indexOf("</h4>", x);
054
055 int y = x + "</h4>".length();
056
057 if ((x != -1) && (y != -1)) {
058 StringBundler sb = new StringBundler(15);
059
060 sb.append(result.substring(0, x));
061 sb.append(StringPool.NBSP);
062 sb.append("<a class=\"toc-trigger\" href=\"javascript:;\">[-]</a>");
063 sb.append("</h4>");
064
065 sb.append("<div class=\"toc-index\">\n");
066 sb.append(result.substring(y));
067 sb.append("</div>\n");
068
069 result = sb.toString();
070 }
071
072 return result;
073 }
074
075 public void headingAdded(WikiContext context, Heading heading) {
076 super.headingAdded(context, heading);
077
078 _count++;
079 }
080
081 private int _count;
082
083 }