Author: ajaquith
Date: Sat Jan 30 15:29:16 2010
New Revision: 904793
URL: http://svn.apache.org/viewvc?rev=904793&view=rev
Log:
TabTag now accepts two new attributes, which can be used in place of the "url"
attribute: "beanclass" and "event". These are used to specify ActionBean names
and event, and are used in the same manner as <stripes:link>. TabTag also now
accepts child <wiki:param> tags to make this easier.
Modified:
incubator/jspwiki/trunk/src/WebContent/WEB-INF/jspwiki.tld
incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabTag.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabbedSectionTag.java
Modified: incubator/jspwiki/trunk/src/WebContent/WEB-INF/jspwiki.tld
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/WEB-INF/jspwiki.tld?rev=904793&r1=904792&r2=904793&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/WEB-INF/jspwiki.tld (original)
+++ incubator/jspwiki/trunk/src/WebContent/WEB-INF/jspwiki.tld Sat Jan 30
15:29:16 2010
@@ -765,22 +765,32 @@
<bodycontent>JSP</bodycontent>
<info>A Tag for a tab, which is a child of tabbedSection</info>
<attribute>
- <name>id</name>
- <required>true</required>
+ <name>accesskey</name>
+ <required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
- <name>title</name>
+ <name>beanclass</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
- <name>titleKey</name>
+ <name>event</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
- <name>accesskey</name>
+ <name>id</name>
+ <required>true</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>title</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>titleKey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
@@ -897,4 +907,45 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
+
+ <function>
+ <description>
+ Returns a localized attachment tab name based on the number of
attachments.
+ </description>
+ <name>attachmentsTitle</name>
+ <function-class>
+ org.apache.wiki.tags.JspFunctions
+ </function-class>
+ <function-signature>
+ String getAttachmentsTitle(java.util.Locale,java.util.Collection)
+ </function-signature>
+ </function>
+
+ <function>
+ <description>
+ Returns a Date formatted in ISO8601 format. Ideal for sorting.
+ </description>
+ <name>iso8601date</name>
+ <function-class>
+ org.apache.wiki.tags.JspFunctions
+ </function-class>
+ <function-signature>
+ String getISO8601Date(java.util.Date)
+ </function-signature>
+ </function>
+
+ <function>
+ <description>
+ Returns a String whose characters above a supplied length
+ are replaced by the ellipsis.
+ </description>
+ <name>shorten</name>
+ <function-class>
+ org.apache.wiki.tags.JspFunctions
+ </function-class>
+ <function-signature>
+ String shortenedString(java.lang.String,int)
+ </function-signature>
+ </function>
+
</taglib>
\ No newline at end of file
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabTag.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabTag.java?rev=904793&r1=904792&r2=904793&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabTag.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabTag.java Sat Jan
30 15:29:16 2010
@@ -21,8 +21,13 @@
package org.apache.wiki.tags;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.servlet.jsp.JspTagException;
+import net.sourceforge.stripes.action.ActionBean;
+
import org.apache.wiki.tags.TabbedSectionTag.TabCollection;
import org.apache.wiki.util.TextUtil;
@@ -53,16 +58,22 @@
* you have something that you want to look like a part of a tag, but for
* example, due to it being very big in size, don't want to include it as a
part
* of the page content every time. <em>Optional.</em></li>
+ * <li><b>beanclass</b> and <b>event</b> - If you <i>don't</i> want to create
+ * a Javascript-enabled tag, you can supply the name of a Stripes ActionBean
+ * and event to be invoked, the URL for which will be looked up and rendered.
+ * If the event is not specified, the default event will be used. If both
+ * {...@code url} and {...@code beanclass} are specified, {...@code beanclass}
wins.
+ * <em>Optional.</em></li>
* </ul>
*
* @since v2.3.63
*/
-public class TabTag extends WikiTagBase
+public class TabTag extends WikiTagBase implements ParamHandler
{
private static final long serialVersionUID = -8534125226484616489L;
private final TabInfo m_tabInfo = new TabInfo();
-
+
/**
* Lightweight class that holds information about TabTags.
*/
@@ -78,14 +89,11 @@
private String m_url = null;
- /**
- * Sets the id.
- * @param id
- */
- public void setId( String id )
- {
- m_id = id;
- }
+ private Class<? extends ActionBean> m_beanclass = null;
+
+ private String m_event = null;
+
+ private Map<String, String> m_containedParams;
/**
* Sets the tab access key.
@@ -99,6 +107,35 @@
}
/**
+ * Sets the tab beanclass.
+ * @param beanclass the ActionBean class name
+ * @throws ClassNotFoundException
+ */
+ @SuppressWarnings("unchecked")
+ public void setBeanclass( String beanclass ) throws
ClassNotFoundException
+ {
+ m_beanclass = (Class<? extends ActionBean>)Class.forName(
beanclass );
+ }
+
+ /**
+ * Sets the tab event.
+ * @param event the ActionBean event handler name
+ */
+ public void setEvent( String event )
+ {
+ m_event = TextUtil.replaceEntities( event );
+ }
+
+ /**
+ * Sets the id.
+ * @param id
+ */
+ public void setId( String id )
+ {
+ m_id = id;
+ }
+
+ /**
* Sets the tab title.
*
* @param title the tab title
@@ -129,32 +166,54 @@
}
/**
- * Returns the ID for this tab.
- * @return id
+ * Returns the tab access key.
+ *
+ * @return the access key
*/
- public String getId()
+ public String getAccesskey()
{
- return m_id;
+ return m_accesskey;
}
/**
- * Returns the URL for this tab, if supplied.
- *
- * @return the URL
+ * Returns the tab's ActionBean class name for generating an URL.
+ * @return the bean class
*/
- public String getUrl()
+ public Class<? extends ActionBean> getBeanclass()
{
- return m_url;
+ return m_beanclass;
}
-
+
/**
- * Returns the tab access key.
- *
- * @return the access key
+ * Returns any parameters passed to the Tab tag.
+ * @return the params
*/
- public String getAccesskey()
+ public Map<String,String> getContainedParameters()
{
- return m_accesskey;
+ if ( m_containedParams == null )
+ {
+ m_containedParams = new HashMap<String,String>();
+ }
+ return m_containedParams;
+ }
+
+ /**
+ * Returns the tab's ActionBean event name for generating an URL.
+ * @return the ActionBean event name, or {...@code null} if the default
+ * should be used
+ */
+ public String getEvent()
+ {
+ return m_event;
+ }
+
+ /**
+ * Returns the ID for this tab.
+ * @return id
+ */
+ public String getId()
+ {
+ return m_id;
}
/**
@@ -174,6 +233,33 @@
{
return m_tabTitleKey;
}
+
+ /**
+ * Returns the URL for this tab, if supplied.
+ *
+ * @return the URL
+ */
+ public String getUrl()
+ {
+ return m_url;
+ }
+
+ /**
+ * Adds a nested parameter value to the tab
+ * @param name the parameter name
+ * @param value the value
+ */
+ public void setContainedParameter( String name, String value )
+ {
+ if( name != null )
+ {
+ if( m_containedParams == null )
+ {
+ m_containedParams = new HashMap<String, String>();
+ }
+ m_containedParams.put( name, value );
+ }
+ }
}
protected TabInfo getTabInfo()
@@ -186,6 +272,10 @@
*/
public int doEndTag() throws javax.servlet.jsp.JspTagException
{
+ // Add tab to TabCollection so parent TabbedSection can get it later
+ TabCollection tc = TabbedSectionTag.getTabContext(
getPageContext().getRequest() );
+ tc.addTab( this );
+
try
{
pageContext.getOut().write( "</div>\n" );
@@ -205,6 +295,9 @@
{
super.doFinally();
m_tabInfo.m_accesskey = null;
+ m_tabInfo.m_beanclass = null;
+ m_tabInfo.m_containedParams = null;
+ m_tabInfo.m_event = null;
m_tabInfo.m_tabTitle = null;
m_tabInfo.m_tabTitleKey = null;
m_tabInfo.m_url = null;
@@ -212,8 +305,9 @@
/**
* {...@inheritdoc}
+ * @throws ClassNotFoundException
*/
- public int doWikiStartTag() throws JspTagException
+ public int doWikiStartTag() throws JspTagException, ClassNotFoundException
{
//
// Sanity checks
@@ -227,10 +321,6 @@
throw new JspTagException( "Tab Tag without \"tabTitle\" or
\"tabTitleKey\" attribute" );
}
- // Add tab to TabCollection so parent TabbedSection can get it later
- TabCollection tc = TabbedSectionTag.getTabContext(
getPageContext().getRequest() );
- tc.addTab( this );
-
// Generate the opening <div id=foo> tag, always with "hidetab" class
// (TabbedSection#doAfterBody will fix this later...)
try
@@ -266,6 +356,36 @@
{
m_tabInfo.setAccesskey( accessKey );
}
+
+ /**
+ * Sets the tab beanclass, which must be the name of a class of
+ * type {...@link net.sourceforge.stripes.action.ActionBean}.
+ * @param beanclass the ActionBean class name
+ * @throws ClassNotFoundException if the bean class cannot be located or
loaded
+ */
+ public void setBeanclass( String beanclass ) throws ClassNotFoundException
+ {
+ m_tabInfo.setBeanclass( beanclass );
+ }
+
+ /**
+ * Support for ParamTag supplied parameters in body.
+ */
+ public void setContainedParameter( String name, String value )
+ {
+ m_tabInfo.setContainedParameter( name, value );
+ }
+
+ /**
+ * Sets the tab event, which must correspond to the handler name
+ * of a Stripes ActionBean. If omitted, the event handler
+ * will be the method annotated by {...@link
net.sourceforge.stripes.action.DefaultHandler}.
+ * @param event the ActionBean event handler name
+ */
+ public void setEvent( String event )
+ {
+ m_tabInfo.setEvent( event );
+ }
/**
* Sets the tab title.
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabbedSectionTag.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabbedSectionTag.java?rev=904793&r1=904792&r2=904793&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabbedSectionTag.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TabbedSectionTag.java
Sat Jan 30 15:29:16 2010
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
@@ -33,10 +34,14 @@
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
+import net.sourceforge.stripes.util.UrlBuilder;
+
import org.apache.wiki.WikiEngine;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.tags.TabTag.TabInfo;
+import com.sun.tools.internal.ws.processor.model.Request;
+
/**
* <p>
* Generates a container for page tabs, as defined by collaborating
@@ -136,6 +141,7 @@
* cached copies.
*
* @param tab the tab to add
+ * @throws ClassNotFoundException
*/
public void addTab( TabTag tab ) throws JspTagException
{
@@ -146,6 +152,22 @@
TabInfo tabInfo = new TabInfo();
tabInfo.setAccesskey( tab.getTabInfo().getAccesskey() );
+ if ( tab.getTabInfo().getBeanclass() != null )
+ {
+ try
+ {
+ tabInfo.setBeanclass(
tab.getTabInfo().getBeanclass().getName() );
+ }
+ catch( ClassNotFoundException e )
+ {
+ throw new JspTagException( "Could not set beanclass: " +
e.getMessage() );
+ }
+ }
+ for ( Map.Entry<String,String> entry :
tab.getTabInfo().getContainedParameters().entrySet() )
+ {
+ tabInfo.setContainedParameter( entry.getKey(),
entry.getValue() );
+ }
+ tabInfo.setEvent( tab.getTabInfo().getEvent() );
tabInfo.setId( tab.getTabInfo().getId() );
tabInfo.setTitle( tab.getTabInfo().getTitle() );
tabInfo.setTitleKey( tab.getTabInfo().getTitleKey() );
@@ -290,9 +312,30 @@
{
writer.append( " class=\"activetab\"" );
}
+
+ // Generate the ActionBean event URL, if supplied
+ if ( tab.getBeanclass() != null )
+ {
+ HttpServletRequest request =
(HttpServletRequest)pageContext.getRequest();
+ UrlBuilder builder = new UrlBuilder( request.getLocale(),
tab.getBeanclass(), true );
+ if ( tab.getEvent() != null )
+ {
+ builder.setEvent( tab.getEvent() );
+ }
+ for ( Map.Entry<String, String> entry :
tab.getContainedParameters().entrySet() )
+ {
+ builder.addParameter( entry.getKey(), entry.getValue() );
+ }
+ String url = builder.toString();
+ if ( request.getContextPath() != null && !url.startsWith(
request.getContextPath() ) )
+ {
+ url = request.getContextPath() + url;
+ }
+ writer.append( " href='" + url + "'" );
+ }
// Generate the URL, if supplied
- if( tab.getUrl() != null )
+ else if( tab.getUrl() != null )
{
writer.append( " href='" + tab.getUrl() + "'" );
}