jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r905887 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki/tags: TabTag.java TabbedSectionTag.java
Date Wed, 03 Feb 2010 05:17:19 GMT
Author: ajaquith
Date: Wed Feb  3 05:17:19 2010
New Revision: 905887

URL: http://svn.apache.org/viewvc?rev=905887&view=rev
Log:
TabbedSectionTag gains an onclick() attribute that passes contents through to the underlying
<div>. This feature is super-useful and enables the new preview functionality. Refactored
TabTag to make it simpler.

Modified:
    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/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=905887&r1=905886&r2=905887&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 Wed Feb  3 05:17:19
2010
@@ -64,6 +64,8 @@
  * 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>
+ * <li><b>onclick</b>(Pass-through) JavaScript to be executed after the
+ * tab is clicked, but before the contents are displayed. <em>Optional.</em></li>
  * </ul>
  * 
  * @since v2.3.63
@@ -72,199 +74,61 @@
 {
     private static final long serialVersionUID = -8534125226484616489L;
     
-    private final TabInfo m_tabInfo = new TabInfo();
+    private final Info m_info = new Info();
     
     /**
      * Lightweight class that holds information about TabTags.
      */
-    public static class TabInfo 
+    public static class Info implements Cloneable
     {
-        private String m_id = null;
-        
-        private String m_accesskey = null;
-
-        private String m_tabTitle = null;
-
-        private String m_tabTitleKey = null;
+        static final String ACCESS_KEY = "accessKey";
 
-        private String m_url = null;
-        
-        private Class<? extends ActionBean> m_beanclass = null;
-        
-        private String m_event = null;
+        static final String EVENT = "event";
         
-        private Map<String, String> m_containedParams;
-        
-        /**
-         * Sets the tab access key.
-         * 
-         * @param accessKey the access key
-         */
-        public void setAccesskey( String accessKey )
-        {
-            m_accesskey = TextUtil.replaceEntities( accessKey ); // take only the
-            // first char
-        }
+        static final String ID = "id";
 
-        /**
-         * 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
-         */
-        public void setTitle( String title )
-        {
-            m_tabTitle = TextUtil.replaceEntities( title );
-        }
+        static final String ON_CLICK = "onClick";
 
-        /**
-         * Sets the tab title key.
-         * 
-         * @param key the tab title key
-         */
-        public void setTitleKey( String key )
-        {
-            m_tabTitleKey = TextUtil.replaceEntities( key );
-        }
+        static final String TITLE = "tabTitle";
 
-        /**
-         * Sets the tab URL.
-         * 
-         * @param url the URL
-         */
-        public void setUrl( String url )
-        {
-            m_url = TextUtil.replaceEntities( url );
-        }
-        
-        /**
-         * Returns the tab access key.
-         * 
-         * @return the access key
-         */
-        public String getAccesskey()
-        {
-            return m_accesskey;
-        }
-        
-        /**
-         * Returns the tab's ActionBean class name for generating an URL.
-         * @return the bean class
-         */
-        public Class<? extends ActionBean> getBeanclass()
-        {
-            return m_beanclass;
-        }
-        
-        /**
-         * Returns any parameters passed to the Tab tag.
-         * @return the params
-         */
-        public Map<String,String> getContainedParameters()
-        {
-            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;
-        }
+        static final String TITLE_KEY = "tabTitleKey";
+
+        static final String URL = "url";
         
         /**
-         * Returns the tab title.
-         * @return the title
+         * The tab's ActionBean class name for generating an URL.
          */
-        public String getTitle()
-        {
-            return m_tabTitle;
-        }
+        Class<? extends ActionBean> beanclass = null;
         
         /**
-         * Returns the i18n key used to generate the tab title.
-         * @return the title key
+         * Parameters passed to the Tab tag.
          */
-        public String getTitleKey()
-        {
-            return m_tabTitleKey;
-        }
+        final Map<String, String> containedParams = new HashMap<String,String>();
         
         /**
-         * Returns the URL for this tab, if supplied.
-         * 
-         * @return the URL
+         * The String options passed to the TabTag object.
          */
-        public String getUrl()
-        {
-            return m_url;
-        }
+        final Map<String,String> options = new HashMap<String,String>();
 
         /**
-         * Adds a nested parameter value to the tab
-         * @param name the parameter name
-         * @param value the value
+         * Clones the Info object.
          */
-        public void setContainedParameter( String name, String value )
+        public Object clone()
         {
-            if( name != null )
+            Info info = new Info();
+            if ( beanclass != null )
             {
-                if( m_containedParams == null )
-                {
-                    m_containedParams = new HashMap<String, String>();
-                }
-                m_containedParams.put( name, value );
+                info.beanclass = beanclass;
             }
+            info.containedParams.putAll( containedParams );
+            info.options.putAll( options );
+            return info;
         }
     }
 
-    protected TabInfo getTabInfo()
+    protected Info getTabInfo()
     {
-        return m_tabInfo;
+        return m_info;
     }
     
     /**
@@ -294,13 +158,9 @@
     public void doFinally()
     {
         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;
+        m_info.beanclass = null;
+        m_info.containedParams.clear();
+        m_info.options.clear();
     }
 
     /**
@@ -316,7 +176,8 @@
         {
             throw new JspTagException( "Tab Tag without \"id\" attribute" );
         }
-        if( m_tabInfo.m_tabTitle == null && m_tabInfo.m_tabTitleKey == null )
+        if( m_info.options.get( Info.TITLE ) == null && 
+            m_info.options.get( Info.TITLE_KEY ) == null )
         {
             throw new JspTagException( "Tab Tag without \"tabTitle\" or \"tabTitleKey\" attribute"
);
         }
@@ -338,13 +199,14 @@
     }
     
     /**
-     * {@inheritDoc}. Also sets the ID for the embedded {@link TabInfo object}.
+     * {@inheritDoc}. Also sets the ID for the embedded {@link Info object}.
+     * This attribute is required.
      */
     @Override
     public void setId( String id )
     {
         super.setId( id );
-        m_tabInfo.setId( id );
+        m_info.options.put( Info.ID, id );
     }
     
     /**
@@ -354,7 +216,10 @@
      */
     public void setAccesskey( String accessKey )
     {
-        m_tabInfo.setAccesskey( accessKey );
+        if ( accessKey != null && accessKey.length() > 0 )
+        {
+            m_info.options.put( Info.ACCESS_KEY, accessKey.substring( 0, 1 ) );
+        }
     }
     
     /**
@@ -363,9 +228,10 @@
      * @param beanclass the ActionBean class name
      * @throws ClassNotFoundException if the bean class cannot be located or loaded
      */
+    @SuppressWarnings("unchecked")
     public void setBeanclass( String beanclass ) throws ClassNotFoundException
     {
-        m_tabInfo.setBeanclass( beanclass );
+        m_info.beanclass = (Class<? extends ActionBean>)Class.forName( beanclass );
     }
 
     /**
@@ -373,7 +239,7 @@
      */
     public void setContainedParameter( String name, String value )
     {
-        m_tabInfo.setContainedParameter( name, value );
+        m_info.containedParams.put( name, value );
     }
 
     /**
@@ -384,17 +250,27 @@
      */
     public void setEvent( String event )
     {
-        m_tabInfo.setEvent( event );
+        m_info.options.put( Info.EVENT, TextUtil.replaceEntities( event ) );
     }
 
     /**
+     * Sets the JavaScript to execute after the tab is clicked, but before
+     * the contents are shown.
+     * @param onclick the code
+     */
+    public void setOnclick( String onclick )
+    {
+        m_info.options.put( Info.ON_CLICK, onclick );
+    }
+    
+    /**
      * Sets the tab title.
      * 
      * @param title the tab title
      */
     public void setTitle( String title )
     {
-        m_tabInfo.setTitle( title );
+        m_info.options.put( Info.TITLE, TextUtil.replaceEntities( title ) );
     }
 
     /**
@@ -404,7 +280,7 @@
      */
     public void setTitleKey( String key )
     {
-        m_tabInfo.setTitleKey( key );
+        m_info.options.put( Info.TITLE_KEY, TextUtil.replaceEntities( key ) );
     }
 
     /**
@@ -414,6 +290,6 @@
      */
     public void setUrl( String url )
     {
-        m_tabInfo.setUrl( url );
+        m_info.options.put( Info.URL, TextUtil.replaceEntities( url ) );
     }
 }

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=905887&r1=905886&r2=905887&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 Wed Feb  3
05:17:19 2010
@@ -38,7 +38,7 @@
 
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.i18n.InternationalizationManager;
-import org.apache.wiki.tags.TabTag.TabInfo;
+import org.apache.wiki.tags.TabTag.Info;
 
 /**
  * <p>
@@ -128,7 +128,7 @@
             super();
         }
 
-        private final List<TabTag.TabInfo> m_tabs = new ArrayList<TabTag.TabInfo>();
+        private final List<TabTag.Info> m_tabs = new ArrayList<TabTag.Info>();
 
         /**
          * Adds a child TabTag to the TabCollection. When the TabbedSection tag
@@ -148,29 +148,7 @@
                 throw new JspTagException( "Cannot add null TabTag." );
             }
 
-            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() );
-            tabInfo.setUrl( tab.getTabInfo().getUrl() );
-            m_tabs.add( tabInfo );
+            m_tabs.add( (Info)tab.getTabInfo().clone() );
         }
 
         /**
@@ -178,7 +156,7 @@
          * 
          * @return the list of tab
          */
-        public List<TabTag.TabInfo> getTabs()
+        public List<TabTag.Info> getTabs()
         {
             return m_tabs;
         }
@@ -233,7 +211,7 @@
 
         // Figure out the active (default) tab
         TabCollection tc = getTabContext( pageContext.getRequest() );
-        List<TabTag.TabInfo> tabs = tc.getTabs();
+        List<TabTag.Info> tabs = tc.getTabs();
 
         try
         {
@@ -242,18 +220,19 @@
             JspWriter writer = this.getPreviousOut();
 
             writer.append( "<div class=\"tabmenu\">\n" );
-            for( TabTag.TabInfo tab : tabs )
+            for( TabTag.Info tab : tabs )
             {
                 // Is this the default tab?
-                if( tab.getId().equals( m_defaultTabID ) )
+                String id = tab.options.get( Info.ID );
+                if( id.equals( m_defaultTabID ) )
                 {
-                    m_defaultTabID = tab.getId();
+                    m_defaultTabID = id;
                 }
 
-                // If default tag still not 't set, use the first one
+                // If default tag still not set, use the first one
                 if( m_defaultTabID == null || m_defaultTabID.length() == 0 )
                 {
-                    m_defaultTabID = tab.getId();
+                    m_defaultTabID = id;
                 }
 
                 // Generate each menu item div
@@ -295,32 +274,39 @@
      * Outputs a single menu item <code>div</code> element for a supplied tag.
      * 
      * @param writer the JspWriter to write the output to
-     * @param tab the TabInfo object containing information about the tab
+     * @param tab the TabTag.Info object containing information about the tab
      * @throws IOException
      */
-    private void writeTabMenuItem( JspWriter writer, TabTag.TabInfo tab ) throws IOException
+    private void writeTabMenuItem( JspWriter writer, TabTag.Info tab ) throws IOException
     {
         writer.append( "  <a" );
 
         // Generate the ID
-        writer.append( " id=\"menu-" + tab.getId() + "\"" );
+        String id = tab.options.get( Info.ID );
+        writer.append( " id=\"menu-" + id + "\"" );
 
         // Active tab?
-        if( tab.getId().equals( m_defaultTabID ) )
+        if( id.equals( m_defaultTabID ) )
         {
             writer.append( " class=\"activetab\"" );
         }
+
+        // Onclick event?
+        if ( tab.options.get( Info.ON_CLICK ) != null )
+        {
+            writer.append( " onclick=\""+ tab.options.get( Info.ON_CLICK ) + "\"" );
+        }
         
         // Generate the ActionBean event URL, if supplied
-        if ( tab.getBeanclass() != null )
+        if ( tab.beanclass != null )
         {
             HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
-            UrlBuilder builder = new UrlBuilder( request.getLocale(), tab.getBeanclass(),
true );
-            if ( tab.getEvent() != null )
+            UrlBuilder builder = new UrlBuilder( request.getLocale(), tab.beanclass, true
);
+            if ( tab.options.get( Info.EVENT ) != null )
             {
-                builder.setEvent( tab.getEvent() );
+                builder.setEvent( tab.options.get( Info.EVENT ) );
             }
-            for ( Map.Entry<String, String> entry : tab.getContainedParameters().entrySet()
)
+            for ( Map.Entry<String, String> entry : tab.containedParams.entrySet()
)
             {
                 builder.addParameter( entry.getKey(), entry.getValue() );
             }
@@ -333,27 +319,27 @@
         }
 
         // Generate the URL, if supplied
-        else if( tab.getUrl() != null )
+        else if( tab.options.get( Info.URL ) != null )
         {
-            writer.append( " href='" + tab.getUrl() + "'" );
+            writer.append( " href='" + tab.options.get( Info.URL ) + "'" );
         }
 
         // Generate the tab title
         String tabTitle = null;
-        if( tab.getTitleKey() != null )
+        if( tab.options.get( Info.TITLE_KEY ) != null )
         {
             Locale locale = pageContext.getRequest().getLocale();
             InternationalizationManager i18n = m_engine.getInternationalizationManager();
-            tabTitle = i18n.get( InternationalizationManager.TEMPLATES_BUNDLE, locale, tab.getTitleKey()
);
+            tabTitle = i18n.get( InternationalizationManager.TEMPLATES_BUNDLE, locale, tab.options.get(
Info.TITLE_KEY ) );
         }
         if( tabTitle == null )
         {
-            tabTitle = tab.getTitle();
+            tabTitle = tab.options.get( Info.TITLE );
         }
         writer.append( ">" );
 
         // Output the tab title
-        String accesskey = tab.getAccesskey();
+        String accesskey = tab.options.get( Info.ACCESS_KEY );
         if( tabTitle != null )
         {
             // Generate the access key, if supplied



Mime
View raw message