TableOfContents.java |
1 /** 2 * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 */ 22 23 package com.liferay.portlet.wiki.engines.jspwiki.plugin; 24 25 import com.ecyrd.jspwiki.WikiContext; 26 import com.ecyrd.jspwiki.plugin.PluginException; 27 28 import com.liferay.portal.kernel.util.StringMaker; 29 import com.liferay.portal.kernel.util.StringPool; 30 import com.liferay.util.PwdGenerator; 31 32 import java.util.Map; 33 34 /** 35 * <a href="TableOfContents.java.html"><b><i>View Source</i></b></a> 36 * 37 * <p> 38 * This is a modification of JSPWiki's core TableOfContents plugin for use 39 * within Liferay. This plugin modifies the original behavior by producing 40 * ordered lists and making contents collapsable. 41 * </p> 42 * 43 * @author Alexander Chow 44 * 45 */ 46 public class TableOfContents extends com.ecyrd.jspwiki.plugin.TableOfContents { 47 48 public String execute(WikiContext context, Map params) 49 throws PluginException { 50 51 if (!params.containsKey(PARAM_NUMBERED)) { 52 params.put(PARAM_NUMBERED, Boolean.TRUE.toString()); 53 } 54 55 String result = super.execute(context, params); 56 57 int x = result.indexOf("<div class=\"collapsebox\">\n"); 58 59 x = result.indexOf("</h4>", x); 60 61 int y = x + "</h4>".length(); 62 63 if ((x != -1) && (y != -1)) { 64 String id = "toc_" + PwdGenerator.getPassword(); 65 66 StringMaker sm = new StringMaker(); 67 68 sm.append(result.substring(0, x)); 69 sm.append(StringPool.NBSP); 70 sm.append("<span style=\"cursor: pointer;\" "); 71 sm.append("onClick=\"Liferay.Util.toggleByIdSpan(this, '"); 72 sm.append(id); 73 sm.append("'); self.focus();\">["); 74 sm.append("<span>-</span>"); 75 sm.append("<span style=\"display: none;\">+</span>"); 76 sm.append("]</span>\n"); 77 sm.append("</h4>"); 78 79 sm.append("<div id=\""); 80 sm.append(id); 81 sm.append("\">\n"); 82 sm.append(result.substring(y)); 83 sm.append("</div>\n"); 84 85 result = sm.toString(); 86 } 87 88 return result; 89 } 90 91 }