View Javadoc

1   package org.tinyjee.maven.dim.extensions;
2   
3   import org.tinyjee.maven.dim.spi.RequestParameterTransformer;
4   
5   import java.util.Map;
6   
7   import static org.tinyjee.maven.dim.IncludeMacroSignature.*;
8   
9   /**
10   * This extension renders a tabbed panel from document sections (hierarchical headlines in Doxia).
11   * <p/>
12   * Tabbed panels are useful in improving the screen appearance of large content by creating multiple pages using tabs.
13   * When printing a document, the content renders in the same way as before (the panel is hidden and all tabs are visible).
14   *
15   * @author Juergen_Kellerer, 2011-11-06
16   */
17  public class TabbedPanelParameterTransformer extends AbstractParameterTransformer {
18  
19  	/**
20  	 * Enables this extension and sets a regular expression matching the section titles that should be transformed into a tabs.
21  	 * <p/>
22  	 * <b>Note:</b> Setting this property has no effect in case of "<code>source</code>" or "<code>source-class</code>" were
23  	 * specified with the macro call. This behaviour ensures that the parameter "<code>tabbed-panel</code>" can still be used
24  	 * with ordinary macro calls where a source or source-class was set.
25  	 * <p/>
26  	 * This parameter expects a regular expression that is used to select what sections turn into tabs and what not by matching
27  	 * the given titles (headlines).<br/>
28  	 * By default the javascript looks for the first section that follows the include position and continues with all
29  	 * siblings (sections of the same level). Neither parent nor child sections are processed, therefore it's mostly safe
30  	 * to use the <i>match all</i> expression <code>.*</code> if all sub-sequent sections of the same nesting level should
31  	 * turn into tabs.
32  	 * <p/>
33  	 * Examples:<ul>
34  	 * <li>"<code>%{include|tabbed-panel=.*}</code>" - Transforms all following sections (of the same level) to tabs.</li>
35  	 * <li>"<code>%{include|tabbed-panel=.*(Example).*}</code>" - Transforms all following sections to tabs that contain
36  	 * the word "Example".</li>
37  	 * </ul>
38  	 */
39  	public static final String PARAM_TABBED_PANEL = "tabbed-panel";
40  
41  	/**
42  	 * Toggles whether section titles are hidden once they were transformed into a tab (defaults to 'true').
43  	 */
44  	public static final String PARAM_HIDE_TITLES = "hide-titles";
45  
46  	/**
47  	 * <b>Optional Parameter:</b> Specifies a minimum tab height to improve scrolling behaviour when switching tabs.
48  	 */
49  	public static final String PARAM_MIN_HEIGHT = "min-height";
50  
51  	private static final String PARAM_TABS = "tabs";
52  
53  	@Override
54  	protected boolean doTransformParameters(Map<String, Object> requestParams) {
55  		Object tabs = requestParams.get(PARAM_TABBED_PANEL);
56  		if (tabs != null) {
57  			requestParams.put(PARAM_SOURCE, "classpath:/templates/dim/tabbed-panel.html.vm");
58  			requestParams.put(PARAM_VERBATIM, false);
59  			requestParams.put(PARAM_TABS, "*".equals(tabs) ? ".*" : tabs);
60  
61  			if (!requestParams.containsKey(PARAM_HIDE_TITLES)) requestParams.put(PARAM_HIDE_TITLES, true);
62  			return true;
63  		}
64  		return false;
65  	}
66  }