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 @Override
039 @SuppressWarnings("rawtypes")
040 public String execute(WikiContext context, Map params)
041 throws PluginException {
042
043 if (!params.containsKey(PARAM_NUMBERED)) {
044 params.put(PARAM_NUMBERED, Boolean.TRUE.toString());
045 }
046
047 String result = super.execute(context, params);
048
049 if (_count < 2) {
050 return StringPool.BLANK;
051 }
052
053 int x = result.indexOf("<div class=\"collapsebox\">\n");
054
055 x = result.indexOf("</h4>", x);
056
057 int y = x + "</h4>".length();
058
059 if ((x != -1) && (y != -1)) {
060 StringBundler sb = new StringBundler(15);
061
062 sb.append(result.substring(0, x));
063 sb.append(StringPool.NBSP);
064 sb.append("<a class=\"toc-trigger\" href=\"javascript:;\">[-]</a>");
065 sb.append("</h4>");
066
067 sb.append("<div class=\"toc-index\">\n");
068 sb.append(result.substring(y));
069 sb.append("</div>\n");
070
071 result = sb.toString();
072 }
073
074 return result;
075 }
076
077 @Override
078 public void headingAdded(WikiContext context, Heading heading) {
079 super.headingAdded(context, heading);
080
081 _count++;
082 }
083
084 private int _count;
085
086 }