jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject [06/10] jspwiki git commit: refactor PluginBean by extending ModuleBean instead of SimpleAdminBean
Date Tue, 22 Aug 2017 18:13:02 GMT
refactor PluginBean by extending ModuleBean instead of SimpleAdminBean


Project: http://git-wip-us.apache.org/repos/asf/jspwiki/repo
Commit: http://git-wip-us.apache.org/repos/asf/jspwiki/commit/5139de06
Tree: http://git-wip-us.apache.org/repos/asf/jspwiki/tree/5139de06
Diff: http://git-wip-us.apache.org/repos/asf/jspwiki/diff/5139de06

Branch: refs/heads/master
Commit: 5139de06536922b71ee1b89c5b202178b817b9a2
Parents: 14b2bbb
Author: juanpablo <juanpablo@apache.org>
Authored: Tue Aug 22 20:03:29 2017 +0200
Committer: juanpablo <juanpablo@apache.org>
Committed: Tue Aug 22 20:03:29 2017 +0200

----------------------------------------------------------------------
 .../apache/wiki/ui/admin/beans/PluginBean.java  | 85 ++++++++------------
 1 file changed, 35 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jspwiki/blob/5139de06/jspwiki-war/src/main/java/org/apache/wiki/ui/admin/beans/PluginBean.java
----------------------------------------------------------------------
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/ui/admin/beans/PluginBean.java b/jspwiki-war/src/main/java/org/apache/wiki/ui/admin/beans/PluginBean.java
index d17c10f..da0f126 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/ui/admin/beans/PluginBean.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/ui/admin/beans/PluginBean.java
@@ -14,7 +14,7 @@
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
-    under the License.  
+    under the License.
 */
 package org.apache.wiki.ui.admin.beans;
 
@@ -22,79 +22,64 @@ import java.util.Collection;
 
 import javax.management.NotCompliantMBeanException;
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.wiki.Release;
-import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
-import org.apache.wiki.api.engine.PluginManager;
 import org.apache.wiki.plugin.DefaultPluginManager.WikiPluginInfo;
-import org.apache.wiki.ui.admin.SimpleAdminBean;
 import org.apache.wiki.util.XHTML;
 import org.apache.wiki.util.XhtmlUtil;
 import org.jdom2.Element;
 
-public class PluginBean extends SimpleAdminBean {
-	
-    private WikiEngine m_engine;
-    
-    private static final String VER_WARNING = "<span class='warning'>This module is
not compatible with this version of JSPWiki.</span>";
-    
-    public PluginBean( WikiEngine engine ) throws NotCompliantMBeanException {
-        m_engine = engine;
-    }
 
-    public String[] getAttributeNames() {
-        return new String[0];
-    }
+public class PluginBean extends ModuleBean< WikiPluginInfo > {
 
-    public String[] getMethodNames() {
-        return new String[0];
+    public PluginBean( WikiEngine engine ) throws NotCompliantMBeanException {
+        super( engine );
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public String getTitle() {
         return "Plugins";
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public int getType() {
         return CORE;
     }
 
-    @SuppressWarnings("unchecked")
-    public String doGet(WikiContext context) {
-        PluginManager pm = m_engine.getPluginManager();
-        Collection< WikiPluginInfo > plugins = pm.modules();
-        
-        Element root = XhtmlUtil.element( XHTML.div );
-        Element tb =  XhtmlUtil.element( XHTML.table ).setAttribute( "border", "1" );
-        
-        root.addContent( XhtmlUtil.element( XHTML.h4 ).addContent( "Plugins") )
-            .addContent( tb );
-        
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Collection< WikiPluginInfo > modules() {
+        return m_engine.getPluginManager().modules();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Element heading() {
         Element trHead = XhtmlUtil.element( XHTML.tr );
         trHead.addContent( XhtmlUtil.element( XHTML.th ).addContent( "Name" ) )
-              .addContent( XhtmlUtil.element( XHTML.th ).addContent( "Alias" ) )
               .addContent( XhtmlUtil.element( XHTML.th ).addContent( "Author" ) )
               .addContent( XhtmlUtil.element( XHTML.th ).addContent( "Notes" ) );
-        
-        tb.addContent( trHead );
-        
-        for( WikiPluginInfo info : plugins ) {
-            Element tr = XhtmlUtil.element( XHTML.tr );
-            tr.addContent( XhtmlUtil.element( XHTML.td ).addContent( info.getName() ) ) 
-              .addContent( XhtmlUtil.element( XHTML.td ).addContent( info.getAlias() ) )

-              .addContent( XhtmlUtil.element( XHTML.td ).addContent( info.getAuthor() ) )
-              .addContent( XhtmlUtil.element( XHTML.td ).addContent( validPluginVersion(
info ) ) );
-                
-            tb.addContent( tr );
-        }
-
-        return XhtmlUtil.serialize( root, XhtmlUtil.EXPAND_EMPTY_NODES );
+        return trHead;
     }
 
-    String validPluginVersion( WikiPluginInfo info ) {
-        return Release.isNewerOrEqual( info.getMinVersion() ) && Release.isOlderOrEqual(
info.getMaxVersion() ) 
-               ? StringUtils.EMPTY 
-               : VER_WARNING;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Element rowBody( WikiPluginInfo plugin ) {
+        Element tr = XhtmlUtil.element( XHTML.tr );
+        tr.addContent( XhtmlUtil.element( XHTML.td ).addContent( plugin.getName() ) )
+          .addContent( XhtmlUtil.element( XHTML.td ).addContent( plugin.getAlias() ) )
+          .addContent( XhtmlUtil.element( XHTML.td ).addContent( plugin.getAuthor() ) )
+          .addContent( XhtmlUtil.element( XHTML.td ).addContent( validModuleVersion( plugin
) ) );
+        return tr;
     }
 
 }


Mime
View raw message